5

OK, here goes nothing: now, I absolutely hate putting the main function at the end of the file and everything else above it.

Comments
  • 0
    Use languages that aren't stuck in the past, problem solved.

    But seriously, I also don't get why this is still a thing in some languages. Even fucking Bash can call functions defined later.
  • 0
    @deadlyRants I'm trying to, LOL!

    I'm currently writing some bash scripts and I just released that!
  • 0
    @deadlyRants and it doesn't work in bash :'D
  • 1
    @deadlyRants I wouldn't say c++ is stuck in the past but to some extent you have a Point.
  • 5
    C/C++ have always had header files and forward declarations so that the function order in the source files doesn't matter.
  • 2
    Put the main function first and forward declare things, problem solved
  • 7
    That was a limitation of the compiler as it was a one pass compiler only going over the code once.

    Due to this it had to know about the function definition before it was used.

    Most other compilers do multiple passes so order is irrelevant.
  • 2
    Came here to say this @Voxera and this @Fast-Nop: Single vs multi pass compiler, and prototypes/headers in C/C++.
  • 1
    But why?!
    For me anything/everything else is weird.. this way you can scan little bits of code befere you actually see how and where they're called..
    Huh.. guess I'm weird that way..
  • 0
    Why?
  • 0
    @sladuled @iiii I think it's because I want to see the entry point at the beginning instead of looking for it specially if the file is huge (C devs love huge files). Also, it has to do with function scope. I always order my functions in the file from public to private. I don't want to read a private function before I can look at the main function.
Add Comment