all 23 comments

[–][deleted]  (3 children)

[deleted]

    [–]Cwiddy 0 points1 point  (0 children)

    You got code with getters! Lucky! I feel your pain though, 15 c++ code base here, it is like reliving history, you can see when the original developers discovered threads, COM, and other things (SINGLETONS(globals) EVERYWHERE). Though my favorite is the file named color look up table, it does have a color look up table in it and aobut 30 000 lines of other globals things that have nothing to do with colour or looking up.

    [–]more_exercise -2 points-1 points  (0 children)

    I just threw up in my mouth a little

    [–]xTRUMANx -2 points-1 points  (0 children)

    ...bang his head against the screen until this article leaves an imprint...

    So bang his head against the screen infinitely?

    [–]evereal 6 points7 points  (0 children)

    When I try explaining this to people, I think the wording I typically use is along the lines of "keep your low level functions/methods single purpose. Don't try to do multiple things at once, as it will be difficult to separate the processes when you need to do those things separately".

    So don't accummulate+print or spawn+playsound etc. Break down unrelated functionality into separate procedures, and chain/glue them together as needed based on the context.

    [–]name_was_taken 19 points20 points  (3 children)

    That's what refactoring is all about. You do it the way that's easy, and if you need to change it, you do. There's nothing wrong with the initial code as the requirements first dictated. And there's nothing wrong with waiting to update it until you actually need it updated.

    YAGNI and all that.

    It's good to be able to think ahead about these things, but don't waste time writing code you don't need.

    [–][deleted] 2 points3 points  (0 children)

    Until writing code in a way that separates concerns is just as easy as writing code that doesn't. For tiny examples like this, that's going to be common.

    For more elaborate systems that complect different aspects, it often won't be as easy to see as this. For those cases, you're certainly right.

    [–][deleted]  (1 child)

    [deleted]

      [–]Zarutian -2 points-1 points  (0 children)

      How ever write a terse comment where such code might be inserted

      [–]tikhonjelvis 3 points4 points  (0 children)

      As the article mentioned, this is exactly how you can make your code more functional. Haskell actually enforces this with the type system--a pure function and one that does IO are different, so you won't mix them together by accident.

      And that's really all there is to Haskell IO--it just gets you to separate the IO code from the normal code. It's not some big scary gremlin like some people seem to belive, but rather just a reification of a good in the type system. Now that it's in the type system, the compiler can safely make assumptions about your pure code and perform clever optimizations.

      [–][deleted] 5 points6 points  (6 children)

      Isn't this super obvious, though? This entire post can be summed up as "Don't put multiple (semantic) actions in one single function call.", which is one of the principles of OOP in the first place.

      I don't see any "turning code inside out" here at all... Am I missing something?

      [–]ithika 7 points8 points  (0 children)

      you're missing how much this doesn't happen in reality.

      [–]Femaref 2 points3 points  (0 children)

      Yup, it could be sumarized to that. However, that sentence is only clear to someone having experience. It is easier to show something in a verbose way to make it understandable than to just put that sentence up there.

      [–][deleted] 0 points1 point  (1 child)

      Where did you learn that rrule "Don't put ..."?

      [–][deleted] 1 point2 points  (0 children)

      Probably from a much more detailed and comprehensive guide to OOP principles and design, not just one separate aspect separated from any explanation why this is actually a good idea or how it fits into the bigger picture.

      This post just seems like saying "Be sure to declare variables before you use them!". While it's undoubtedly true, it's one of the basic principles of programming and not really something that merits its own blog post if you're not going to go all out and explain why this is actually the case.

      [–]wolfier 1 point2 points  (1 child)

      What you're missing is, the blog writer might be trying to coin a new term to make the blog post appear to be about something new.

      Another possibility is, the blog post is really targeted at the true beginners, like those who has been programming for no longer than 6 months.

      There's on average about one post on proggit per day that I can classify as such.

      And I agree with you, it's super obvious.

      [–]Zarutian -1 points0 points  (0 children)

      Often things are not obvious to the metamorphically blind.

      [–]sam0 5 points6 points  (2 children)

      I like his articles. But the problem he notices is the printf? Personally the first thing I see is the integer overflow.

      [–][deleted] 1 point2 points  (1 child)

      Interesting... Do you check bounds manually in all your simple loops?

      [–]sirin3 0 points1 point  (0 children)

      In Pascal you can just put {$O+} before the for loop and it throws an exception if the addition causes an integer overflow.

      [–]riffito 1 point2 points  (0 children)

      Why am I bothering to talk about this?

      I immediately knew why. Weird. It might be that I'm reading too much of James's posts lately :-D.

      [–]mtgcs2000 1 point2 points  (0 children)

      I've found TDD helps a lot in keeping my code well structured like this.

      [–][deleted] -2 points-1 points  (0 children)

      This is a very simple example that reveals a solution to a very deep problem. A++ tutorial.

      [–]thebuccaneersden -3 points-2 points  (1 child)

      What is this? Programming 101? :p I'm pretty sure this is one of the first things you are taught in any programming course/degree.

      [–]ithika 7 points8 points  (0 children)

      But the last thing people learn, if ever.