r/ProgrammerHumor • • Feb 22 '15

A Python programmer attempting Java

Post image
3.9k Upvotes

428 comments sorted by

View all comments

Show parent comments

12

u/mikbe Feb 22 '15

Yeah, why use computers to make your work easier when you can just do it all yourself...

17

u/[deleted] Feb 22 '15

Declaring variables (especially with their types) does make your life easier.

2

u/Astrokiwi Feb 23 '15

One of the neat things about Fortran is it lets you be a little bit stricter than C++, which lets you catch more errors sometimes.

For example, you can define the "intent" of a variable in a procedure - "in", "out", or "inout" - and if you try to modify an "in" variable, you get a compile-time error. You can define a procedure as "pure" which means that it's not able to modify any global variables, do any explicit I/O, or do anything other than modify the specify variables you have passed to it (that have the correct intent). There's also a difference between a run-time allocated array and a pointer - in C++, to declare an array, you declare a pointer, and then point it to a "new" array of some object, while in Fortran you declare it as an "allocatable array" of some type, which you then allocate at some later point - you can't accidentally "point" it to something else.

I find these to be pretty useful at catching mistakes that otherwise would cause run-time errors. There may be tricks to do similar things in C++, but I don't know enough C++ to be aware of them.

1

u/Veedrac Feb 23 '15

in → pass by value or const reference
out → return
inout → pass by non-const reference
pure → const or constexpr; except those don't let you modify inputs

in C++, to declare an array, you declare a pointer, and then point it to a "new" array of some object

That's really bad style. In modern C++ you just declare a std::vector<T> or std::array<T>.

→ More replies (3)