Hacker News new | past | comments | ask | show | jobs | submit login

1) Lack of heap-allocated convenient strings, dynamic lists and a dict/hashmap structure. They would not need to be fast, but the total lack of such types built in means that you cannot even deserialse a JSON or YAML config file without it getting very verbose.

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).




> 1) Lack of heap-allocated convenient strings

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).


Heap-allocated was a bad choice of words. I mean strings that allow you to do "a+b" or similar simple concatenation built in almost any other language has (not C though, although there null-termination and stdlib helps a lot more than Fortran character arrays does). Though I guess one could roll one own here too, same as with lists and dicts and so on.


> I mean strings that allow you to do "a+b" or similar simple concatenation

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.


In Fortran you can overload the "+" operator for string concatenation, if you like.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: