www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Let Go, Standard Library From Community

reply Dan <murpsoft hotmail.com> writes:
janderson Wrote:
 The problem is that every code monkey ends up re-writing the same code. 
      That means a lot of time wasted focusing on writing solutions to 
 problems that have already been solved.  It also means when reading 
 someone else's code there's more to learn, rather then there being a 
 standard way of writing something (more time wasted).  

To that end, I find it takes me more time to learn an entirely new set of types, methods parameters, interfaces and class hierarchy that follow a convention completely unlike the D language itself and the intricacies of the classes I'm working with when they're opague; than I do performing a mere cast on that void[], or merely using char[] rather than String. Furthermore
 things that have been in some public library (not necessarily standard) 
 generally receive a high level of free testing from the community, that 
 means I save more time.

Yes, I suppose it would save you a deal of time debugging if your code has obvious bugs like the two examples I provided for abs(). It would also be prone to gradual improvement accross many applications and therefore be more maintainable compared to reimplementing the wheel each time.
 My approach to coding is to try to do as much re-use as is feasible.  It 
 means I can focus on the actual problem more, not how I get there.

design++; code--; Sounds like a good objective.
 Humm, although I respect your option:  You should know that this is one 
 common interview question.

Interview question or not... my abilities revolve around making code smaller, faster, cleaner, and more robust within the environment they are targetted. Using library code may or may not have something to do with that, but my mentality when I code is KISS, and it's quite engrained. When I see a bunch of code that works, such as raw D source with language features, and I compare it with a library made out of template and class hierarchies, I'm very hesitant. When people start suggesting that we abandon the simple, working code in favor of the complex, I insist on it being justified - this being the stem of this topic. So, I tried poking holes. : ) As for abs(): The IEEE 754 standard is applied accross most if not all platforms, and proposes much the same for 32-bit, 64-bit, 43-bit, 79/80-bit, doubles, floats, and all. The sign bit is the high bit. Putting the high bit in the low bit of a register, and'ing it with the original value and performing a one's complement will give you the absolute value of all but one value - try int.min; then, try it with your other solutions... Sincerely, Dan
Apr 19 2007
parent reply Sean Kelly <sean f4.ca> writes:
Dan wrote:
 When I see a bunch of code that works, such as raw D
  source with language features, and I compare it with a
 library made out of template and class hierarchies, I'm
 very hesitant.

Some points of analysis worth considering are average lines of code, number of parameters, cyclometric complexity, etc. One can't infer much from the simple presence of templates or a class hierarchy. Heck, the presence of templates can suggest more robust code than average, because they tend to prevent code duplication and force a focus on algorithm design rather than type-specific optimizations (which can be a source of bugs). Similar things could be said for classes. Sean
Apr 19 2007
parent "David B. Held" <dheld codelogicconsulting.com> writes:
Sean Kelly wrote:
 [...]
 Some points of analysis worth considering are average lines of code, 
 number of parameters, cyclometric complexity, etc.  One can't infer much 
 from the simple presence of templates or a class hierarchy.  Heck, the 
 presence of templates can suggest more robust code than average, because 
 they tend to prevent code duplication and force a focus on algorithm 
 design rather than type-specific optimizations (which can be a source of 
 bugs).  Similar things could be said for classes.
 [...]

Personally, I find that libraries that *don't* use templates are primitive, because they probably aren't very configurable. You're stuck with what the library designer chose for you. I think in the future, this is just going to become more and more pronounced. All of the most interesting libraries I can think of are extremely generic. I would be interested to hear about counter-examples. As far as re-inventing wheels vs. code re-use, I think it is instructional to look at other engineering disciplines. Which engineers are praised for designing custom bolts and I-beams and steel pipes and wires? The ones who get the recognition are the ones who take commodity items for granted, who choose the best available, and focus on the things that matter, which are the high-level problems. That is, the best engineers are the ones that can abstract away the trivialities and introduce something compelling and new using off-the-shelf parts. Given that architect-level engineers usually need a decent variety of parts to choose from, I think it makes perfect sense that one would have alternatives in libraries. There is also the aspect of healthy competition and alternative tastes. Obviously, Phobos appeals to C-philes like Dan, while Tango appeals to Java-philes like...well, like all the Java-philes out there. ;) I think making them interchangable is the most worthwhile course of action. Rewriting basic libraries is a good exercise for the learning programmer. I reinvented plenty of good wheels in my day, and had a lot of fun doing it. But when you get old and tired, you lose the zeal for wheel-making, and you start to build cars, using parts that other people made. Dave
Apr 19 2007