首页
Ask HN: Do you think ahead when programming?
I always find myself forgetting necessary variables when programming. For example, when I am summing the numbers between 1 and 5, I might remember to start the for loop<p>for (int i = 1; i <= 5; i++) {<p>}<p>but then I'll realize I forgot to initialize a counter, so I'll go back up and add int counter = 0 at the top.<p>To combat this issue, I've been visualizing code in the future while writing the current code. This has been making my brain sharper and improving my programming. However, no one talks about it. Thoughts?
3 条评论
thagerty超过 3 年前
Depends on what you mean by 'thinking ahead.' Do kids make flow charts anymore? How about writing code out by hand before typing it in? These exercises used to be considered normal 'thinking ahead.' Sometimes necessitated by resource constraints, other times just a rough draft practice, some type of forethought is a good way to train your mind to do the work, instead of just reacting to errors.
tyingq超过 3 年前
An IDE can show you stuff like that. Visual Studio underlines uninitialized variables with a squiggly line for me.
luxurytent超过 3 年前
Without thinking ahead, I'm not considering the scale of technical debt I may introduce with my change.
评论 #28962586 未加载