A Fortran Web Framework
fortran.io
fortran.io
I know it's the butt of many jokes (together with Cobol and Assembly - especially in the context "really hard to learn/use languages) but just scrolling through the github repo (frontpage), the code doesn't seem that intimidating (or any less confusing than Go would seem for someone unfamiliar with its nuances).
2) What makes Fortran so much 'faster' at computation than C?
C is the go-to for any low-level performance, but in terms of computation, Fortran seems to do better (or so we're told). Is/Was Fortran a better-designed language, that allowed it to perform better than C at computation?
Some versions of Fortran are optimised at compiler level for hardware, hence question #2 is moot. [0] Note the level of optimisation on linux [1] required to speed the code up.
[0] https://en.wikipedia.org/wiki/Intel_Fortran_Compiler
[1] https://software.intel.com/en-us/articles/using-intel-compil...
What I mean is the reason C isn't faster is because of the hardware support at processor level and extra library support for example in IFort. Is writing/re-writing a problem in another language when there is an existing well documented body of code is premature optimisation?
FORTRAN 77 (and FORTRAN 66) was a pretty primitive language. Source code still used line numbers, no malloc, no recursion (there is a workaround, though), very cumbersome text manipulation.
When Pascal and C got popular in the 70s and 80s, FORTRAN 77 felt ancient in comparison.
I guess the jokes originate in the 80s, and from then on they have lived in the folklore, told to new generations. Fortran 90 came only in 1992 (and then later 95/03/08) and while it is much modernized, I don't think the people telling the jokes have yet looked at it.
I wonder the same thing: there is irrational contempt towards Fortran here on Hacker News. I think it says more about the attitude than it does about Fortran.
2) What makes Fortran so much 'faster' at computation than C?
two things: the compilers are excellent, and produce really fast machine code, and intel has invested tremendous amount of engineering, with focus on exploiting the newest features of their processors (such as AVX2). The new ifort compiler comes out every six months. Others like PGI have produced a Fortran compiler which can generate NVidia GPU code. Fortran compiler technology and Fortran the language standard / features are on the cutting edge of the domain Fortran is designed to handle, computing. And since Fortran can actually handle strings and has regex support, I've often wondered what it would be like for web applications...
There is no restrictions in the use of pointers in Fortran, the compiler knows pointers can overlap. The restriction is when arrays are passed as arrays (passed by reference internally), not pointers.
- very terse and cryptic variable naming. Understandable since fortran 77 only allows variable to contains up to 6 characters. But it makes working with large codebase very painful.
- You had to use upper case only. It may not sounds a big deal, but you'll get tired of it eventually when working with lots of fortran code.
- Implicit typing: If your variable starts with i-n character, it will be treated as integer. Otherwise it's a float. You better not forgetting this one or terrible bugs will appears on your code.
- Source code fixed format: your source code must conform to this format or the compiler won't recognize it:
- only the first 72 chars get parsed;
- first 5 characters/columns of the line must be blank or contain numeric label
- if your code is not going to fit in one line, you can extend to the next line by marking it with a non-numeric character in the 6th columns. otherwise it should be blank.
I think there are more annoyances but those are the ones that I still remember to this day.- AOT compilation straight native code
- Distributing the runtime with the application, instead of a central installed location
Probably the closest you can get today would be one of the more modern BASICs out there (QB64 or GAMBAS - maybe FreeBASIC?).
That is why you have the old joke that "God is real, unless declared otherwise".
What do you use for the easy GPU processing? PGI? Or is there something else (hopefully open source) that you've found that works?
Fun fact: Nowadays people are doing the same with SQL - even though there is absolutely no reason to do so.
select * from mytable
is as good as: SELECT * FROM MYTABLE
Nowadays, upper case SQL seems to be a sign that the code is either 1) auto-generated by an ORM, or 2) written by a novice, or 3) written by a project with very strange coding styles (the last two seems to be some kind of cargo culting).SELECT * FROM my table
has a purpose, which is to visually separate SQL statements from table and column names.
The other advantage it makes bugs where you use a Reserved word where you should not much easier to see visually
You see the same issue with other relicts, for example, Pascal back in the 90s. Old text books wrote Pascal in uppercase style:
PROGRAM HelloWorld(output);
BEGIN
...
END.
But in reality, everybody using e.g. the Turbo Pascal IDE wrote lowercase instead, because it easier to type and because of proper syntax highlighting: program HelloWorld(output);
begin
...
end.
Maybe this is not so much about the maturity of the developers (as I assumed in the previous comment), but about the maturity of the tooling.Every RDBMS has its own set of keywords and reserved words, so it's pretty much impossible to maintain a "proper" syntax highlighting mode.
I also like to stylistically indent my SQL to make it easier to follow. This works well for most typically use cases, but it can fail horribly when you start to certain kinds of JOINs and such - the indenting will make things more difficult to read.
Of course, once you start doing really wild things with SQL, no amount of casing or indentation will save you.
EDIT: Missed that the sibling comment said the same thing...
The Fixed code format went away a long time ago (it was to fit on a 80 col punched card) any one using F77 and later in the last 30+ years will have used free format
And the MAGIC is REAL unless declared INTEGER - professional Fortan programmers declare everything! (well apart form loop indexes I j etc)
I never knew that! I've always wondered why the BLAS / LAPACK routines had such frustratingly concise names (dgesv, dgbsv, dposv, ... just grabbing the top few from [1]).
Hence the old Fortran joke: God is real --- unless declared integer.
Maybe 50? To put modern into perspective, 30 years ago is 1986 and Python is from 1989. A bunch of other mainstream languages are only slightly younger: Ruby, Java, JavaScript, PHP. I think C++ is not much older than that.
2) Main reason it is faster than C is all arrays are nonaliasable by default (e.g. if you have two arrays as arguments to a function you know they do not occupy the same memory). This enables some important optimizations. In C99 there is the __restrict__ intrinsic to declare the same thing in which case C99 is just as fast. However you still need to write a lot more code in C99 since you need to write loops, while in Fortran "a+b" can add together two arrays (with full compiler support for optimized array expressions).
As of Fortran 2003, there's allocatable scalars, including strings (type "character" in Fortran). There's also "allocate on assignment", which is also nice (that is, you don't need to manually allocate an empty character first before writing stuff to it).
> dynamic lists and a dict/hashmap structure.
As of Fortran 90, with pointers and derived types, you can do it yourself, just like in C. But yeah, sometimes it's frustrating that the standard library is so limited (again, not that much worse than C, but compared to many modern languages, certainly).
Meet "//", the character concatenation operator. Part of Fortran at least since the FORTRAN 77 standard.
With the F2003 additions I mentioned, one can do stuff like
program stringtest
implicit none
character(:), allocatable :: s
s = "hello"
s = s // " world"
print *, s
end program stringtest
where the first executable statement (s = "hello") allocates space for "hello" on the heap, and the second statement reallocates that heap space to now have room for the previous contents + " world".And since Fortran allocatables are a bit like C++ RAII, they are automatically deallocated when they go out of scope.
Is this as convenient as doing string handling in, say, python? IMHO, no, but better than plain C + stdlib.
2) C can be faster than Fortran (not by a lot mind you). But when it comes to math-y type things, Fortran code can be made very, very fast, and can be parallelized with little to no effort.
I think it's more like this: As long as the numerics is vectors, matrices and multidimensional arrays (no complex graph or tree data structures implemented with pointers, no string manipulation, no bit-level fiddling), a scientist or engineer who spent less than a week learning Fortran, can write code, almost in a first pass, with nice array notation, that is close to as performant as a relatively seasoned C-expert could write.
Is there an introduction, available online, to Fortran support for vector/matrix operation?
I've heard there is no null dereferencing and pointer nonsense - all without the need for a garbage collector - which ultimately leads to Fortran's great reputation for speed.
re 2. It is simple so easier to optimise.
Regarding 1 again, I can't find it right now but the fact that Fortran could not even read it's own source code was one of the motivations for Ratfor; a C-like preprocessor for Fortran. By the esteemed Brian Kernighan.
DO 100 I = 1.10
which the programmer thinks sets up a DO loop to run ten times but instead assigns 1.10 to a variable called DO100I, thanks to the period that should be a comma. Then there was the infamous H (Hollerith) format item; to get a literal string int formatted output you had to use it and had to count characters rather than using a string literal, so 100 FORMAT(10HHELLO WORLD)
has an off-by-one error.2. Pointers. Fortran explicitly states it will make assumptions that let it ignore impediments to optimization that pointers can cause. C has the "strict aliasing rule" and the "restrict" keyword that help, but not enough.
....
CALL MUNG(2)
I = J + 2
...
SUBROUTINE MUNG(N)
N = 42
RETURN
END
After passing the constant 2 to MUNG, later uses of 2 will actually give you the value 42. Have fun debugging that!I'm not sure, I would like to know the answer to this. At least for modern Fortran.
2) What makes Fortran so much 'faster' at computation than C?
I don't know if the computation of Fortran is always faster than C (I thought they were comparable), but at least in development time, it was a huge improvement for me. I was forced to use Fortran 2003 at university for numerical simulations etc and expected it to be terrifying but found it very pleasant. Instead it was when programming C later on that I got slightly frustrated.
- It's easy to learn. No need to learn about pointers etc.
- It's very math friendly. The fact that you can easily extract and use sub matrices/array is probably my favorite feature. In C I needed to write loops, pass around array length or matrix sizes, etc. Multi dimensional arrays got annoying to work with and ended up writing matrices as column-major vectors.
- It has some nice built in functions such as matrix multiplications (no loops for this). It also has great math libraries like BLAS/LAPACK
- Offers OOP
I haven't made use yet of the advantage I hear most often i.e. for HPC.
And just for more fun, more Fortran libs for fun and profit: Awesome Fortran: https://github.com/rabbiabram/awesome-fortran
It's happened a couple of times before, but today I was on a trans-Pacific airplane flight and my laptop had run out of power! agghghgh
Speaking more broadly - I hope we see more web stuff in the statically typed, machine code compiled camp. It is my understanding that web apps do more and more client side these days and only really need a "thin" server. Ruby or Python seems over kill.
http://www.learnbchs.org/tools.html (mirror: https://archive.is/d1BXC)
In the future, I might add some wrappers over access of CGI environment vars, but you can already look those up by hand, using the standard environment access routines.
COBOL needs to DIEEEEEE!!!!!!!!!!!
But I do have a question: Can this new FORTRAN framework match the performance of the best web framework out there, INTERCAL on Interstates? http://www.intercaloninterstates.org/
His homepage: http://mapmeld.com/ Fascinating person. Has worked with various languages and does educational work throughout the world with OLPC laptops.
502 Bad Gateway nginx/1.4.6 (Ubuntu)
Is it just "it works" PoC or does it run OK?
(chuckles)
I call it "Railth".
Fun fact : I informed the author (which I'd a good fortune to get to know him for some time) this morning (east time zone) that his project is (again) on the front page on HN. He was in the air on his way to Taiwan. We both wished it doesn't break but it seems like it did and he restarted it again.