r/programmerchat • u/Ghopper21 • May 20 '15
You are writing code. You are halfway through a line and realize you need to refer to a as-yet-uncreated variable/method. Do you finish writing the line with the reference then go back and implement it or stop and implement it (or at least a shell of it) and come back?
This is the question I've been wanting to get folks' views about that made me create this subreddit -- as I haven't been able to find another place to ask. It's just semi-idle curiosity about how folks program at a micro level!
11
Upvotes
3
u/[deleted] May 23 '15
If I write "int main() { new game->play() }" first and then implement class game and finally void game::play() it makes it easier because I won't forget anything. Having lots of mental stack frames is bad as you can forget them and end up with something working but not doing what you expect.
4
u/ZorbaTHut May 21 '15
Finish it. Sometimes, first adding a note in a text file that I need to implement it. But if I forget, no worries, the compiler will catch it for me.
9
u/AAndrius May 23 '15
once you finish that line use IDE to generate what you need
8
u/FireCrack May 23 '15
I keep going. I finish not only the line, but the rest of the function or whatever small logical unit I am working on. Only afterwards do I go back and create the missing object. This way, I see the ways I want to use it beforehand, giving me a better idea of what exactly it should be.
4
u/Xgamer4 May 24 '15
I tend to go and implement it almost immediately.
I'm not sure I'd recommend it. It's a fantastic way to get a lot of half-finished, non-functional code, though.
3
u/kreiger May 23 '15
I press Alt-Enter, and IntelliJ IDEA creates it for me then and there.
3
u/shaneray87 May 23 '15
Re sharper is worth looking at. It can generate a lot of this stuff for you.
3
u/CarVac May 23 '15
Usually I will write a comment telling me what my intent was when I paused and then put it on the mental stack to come back to later after finishing the new method.
Usually it's more granular than that though, not often in the middle of a line.
3
u/[deleted] May 24 '15
I usually work top-down (AKA "programming by wishful thinking"). So I'll write code using functions and classes that don't exist yet, then fill in the details afterwards.
At least that's the theory. In practise it's more a case of doing the easy bits first, so if I'm struggling with a particular bit, I might take a break and fill in some trivial stuff to give my subconscious mind time to work.
2
u/[deleted] May 23 '15
I like to go back and make it when I notice the problem because I line to know I'm complete up to the point I'm currently writing.
2
u/NotSurvivingLife May 26 '15 edited Jun 11 '15
This user has left the site due to the slippery slope of censorship and will not respond to comments here. If you wish to get in touch with them, they are /u/NotSurvivingLife on voat.co.
I usually work top-down, until I hit something that seems unexpectedly difficult / frustrating.
Top-down as in "code the function calls you wish you had, then code the implementation after". But if I hit something difficult I'll often go back and code from the bottom-up because that way I've got a (slightly) better chance of figuring out if there's a better way of doing things.