Skip to main content
13 events
when toggle format what by license comment
Aug 17, 2012 at 13:18 comment added Rafael Piccolo I don't know where is this mountain of code you said, but the point I was trying to make was not about changing structures, but about encapsulation. For example, if there is an OrderProcessor class and this class needs the total value of the items, should it do the calculation? No, it should ask it for the collection. For the processor class, is doesn't matter if the collection is a set, an array or whatever, it just needs the total value. The changing structure possibility is a bonus you get for doing that, not the primary motivation.
Aug 15, 2012 at 17:37 comment added riwalk Any good IDE will help you change something like that in minutes. You're suggesting that he program for requirements that do not exist. You're envisioning a beautiful architecture in your head that will make things easier, but the problem is that the ideas stay there--in your head. When someone else comes along, it is HIGHLY unlikely that they will take the time to understand the mountains of code that you've written. What is much more likely is that they will just tag something on, and the result is lava flow programming accompanied by mountains of useless code.
Aug 15, 2012 at 17:08 comment added Rafael Piccolo Well, I didn't said never use collections, or always encapsulate every collection. These radical words are dangerous in software development. Things change, even the ones you never thought, so, the more prepared you are for changes, the better when they come. It's up to the developer to decide when to do it or not. Set has its limitations, if the order of the items becomes important, good luck in changing the same thing in dozens of places. Plus, there is the encapsulation issue: the collection should know how to handle its own items, not external classes.
Aug 15, 2012 at 15:35 comment added riwalk He's asking which example is better, which means that yes, he is talking about the 12 line long function. Even if I were to believe that he was metaphorically speaking about a massively large block of code, your example of encapsulating the data structure (just in case it changes!) still warrants the downvote. Your attitude towards programming reminds me of this blog: chaosinmotion.com/blog/?p=622
Aug 15, 2012 at 15:04 comment added Rafael Piccolo @Stargazer712 He is not talking about 12 lines long functions, he asked about concepts and best practice. The 12 lines long function he posted was just a simplified example, just to illustrate his question. We all post simplified versions of our problems when writing a question. Would you prefer a full program with hundreds of lines in this tinny space?
Aug 15, 2012 at 14:29 comment added riwalk I'm sorry, but -1. If you see a function that is 12 lines long (including the whitespace!) and say "there is more refactoring to be done there," then you have some serious issues. The fact that you then say that you should use a class instead of a 12 line function, it makes my -1 even more solid. When you start talking about encapsulating the data structure (just in case it changes!), it makes me wish I had another vote to cast.
Aug 15, 2012 at 7:06 vote accept Miquel
Aug 14, 2012 at 16:57 history edited Rafael Piccolo CC BY-SA 3.0
Formatting of word 'if"
Aug 14, 2012 at 15:11 history edited Rafael Piccolo CC BY-SA 3.0
corrected concordancy
Aug 14, 2012 at 14:57 history edited Rafael Piccolo CC BY-SA 3.0
Text about extracting if statements was poor
Aug 14, 2012 at 14:49 history edited Rafael Piccolo CC BY-SA 3.0
Suggestion to extract the items to OrderItems. Added text about extracting if statements to methods.
Aug 14, 2012 at 13:57 history edited Rafael Piccolo CC BY-SA 3.0
Removed last phrase. It has been said already
Aug 14, 2012 at 12:35 history answered Rafael Piccolo CC BY-SA 3.0