首页

Ask HN: Do you think ahead when programming?

1 点作者 ZhangSWEFAANG超过 3 年前
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 &lt;= 5; i++) {<p>}<p>but then I&#x27;ll realize I forgot to initialize a counter, so I&#x27;ll go back up and add int counter = 0 at the top.<p>To combat this issue, I&#x27;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 &#x27;thinking ahead.&#x27; Do kids make flow charts anymore? How about writing code out by hand before typing it in? These exercises used to be considered normal &#x27;thinking ahead.&#x27; 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&#x27;m not considering the scale of technical debt I may introduce with my change.
评论 #28962586 未加载