Slashdot Mirror


Reuse Code Or Code It Yourself?

eldavojohn writes "I began coding for a project that had simple requirements for my employer — Web services and a test application for them. But requirements have been creeping, as they always do. Initially I had decided to use the Spring Framework with Hibernate. And I re-used a lot of libraries that made things simple and quick for me. The new requests coming in involve capabilities beyond those of the frameworks. Now, I used to be told that good programmers write code and great programmers reuse code. It's starting to look like I would have saved myself a whole lot of time if I had written the database transaction using JDBC instead of Hibernate — now that I'm married to this object model framework, some of this stuff doesn't look doable. So what is better for the majority of software projects out there: reuse code, or code from scratch? What elements or characteristics of a problem point to one option over the other?"

48 of 429 comments (clear)

  1. It's knowing when by Bender0x7D1 · · Score: 5, Insightful

    It's not rewriting code or reusing code that makes you a great programmer. It's knowing when to rewrite code and when to reuse code that makes you a great programmer.

    --
    Reading code is like reading the dictionary - you have to read half of it before you can go back and understand it.
    1. Re:It's knowing when by syousef · · Score: 5, Insightful

      It's not rewriting code or reusing code that makes you a great programmer. It's knowing when to rewrite code and when to reuse code that makes you a great programmer.

      Actually it's all of the above and more...a great programmer can:
      1) Evaluate the suitability of existing code for the task
      2) Use the existing code appropriately
      3) Write excellent readable, maintainable code when needed (and only when needed) to fill the gaps
      4) Communicate well with the business to understand the problem and design a solution

      Each of the above skills you're missing decreases your chances of success.

      --
      These posts express my own personal views, not those of my employer
    2. Re:It's knowing when by Artraze · · Score: 5, Insightful

      > - the first case is trying to make the best of what you have and building on that

      To add to this, never ever simply "reuse" code; if you just copy and paste you'll end up with a horribly designed hack job worth of TDWTF. Instead, take what you have and massage it into place.

      In this particular case, it sounds like your design no longer hashes well with the requirements. My suggestion is to start rewriting/reworking isolated portions of the code base and create a temporary compatibility layer (if necessary) to interface with the old code. Continue doing this until the entire application is converted over to the new design.

    3. Re:It's knowing when by ClosedSource · · Score: 5, Insightful

      Well, I think the GP has a point. These days there seems to be more focus on worrying about the future than producing a high-quality product today (where quality means the least buggy product). Often you spend a lot of time creating sophisticated abstractions to ease future extensions only to find that the future is so different than you expect that your elegant architecture is just code bloat.

    4. Re:It's knowing when by Anonymous Coward · · Score: 5, Insightful

      You left out
      5) Say No when appropriate

    5. Re:It's knowing when by f1vlad · · Score: 2, Insightful

      Sometimes it's actually useful for one to try to reinvent the wheel, if you will; then for that person to realise that that wheel has been invented already and start using old wheel with the some knowledge gained from aforementioned attempts.

      That is the kind of path I went down. :) Depending on a person, that could actually work quite well.

      --
      o_O
    6. Re:It's knowing when by SL+Baur · · Score: 2, Insightful

      Often you spend a lot of time creating sophisticated abstractions to ease future extensions only to find that the future is so different than you expect that your elegant architecture is just code bloat.

      I don't. There's a different term for that - "Over Engineering". The OO fad has certainly contributed mightly towards encouraging over engineering.

      Avoid putting artificial limitations into code where they should not and need not exist. That will do you well in most cases.

    7. Re:It's knowing when by try_anything · · Score: 5, Insightful

      Did he really make a mistake? He already has one version out and is now finding out what the software really needs to do. That sounds pretty damn successful to me. Now he's dithering about rewriting and replacing some of the libraries, which he would have had to do anyway even if they were custom-written.

      If he had written everything from scratch:

      • Would he even be done coding?
      • Would his custom code be any more adaptable to the new requests than the existing libraries that he used?
      • Would he have ended up coding custom libraries for functionality where his needs were actually quite typical, and well-served by existing libraries?

      His original choice was correct. As far as replacing Hibernate, he's in just as good a position now as he would have been if he had written his own persistence layer. Remember, he chose Hibernate, which turned out to be unsuitable, because didn't know the requirements when he started. He would have been damn lucky if he had just happened to develop a custom persistance layer that neatly anticipated the unknown requirements. So, ripping out or rewriting the persistence layer was inevitable. If you're going to throw code away, it might as well be code that you got for free, instead of code that you sweated and toiled over.

      If you're really dead set against replacing or rewriting any libraries, the only way to improve your odds is to use the biggest, oldest, kitchen-sinkiest, most bloatiest library you can find.

    8. Re:It's knowing when by wwwillem · · Score: 4, Insightful

      On the spot!! If the "poster" hadn't reused code from the get-go he was probably still coding. But instead of now making a choice between "hanging in" and "starting to rewrite", there is a third and IMHO better option: Throw out the framework that doesn't fit anymore and replace it with a better fitting one. Don't jump immediately into the "and now I've to write it all from scratch" excuse.

      Your original "reuse" decision was the right one, but appearently you didn't pick the right framework. Which is normal, because at the beginning of the project you didn't know exactly what the requirements would be. Based on your improved knowledge of the application, you should redo your investigation of frameworks and find one that has the right fit.

      And if you can't seem to find one that fits, you need to do some deep-deep-deep thinking. Is your situation really so unique that nothing "standard" out there will fit in, or is it the too often happening "not invented here" syndrome.

      Don't fall into the trap of "I can do it better myself". Yes, I'm sure you can :-), but you won't have the time!! Or better said, your boss won't allow you the time.

      --
      Browsers shouldn't have a back button!! It's all about going forward...
    9. Re:It's knowing when by kv9 · · Score: 5, Insightful

      The only difference is that efficient people actually get stuff done. Lazy people are just.....lazy.

      my anecdotal evidence shows that lazy people tend to write the most nice code (to make life easier for themselves - futureproofing and all that) while "efficient" people are chugging out piles of shitty unmantainable code for 8 hours a day. I guess it's the old "work smarter, not harder" thing.

    10. Re:It's knowing when by thePowerOfGrayskull · · Score: 4, Insightful

      To add to this, never ever simply "reuse" code; if you just copy and paste you'll end up with a horribly designed hack job worth of TDWT

      The fact that you seem to think that "copy and paste" is synonymous with "reuse" is a bit disturbing...

    11. Re:It's knowing when by Duckie01 · · Score: 4, Insightful

      Did he really make a mistake?

      Maybe.

      He already has one version out and is now finding out what the software really needs to do. That sounds pretty damn successful to me.

      It sounds like a mistake in the design stage to me. Did he interview the people who were going to use his software? Did he understand what they were going to expect from the software? Did he analyze the information needed by the software, and by its users? Did he define the software's scope and discuss it with its users?

      I get the impression he didn't make the mistake of coding *beyond* the requirements, which is almost always a waste of time... But did he take a well coordinated effort to get the requirements clear before he wrote the first line of code or even chose the framework?

      Now he's dithering about rewriting and replacing some of the libraries, which he would have had to do anyway even if they were custom-written.

      Of course you'll chose to use libraries over writing it by yourself. I'd like to emphasize tho that the biggest benefit is not the time you'd need to write the code... but the time you'd need to debug it!

      Libraries have usually been out in the wild for some time, been used in many different situations by different people, been looked at, debugged, improved, simplified and documented. Quite often all the functions in a library have a coherent interface, which makes for easy, "intuitive" use and a short learning curve.

      So on my left I have hard time writing pages of code and annoying debug work, and on my right I have a comfortable ride quickly producing nice looking code that just works.

      My two non-lazy braincells tell the rest of them that it's a no brainer ;)

      [...]

      Remember, he chose Hibernate, which turned out to be unsuitable, because didn't know the requirements when he started. He would have been damn lucky if he had just happened to develop a custom persistance layer that neatly anticipated the unknown requirements.

      Yeah. Very lucky indeed. To get a decent course in software engineering, with an emphasis on interviewing techniques and information analysis. You don't really *need* to just code something out of the blue and be lucky to meet the requirements. It's not necessarily a process of trial and error.

      The people you're writing software for can tell you what it's required to do. You can make a crude design and discuss it with them without even writing a single line of code. Once you have your design you start looking for an environment to implement in.

      I think that would have had a good chance of avoiding the hassle in the first place. Right now he's doing what he should have done before writing the code, and finds his hands tied to a codebase and a framework that he probably would not have used if he'd taken time and effort to get the design right!

      So to the guy asking the question... You cannot answer those questions without getting your design right... treat the code you have now as just a piece of code out there... then trust your laziness to chose the right tools to get the job done. If that's gonna be what you wrote yourself and the framework you're using now, or something else, who cares?

      [...]

    12. Re:It's knowing when by julesh · · Score: 3, Insightful

      The OO fad has certainly contributed mightly towards encouraging over engineering.

      I don't think I would call a form of programming that has been pretty-much the dominant form for nearly 20 years now and is showing no signs of giving way to any other form a "fad".

      I'm also not sure object oriented programming itself has contributed that much to *causing* over-engineering. It just makes over-engineering easier, so is particularly attractive to people who do over-engineer their code.

    13. Re:It's knowing when by theaveng · · Score: 4, Insightful

      I agree. Laziness is often the same thing as "saving time". Why reinvent the wheel when somebody already did the work?

      Here's a good illustration from the 8-bit gaming era:

      - Pitfall II was created by the original programmer for the Atari 2600/VCS. Activision wanted to port this extremely successful game to other platforms, including the new Atari 5200/Supersystem and the Commodore=64. Activision assigned this task to two programmers who also happened to be good friends.
      - The C=64 programmer decided to recreate the whole thing from scratch.
      - The A5200 programmer decided to directly copy the code, and only change the pointers as needed.

      The A5200 programmer finished his task in only half the time as his friend. He then used the extra days to program an entirely new level into the game (think Pitfall III). Reusing the code allowed him to create two games, instead of just one game.

      --
      FOX NEWS.com should be BANNED from television and internet. Have the Congress take it over and give us Truespeak.
    14. Re:It's knowing when by bigman2003 · · Score: 3, Insightful

      This is an excellent example of a project with an end date. The game ships, and then you're done. No updating.

      I've been working at the same place for 8 years, not a long time, but not just a blip on a resume either.

      We are still working on the same projects from 8 years ago. Some of them were built using a framework, some were not. We ran into a lot of problems with frameworks. Honestly, if the projects had end dates, everything would have been fine, but they didn't.

      We found that as time went on, the framework may or may not be upgraded along with the software it sits on. If it doesn't get upgraded, then you may have a problem where you cannot upgrade the underlying software. Sitting on an OS that is 2 versions old because the framework uses that particular API is not fun.

      Another problem I ran into, was when the framework WAS kept up to date. As another poster said, we 'massaged' the heck out of the code. A new version comes out, and there are incompatibilities. The new framework can't just be dropped in. We need to re-do all of our work.

      The stuff we have coded ourselves is easier to maintain. On the downside, any new features need to be written by us. On the upside, that is never a problem. We had developed 18 separate projects in the first 4 years I worked at this place. Now we've been able to morph them all into 1 project. That meant taking them off of the frameworks they were on (3 different frameworks) and code everything ourselves.

      Coding it ourselves ensures that everything works together. If we had re-used a lot of code, then the systems just couldn't be integrated together nearly as easily.

      I've tried it both ways, and for my situation, writing my own makes more sense.

      --
      No reason to lie.
    15. Re:It's knowing when by DuckDodgers · · Score: 4, Insightful

      I think the point is important to clarify for people who legitimately don't know the difference. Not everyone who starts reading Slashdot and thedailywtf already understands good software engineering practices.

      I've even worked with senior developers who think "cut and paste" is code reuse. Clearly they were not spending enough time on sites like this one.

    16. Re:It's knowing when by orclevegam · · Score: 2, Insightful

      Now that Hibernate and EJB3.0 have effectively merged, you might as well learn Hibernate because one way or another you're going to be using the same basic system no matter what you choose (raw JDBC possibly excepted, but in that case you're responsible to maintaining all the JDBC calls and making sure they keep pace with your SQL updates). Hibernate really is incredibly flexible, and I find it hard to believe you could possibly have anything you need to do that can be done in JDBC but not Hibernate (in particular since you can use JDBC inside of Hibernate, although it does remove a lot of the nicer things Hibernate does).

      As for Spring, you might be right in that there are some frameworks that a more true to AOP, and that if you're not careful Spring can bite you, but the basic premise of Spring is definitely a good one. In particular, learning and using the annotation based configuration options of both Spring and Hibernate will go a long way towards improving the usability of both frameworks. Coming from a project in which we ripped out a lot of really nasty singleton code (and byzantine object relationships and factory methods necessary to make it work) and replaced it with a very simple dependency injected model built on top of Spring, it really is a nice framework that can lead to some very clean code. The real beauty of Spring though isn't just the dependency injection (which is nice), but in the very clean straightforward components it ships with (like Spring MVC web framework which is one of the better ones I've seen). In addition, managing transactions through Spring can greatly simplify your project, but you've got to design your persistence layer with clear entry and exit points for each transaction to allow them to be annotated with the start and commit transactions, otherwise you're going to struggle with managing the transactions.

      --
      Curiosity was framed, Ignorance killed the cat.
    17. Re:It's knowing when by orclevegam · · Score: 2, Insightful

      I've long said that better programmers write simpler code. Poor programmers write complex code.

      Better programmers write Elegant code, which is just as complex as it needs to be to get the job done, and no more.

      --
      Curiosity was framed, Ignorance killed the cat.
  2. prototype quickly, optimize later by evw · · Score: 4, Insightful

    If you'd tried to write it all yourself from scratch from the beginning you'd still be coding and you wouldn't have gotten the feedback about what needs to change as quickly. Prototype quickly then optimize later.

    1. Re:prototype quickly, optimize later by somersault · · Score: 2, Insightful

      And if the library you're using has an obscure bug then you could also end up wasting days of work either having to track down a bug or write your own library.. sometimes it will be fine, but sometimes you might not be saving yourself any time at all, depending on whether the library is open source, how many other people have used it and bugfixed it etc.

      --
      which is totally what she said
    2. Re:prototype quickly, optimize later by Bad+Mamba+Jamba · · Score: 5, Insightful

      Except every time I've ever done a prototype it is invariably shipped as product minutes later.

      Naturally disaster follows.

      What you say: "I have a working prototype."

      What management hears: blah blah WORKING blah.

      Moral: Never say you have anything "working" until you're really done.

  3. Why not use both options? by aurelianito · · Score: 5, Insightful

    AFAIK, you can access a DB via both JDBC and Hibernate. Just do most of the job with the frameworks and just the little bit that isn't supported use plain JDBC.

  4. Use JDBC *and* Hibernate by puppetman · · Score: 4, Insightful

    It's starting to look like I would have saved myself a whole lot of time if I had written the database transaction using JDBC instead of Hibernate

    Hibernate is great most of the time, but every Hibernate application I worked on had some JDBC somewhere, and I typically managed my own transactions... With regards to object-hydration, Hibernate (2.x) was an all or nothing, and sometimes I needed something in between for performance reasons.

    Obviously, I don't know the problems you face, but I am surprised that a flexible framework like Spring isn't meeting your needs, and that Hibernate is preventing you from using JDBC...

    1. Re:Use JDBC *and* Hibernate by Shados · · Score: 4, Insightful

      This is indeed the best advice. No framework will ever meet 100% of requirements. So you either use extensible frameworks, or have a facade that allow you to pipe logic either through the framework, or through custom code, as needed, allowing 90%+ to go through the framework, and the last 10% to go through whatever you wish.

      A lot of ORMs (I'm not as familiar as I wish I was with Hibernate) will allow you to use the standard dynamic SQL generation, AND to do stored procedure wrapping and projections... With that, you seriously can do pretty much "anything", except for using the very very latest features of the very very latest version of your RDBMS of choice, such as unsupported datatypes. For the 2-3 queries in the entire app that ends up in that situation, you simply have a custom data manipulation layer (small, not very heavily architected), and both that and the framework just sit behind whatever abstraction facade one may have...

      I also agree with the other part of the advice.... Spring not being powerful/flexible enough? When you have what is basically a "meta-meta-meta-meta-extensible framework" (which is basically what Spring is), its hard to see that something could possibly need features that cannot even be met using all of Spring's extension mechanisms...

  5. Wrong Question by pete-classic · · Score: 5, Insightful

    You should be asking, "Should I make architectural decisions before or after I collect all the requirements." But you know the answer to that one.

    A more experienced engineer would have dug for requirements early, planned for some creep, and would have warned the manager that the risk of starting before the thing is properly speced is that all work might have to be thrown away.

    You'll know next time.

    -Peter

    1. Re:Wrong Question by chromatic · · Score: 3, Insightful

      A more experienced engineer would have dug for requirements early....

      Seriously, has that ever worked for you? (I assume you don't work on space probes.)

    2. Re:Wrong Question by syousef · · Score: 4, Insightful

      You should be asking, "Should I make architectural decisions before or after I collect all the requirements." But you know the answer to that one.

      That's harsh. I've seen the business change it's mind to the point that all that was kept was the project name (and wonder why it couldn't be delivered on time). I've also seen changes driven by legislation or changing business conditions that could not have been predicted. You can't dig for what ain't there. What you're asking him to do is be a fortune teller. The best he can do is try to improve relations and communications with the business, and let them know that the more things change at requirements level, the more time will be required.

      --
      These posts express my own personal views, not those of my employer
    3. Re:Wrong Question by Sloppy · · Score: 2, Insightful

      In the real world, you never "collect all the requirements." That's just plain impossible.

      --
      As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
    4. Re:Wrong Question by E++99 · · Score: 2, Insightful

      You should be asking, "Should I make architectural decisions before or after I collect all the requirements." But you know the answer to that one.

      A more experienced engineer would have dug for requirements early, planned for some creep, and would have warned the manager that the risk of starting before the thing is properly speced is that all work might have to be thrown away.

      I disagree. An experienced engineer would know that he never has all the requirements, and the no spec ever encapsulates every real need that will be realized. Therefore, every project must be built with the assumption of future change and growth.

      The is exactly the problem of the overuse of frameworks like Spring and Hibernate. They too frequently introduce unnecessary complexity and limitations.

    5. Re:Wrong Question by mveloso · · Score: 2, Insightful

      Well, that's the wrong question as well. Only in highly structured environments can you collect all the requirements. And in those highly structured environments (ie: government, military, public safety) how many software projects come out meeting the requirements, are on time, and on budget?

      The answer is probably very small. In fact, I'd guess that the only things that a highly structured development process gets you over a fast, iterative and mostly loose process are (1) CYA material, (2) aggravation, and (3) consulting dollars. You get #2 with any development process, but at least in a structured process you aggravate everyone else as well.

      In any piece of software there comes a time when what you built doesn't fit so well with what your customer is asking for anymore. Lucky for you it happened sooner rather than later.

  6. Re:When in doubt rewrite it by Anonymous Coward · · Score: 1, Insightful

    This is bad advice.

    A system that has been tested for years will almost always be better than something new you've rewritten. Remember that it's more than a developer's resources you're using and no developer writes pristine code.

    I've seen many projects that other programmers have said just absolutely need a rewrite and it's never ended well. Usually, they end up with more problems than they started with.

    If you really need to sanitize the code base, wrap the old stuff. I've had much success with this

  7. What's up with slashdot lately by 1155 · · Score: 4, Insightful

    I don't get it. About 2 years ago this post wouldn't have even been front page worthy, and now we have this? If I wanted to use slashdot as a howto forum, I wouldn't be looking here. I just don't get it, why would a post list this make it to front page? It's for nerds, but it doesn't matter except to a small minority, and it's not news.

    Or am I missing something?

    1. Re:What's up with slashdot lately by geekoid · · Score: 2, Insightful

      Apparently you weren't here 2 years ago. These kind of question have been appearing on the front page for 10 years.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    2. Re:What's up with slashdot lately by blank+axolotl · · Score: 5, Insightful

      it doesn't matter except to a small minority

      Then why are there over 200 comments, more than usual? Good programming practice is an interesting topic for many of us.

  8. That's some serious scope creep... by syousef · · Score: 5, Insightful

    In general it does depend on what application you re-use. If you reuse a poor piece of software you're building your product on shaky ground.

    Now I actually don't like Hibernate and Spring all that much and I use them regularly. Replacing a whole bunch of boiler plate code with a whole bunch of boiler plate XML doesn't actually make your app less error prone. Introducing AOP makes it easy to code cross cutting concerns but can make it hard to debug and understand code as it becomes harder to trace (and instead of a pure stack, you again have to look at XML configuration). Then there's the massive overhead. I'm afraid their popularity is due to software as religion pushed by a culture of marketing, rather than being based soley on techical merit. Hell a few years ago EJB was the word according to Bob, and we all saw how well that went. Try finding a new project actively deploying EJB today.

    That said, I've run into the limitations of those products, especially hibernate, and if your scope has crept enough that they were looking like a good solution, but aren't anymore, you need to address the scope creep first. Some creep is expected, and accomodating the business is always a good idea if you can manage it, but people go too far and forget that sufficient scope creep can and will make your project fail. You need to start by talking to the business and ensuring they have an understanding that the more redesign they do after the initial planning the greater the cost and risk. One other thing to watch out for. Make sure you evaluate whether each request is technically possible in the first place, and whether it is practical to attempt what has been asked with the resources you have. (I've often seen business people make requests without understanding the technical effort required. eg. request a change requiring a full blown compiler be written when the component was suppose to be a very simple parser and was scheduled to take 2 weeks to code. That's not entirely their fault. YOU are the technical staff and need to help them understand what is involved in fulfilling their request.).

    Once you've addressed the scope creep, look at your application again and re-evaluate the tools. It may be possible to divide the project in such a way that you retain Hibernate and Spring for one part (and let's face it they're the defacto industry standard and are going to be the easiest to support in the short to medium term. Long term is harder to predict, but the less popular an approach is the harder it will be to find someone appropriate to maintain your app). The other part you can do with raw JDBC or another tool. (eg. you might find it's the reporting that Hibernate isn't dealing with adequately, so move to JDBC or a reporting framework that takes RAW SQL queries).

    --
    These posts express my own personal views, not those of my employer
    1. Re:That's some serious scope creep... by syousef · · Score: 2, Insightful

      I'd like to know what you dislike of Hibernate.

      Where to start...

      If you're writing something simple with very straight forward relationships and are able to define your database yourself up front it's not too bad. You lose some performance in caching, but also gain some in that hibernate does well using indexes to generate sane queries.

      The idea that you don't have to hand code is only partly true. The low level database calls are indeed done for you but your mapping isn't - some of it is just moved away from Java and into XML (You still have to code the object class...some of that can be done for you if you use the right tools but the tools keep breaking and/or being re-written so a lot of people end up doing it by hand. One of the stupidest bugs I ever introduced to code was mis-capitalizing the instance variable in an accessor for one of the fields that mapped to the DB. As a result, hibernate would null that field and save to the database even though save was not explicitly called - the app ended up clearing out reference data in the database!). So my experience with hibernate as a tool to remove errors hasn't been all positive. My experience with the tools hasn't been all positive.

      Next there's HQL. What an abomination. Not every piece of SQL you can write will map to legal HQL. DB specific stuff, while not a good thing to use in the first place, just doesn't work in some cases (or at least didn't in Hibernate 2. That may have been fixed). You end up falling back on JDBC for stuff that needs that. I even vaguely recall problems with certain standard SQL...certain group by clauses or sub-clauses didn't work.

      Next take a look at the way more complex mappings work. Some of the options in the XML mapping files are not intuitive at all. In fact you have to spend considerable time to understand what they are doing, and even then complete understanding only comes when something breaks. It can be very difficult to tune the mappings so that they work well for all the various scenarios in your application, so you have to make compromises.

      Finally, I've worked on proprietary data access frameworks (mostly in Smalltalk, not Java) and they can be quite a burden to maintain, but I see an equal amount of pain trying to keep up with the latest Hibernate version and work out whether you want to do it their way or use Spring to wrap the data access.

      Talk to a Hibernate fan and they'll come up with something to counter each of the above (as that is the nature of the fan) but as far as I'm concerned Hibernate is not the magical wonderful error free data access framework it's made out to be. There's no such animal.

      --
      These posts express my own personal views, not those of my employer
    2. Re:That's some serious scope creep... by abes · · Score: 2, Insightful

      Hibernate is a pretty good product. It has nice features that allows you to abstract tables into OOP representation. Joins can be specified optionally on column values. And while the XML can be hard to parse, it now allows for annotations to be done in the Java code itself.

      That said, when Hibernate fails, it can often be hard to figure out why. It's error messages can be hard to parse, and difficult to trace where it originates. Also, I've definitely come across places where hacks had to be implemented into object relationships in order to get cascades to work properly.

      If Hibernate has any really big issues, is that it probably promises to do more than it actually can. But with that said, if you need Hibernate to do things outside of its general scope, you probably don't want to use SQL in the first place.

      Instead of placing all your requirements on a single product, it might be worth figuring out how each dataset can be stored most optimally. If you're doing a lot of key-value storage, you can store large datasets with MemCached, and write to disk.

      If you need to do relational queries on some of that data, you can create a SQL representation that points to the data you want. Also SleepyCat DB might be worth checking out.

      Apple has jumped in on the fun in this regard, by making key-value bindings a central part of Cocoa. Again, there are no silver bullets -- use the best tool for the job as always..

    3. Re:That's some serious scope creep... by timewasting · · Score: 2, Insightful

      Wow, I almost totally agree. I hate spring for all the stupid interfaces that usually get created and then replacing simple compile-time problems with hunting through a zillion XML files to try to find what the root cause of a cryptic runtime exception is. I'm also a big fan of EJB3 and it's implementations up the Kodo/BEA/Oracle JDO food chain.

  9. Re:code from scratch by Antique+Geekmeister · · Score: 5, Insightful

    If you want to write from scratch, write your own compiler and build your own system from melted glass. The time wasted encountering and solving a variety of problems already solved by others is very, very easy to describe, and there is little guarantee of even the limited success demonstrated by the best of the older code.

    The amount of time I've wasted arriving after some in-house project that one person wrote, everyone got stuck with, and needed to be ripped out and replaced with the standard open source tool when that one person got transferred away or they discovered its limitations the hard way would have given me a month off of work every year of my professional life. Chat clients may be the worst of the bunch: watching those harsh lessons relearned by every sophomore who just learned a new language and thinks the new language won't run into the same issues is in for big, big surprises.

  10. Re:code from scratch by plover · · Score: 5, Insightful

    Always code from scratch. The time saved from complete understanding of your own code is hard to describe.

    Well, that's certainly the least maintainable answer I've ever seen on the subject.

    If someone has to come along after you and maintain the system, how do they know what it does? Did you document it perfectly? Of course not -- you wrote it, you know how it works, so you'll invest nothing in educating others.

    When you use a library, framework, or a reusable whatever, not only do you get the functionality, but you get the available documentation and a potential pool of developers who are already familiar with that technology.

    I've seen an awful lot of NIH (Not Invented Here) syndrome in this business, and I've seen so many "look, I wrote my own string class, isn't it neat?" that I lost count. No, it's not neat. The STL has provided strings in C++ since 1994 -- if you're writing one in 2008, it's because you're so incompetent you don't know the full language. And the same is true for many of the major technologies. I'm not saying Hibernate is or was the best choice for your shop in this exact situation, but it was likely a better choice than writing your own.

    There's actually a solution that's kind of like a compromise, but offers some advantages: write a thin wrapper around the technology. You can either write a straight 1:1 wrapper, or create your own API, customized to be something you're comfortable coding against. You can then replace the technology with something better, when that something better comes along, and all you have to do is change the wrapper. The other reason this is a good choice is you can provide a mock object replacement for your API and run unit tests against it without bringing up an entire web environment.

    --
    John
  11. Re:Better Requirements Gathering by Todd+Knarr · · Score: 3, Insightful

    The problem is that the standard response from the business people, when I try to anticipate future requirements, is "But we're not asking for that. Can't you just do what we asked instead of adding all this extra stuff that's taking too much time to do?". Part of it seems to be that business wants and is given the authority to add to and change the requirements, but never been required to take responsibility for the consequences of those additions and changes.

  12. Reuse good code as much as possible by TheLink · · Score: 5, Insightful

    Actually, the trick is knowing that you _aren't_ a great programmer (honestly what are the odds that you are a great programmer?), and thus choosing to reuse code from better (and hopefully great) programmers.

    If you wish to delude yourself, you can believe that you are a great but lazy programmer and thus choose to reuse code from other great (and more hardworking) programmers.

    Stuff like Perl + CPAN is good because of all that code you don't have to write. The less code you write, the fewer bugs you make.

    More importantly the less code you write, the less code OTHER people have to figure out. If you use popular libraries/modules whenever possible, other people can just go "Ah, the standard wheel", instead of going "He calls it a wheel but is it really a wheel? Better check, the bug might be there". Or they might even go "Ah yes, it's probably that bug in the standard wheel, when are they going to get it fixed already, meanwhile we'll do the recommended workaround".

    You can also reuse "code" in other ways. For example - using a popular RDMBS is one way of reusing code. With a good database you don't have to reinvent transactions, row level locking and all that. Lots of smart people have done all that work already. And you can use the DB as a common "interface" for other programs (also written by other people).

    A lot of the languages the CS academics heap praises on are powerful for the code you have to write, not the code you don't have to write. Yes it's probably a catch-22 thing, but when it comes to "real world", I'd rather pick the language where I don't have to write so much stuff.

    Prefab may be uglier, but it beats spending 10 years carving that perfect sculpture all by yourself, only to have the customer say "erm I want a sculpture of my wife not my ex-wife...".

    (Note I am not a great programmer, so feel free to ignore me).

    --
  13. Design First Then Build... It Just Never Happens. by nick_davison · · Score: 3, Insightful

    You gain efficiency by understanding a feature set and picking the right tools to do that job.

    The problem is, most people/organizations desperately want to build something now, so they feel something's happening, then keep tweaking it all over the place until they're happy, totally changing the spec once it's underway.

    In short, they want you to do the job in order for them to then understand it - making it nigh impossible to select the right tools at the beginning.

    Most of the really great, really efficient systems are built by someone who had a firm idea, figured out all the aspects, then got on and built just that. Or they played with ideas, building multiple prototypes that likely weren't very efficient, then went back and rebuilt it with what they'd then learned.

    Most systems aren't like that. They're designed by committee who won't think through most issues until they see a working version. They essentially force prototyping on you - yet consider what you're building the final system and won't pay for you to do a final rebuild. As a result, they're bloated and suck.

    Welcome to the real life of a programmer. Yes, code re-use is something great programmers do. But only if they have great designers who really think everything through first. If you ever find such a mythical beast, let me know and I'll be clamoring to work there too.

  14. Re:code from scratch by Bodrius · · Score: 2, Insightful

    I think the anonymous coward may have been trolling with the unconditional statement, but there is a valid (if expensive) point there and I would suggest a different (additional?) compromise: if you really want that 'complete understanding' for a brand new problem, write your own prototypes from scratch. Then choose and reuse a mature, complete solution (or write your own only as a last resort).

    Wrapping an existing solution in your own APIs rarely teaches you much about the underlying problem - it helps in a lot of other ways, including experimenting / investigating solutions to reuse. But I think it misses the 'complete understanding' point.

    Writing a solution from scratch (even a bad / hacky solution) does give you a much better understanding which is extremely valuable for you - that's why we do that for the classic problems all the time in college, after all. Of course, no one should be writing their own C++ string class these days, but if you wrote your own string class *once*, it helps you to understand the implications when you use the STL or something else.

    But unless you are an academic, that's normally not what you are being paid for: you have a project to complete, and a specific problem to solve in the best possible way. Reusing a mature, tested solution is almost always simply in the best interest of the project - even if you do not learn as much as you would by writing your own.

    On the other hand, if the problem is different and tractable enough, hacking your own prototype from scratch can give you better understanding that is applicable to any 'real solution' you adopt - and if kept simple enough, can be used for unit-tests, benchmarks or other purposes.

    It's a matter of time and resources, but often enough prototyping your own wheel is well worth the investment - just use it as a tool to choose and apply the best solution for problems that are not well understood. Not as an excuse to risk the quality or cost of your project for the sake of pet projects and personal pride (which is often enough where NIH leads to).

    --
    Freedom is the freedom to say 2+2=4, everything else follows...
  15. Re:Reuse good code as much as possible by ClosedSource · · Score: 4, Insightful

    "Actually, the trick is knowing that you _aren't_ a great programmer (honestly what are the odds that you are a great programmer?), and thus choosing to reuse code from better (and hopefully great) programmers."

    This is a similiar flaw to believing that ISO certification means that a company will always create great products. Just as each product should be evaluated on its own (the UL approach), so software should be evaluated on its merits, not on the reputation of the programmer.

    There's no such thing as a "great programmer" in the sense that one individual excels in every aspect of software development. Average programmers (whatever that means) are quite capable of producing quality code. Quality code depends more on the dedication of the developers on the project than it does on programming IQ (again, whatever that means).

  16. Re:Reuse good code as much as possible by SL+Baur · · Score: 3, Insightful

    Stuff like Perl + CPAN is good because of all that code you don't have to write. The less code you write, the fewer bugs you make.

    Stuff like Perl + CPAN is also a very mixed bag and has likely caused my employer very much expense towards working around limitations in code therein compared to what has been gained. I know they've spent upwards of 6 figures on my time and others in direct and indirect costs working around the limitations and bugs in Storable, to name one example.

  17. Re:Design First Then Build... It Just Never Happen by julesh · · Score: 3, Insightful

    The problem is, most people/organizations desperately want to build something now, so they feel something's happening, then keep tweaking it all over the place until they're happy, totally changing the spec once it's underway.

    Actually, if it's done right, that's the best thing to do. Why? You produce a first release _quickly_ without having to worry about the features that are several versions down the line. That release is adopted and the customer starts actually using it. Whatever happens, they're now actually getting the benefit of having the useful software that you have written for them.

    And sure, they might decide that it's wrong in some critical respects. But at least they have _something_ to work with while you're making the changes they requested.

    Most systems aren't like that. They're designed by committee who won't think through most issues until they see a working version. They essentially force prototyping on you - yet consider what you're building the final system and won't pay for you to do a final rebuild.

    I've never had a client who expects to get free changes to the working software I've delivered that meets their original spec, even when they decide it's not what they wanted. Well, OK, there was one. But the court agreed with me and made them pay up. That's in over ten years of professional software development. I've had clients who ended up with bills nearly double what they originally expected, but they've paid happily because they knew I delivered their original requirements, but those requirements changed. They know I charge per feature developed, and I always make sure they know before I start work on it what each feature will cost. Generally speaking, they're all happy with that.

    Yes, code re-use is something great programmers do. But only if they have great designers who really think everything through first.

    Some of the best code reusers I've come across are agile developers who espouse not thinking through anything beyond the feature you're working on at the moment. Reuse doesn't require ahead-of-time design, but it does require a lot of attention to detail. In the OO world, it requires a good understanding of design patterns (which means when not to use, as much as it does when to use them). It requires the ability to understand what your code is doing in great detail, and to hold a large chunk of that information in your head at once, to enable you to spot where another piece of code is doing something similar to what you're trying to do now. It requires you to have sufficient confidence to rework that old code to better fit its new application, where necessary (which normally means you'd better have good test coverage of it). But it doesn't seem to require you to identify the opportunities for reuse in advance.

  18. Good Programmers Abstract by smartin · · Score: 4, Insightful

    Where possible, you should never expose your choice to use an underlying technology. Instead wrap it in an Interface that exposes the functionality that your application requires and hide the implementation from the rest of your work.

    --
    The difference between Canada and the USA is that in Canada healthcare is a right and gun ownership is a privilege.