On Sun, 23 Sep 2012 22:47:58 -0700 "H. S. Teoh" <[email protected]> wrote:
[...] > > As soon as you start having a whole bunch of code at different levels > of abstraction mixed together, you know it's time to split them up > into separate functions, 'cos chances are you'll need to use each > piece independently one day. > Yea, I feel the same way: Code should operate at one level of abstraction. At least ideally. I don't always adhere hard-and-fast to it either because sometimes "getting it done" is more important than "getting it perfect" (not to say that excuses *really* bad enterprisey code). And sometimes you *can't* stick to one level due to performance or language limitations (depending on the language). But whenever reasonably possible, the rule of thumb: One level of abstraction per function. Along similar lines, there's another rule-of-thumb that I actually did pick up in college (and oddly enough, from the "Let's teach first-time beginners OOP, ie code architecture, before flow-of-execution" instructor): If a function is more than one screenful, it's probably too long. Now obviously that can't and shouldn't be used as a hard-and-fast rule, but I've found it a sensible rough guideline. Although I'm much more relaxed about it now than I used to be...and even *moreso* now that I'm on one of these annoying half-height short-screens, erm, I mean "widescreen" ;) > > [...] > > > > What really gets me is that these are the sorts of things that are > > harped on in chapter 1 of just about any decent "intro to > > programming" book. So where did these people even learn to code in > > the first place? > > Probably from a youtube video on how to write your own lame Flash > game. :-P OK, I'm being a bit harsh. But it's hard not to be cynical > when you've seen the kind of code that passes for "enterprise > software" these days. > Maybe it's just because I'm just beyond the snapping point, too, but I don't think it's possible to be too harsh on such code, or anything involving Flash ;) > > (Well, except for the handful of students, and I could always tell > > which ones they were, who were from the class of Mrs. "Let's Teach > > OOP *Before* Basic Flow Of Execution". Those poor students couldn't > > write *any* code, let alone good or bad code. I felt bad for them.) > > Speaking of students who couldn't code... I used to give out > "sympathy marks" for struggling students. Y'know, their code was so > bad, like code that obviously didn't compile or work, or code with > comments written in a way that suggested the student thought that if > they pleaded hard enough verbally the computer might *just* do what > they wanted it to do -- they had to get a failing mark, but I tried > to find excuses to not give them an outright zero. But one time, > after marking a bunch of 15-20 page assignments (complete with intro, > description, code, test results, etc.), I came across a submission > consisting of a single sheet of paper *hand-written* on a single > side. I was boggled for a good moment. It was like... I was trying > not to give anyone an outright zero but she gave me no choice, > y'know? What was the point of handing that piece of paper if she > wasn't even going to make the effort of using the lab *printer*, for > crying out loud. > Ouch. Yea. I think I actually got a sympathy "pass" in German 101. I barely scraped by with a "D-" overall, but if you went strictly by the numbers and class rules it really should have been an F. I think she knew I was at least trying and struggling though. Ironically, the only reason I even took it was because I was having trouble getting through the school's "4 semesters of the same foreign language" requirement when I went with Japanese. Little did I know German would be *far* harder. "Oh, yea, go with German - it's the closest language to English!" Yea, I think that's actually what made it so hard ;) That, and gendered words.
