6 ms·
It's funny, as a kid I can remember thinking: "Right, everything has to go in the main function unless absolutely necessary, it will just be easier to read that
by poopicus 13y ago
It's funny, as a kid I can remember thinking: "Right, everything has to go in the main function unless absolutely necessary, it will just be easier to read that way."
Nowadays, it's the exact opposite!
- daigoba66 13y agoAs a kid I wrote a few games using QBasic. I apparently didn't have a firm grasp on control flow because every call to a sub routine ended with a call to another subroutine; sometimes to a sub routine that was already called earlier in the stack. You win the game by beating it before crashing with a stack overflow.
- Sammi 13y agoNah you just invented continuation passing style. You just needed tail recursion too, and you would be good to go ;)
- doktrin 13y agoMy code changed in a similar way, however I recently devolved. I've mostly worked with higher level languages, and recently delved back into C. I had forgotten what a complete pain in the ass it is to pass complex data structures around between functions. I'm a bit ashamed to admit my functions got pretty damn beefy real quick.
- Nursie 13y ago&structure ... ?
- doktrin 13y ago> &structure AFAIK, that's only a legal function signature in C++. To the point of the question : when I wrote that, I was specifically thinking of 2-dimensional arrays, not structs per se.
- Nursie 13y agoI meant passing a pointer rather than a by-ref call (which is indeed C++ only). i.e. void myfunc(thing* stuff) { return; } int main() { thing stuff; myfunc(&stuff); }
- doktrin 13y agoOh, totally agreed. What I had difficulty with, specifically, was passing around a struct that contained a multidimensional array of a size determined at runtime. I'm sure the problems I had could be solved by either a full re-design (not really an option), or accomplished by someone with more C experience.
- ATLobotomy 13y agoIt shouldn't matter what the struct is holding, you are passing a pointer, it's always the same size.
- marvin 13y agoDon't worry, you can do this in C# or Python as well. Just structure your small, gradually growing proof-of-concept and soon-to-be-finished-product program correctly. No classes! Or at the very least a few monolithic ones, which cannot be instantiated. Use static methods whenever possible. I have never ever ever done this. (I am getting ready to write an essay titled "Confessions of a Shitty Programmer").
- lstamour 13y agoTry C++, join the dark side! In addition to chocolate chip cookies, we promise C++11 move semantics for returned objects/values. The cookies/cake might be a lie. :-)
- krapp 13y agoI had to create a small ADO class for advanced C++ last year. It was... terrifying.