Slashdot Mirror


Reusing and Recycling Code

An anonymous reader sends us to a writeup about when and how to recycle code, excerpting: "As developers, once we start separating our code into abstract ontological typologies, we make use of the human mind's phenomenal ability to work with types. Our code becomes less about jump tables and registers and more about users, email messages and images. What once was a problem of allocating resources and operations within the computer becomes an abstract, logical problem within a collection of objects....Over time, by constantly working to reuse our own code, we choose practices that work well for ourselves and discard practices that don't work as well or slow down our workflow. For developers flying solo or those working on small projects, this evolutionary process is a sufficient way of going about things. But there's trouble when we add other players into the mix--other developers, a user interface person, a database person, a sysadmin, a project mana-jerk: as a developer, they don't have access to our 'experience' of the code and we don't have access to theirs. "

17 of 114 comments (clear)

  1. Recycling isn't always good by Anonymous Coward · · Score: 2, Insightful

    This assumes the code is good. If it isn't, it's akin to eating your own vomit.

  2. Knows his stuff by Anonymous Coward · · Score: 1, Insightful

    Drink a lot of vodka and red bull and black out when you code so that you can approach it with a fresh mind the following day

    A solid recommendation from an insightful article. Should be in every corporate coding guide.

  3. what the hell is the question? by roman_mir · · Score: 3, Insightful

    What is the question in this 'story'? Is this about coding for money or free source or what?

    If the question is about coding for money then it is the responsibility of the team lead/designer/architect to make sure that the business problem is divided into pieces in a way that allows different people to work in parallel (if there are multiple people on the project.)

    If the question is just about some abstract idea of 'code reuse', then the answer is simple: libraries. Create libraries and document them (otherwise they are useless really, without anyone knowing what the hell is inside.)

    In any case, please document the purpose of the code, and then break the higher level requirements into more granular ones with clear specifications.

    In all cases divide, concur and document well seems to work best...

  4. Hell is other people by leereyno · · Score: 4, Insightful

    Hell is other people.

    Having to work with people for whom the Peter principle has reached its end state is exasperating at best.

    Then you have the emotionally unstable, the delusional, the political operators, the empire builders, the saboteurs, the goldbrickers, and of course the fearful.

    Is there some reason why I would WANT to work with this motley crew of idiots, assholes, nutjobs, and losers?

    Success isn't about a paycheck. Past a certain pay grade the money ceases to be a factor. I'd much rather get an adequate paycheck to work in an environment that is conducive to success than be paid generously to work someplace that sucks.

    --
    Muslim community leaders warn of backlash from tomorrow morning's terrorist attack.
    1. Re:Hell is other people by wkitchen · · Score: 5, Insightful

      And then there's the skilled but arrogant jerks who deride anyone they think they're better than, which is almost everyone. Just one of those guys can bring dysfunction to what would otherwise have been a productive team. You REALLY don't want to get stuck with one of them on your team project.

      And it's a real shame, too. Some of those guys actually are as talented as they believe themselves to be, and if they weren't such assholes, could have made the team better by showing the others better ways to do things. And no, I don't mean hand-holding or playing teacher, but just the influence of having the others see what really good work looks like. Leading by example, in other words.

      These guys aren't useless, however. There are problems that are well-suited to single-handed solutions. Just keep them far away from anything that requires close collaboration, and both they and their employer's will be happy.

    2. Re:Hell is other people by Anonymous Coward · · Score: 2, Insightful

      Success isn't about a paycheck. Past a certain pay grade the money ceases to be a factor.

      Actually, after a couple of decades in IT and enough financial inertia along the way to avoid becoming rich, success is **only** a paycheck. I see the march of cybernetic progress as a superstructure upon which the march of coral-like growth of business and science proceeds. It proceeds, by and large, by the energy system known as money economics with a few motivational impurities thrown in for colloidal structure.

      Very, very few of us code monkeys have reached that pay grade where money ceases to be a factor. After enough years at it, the challenges to be solved aren't that challenging any more and reach a certain "meh" stage. And unless you're one of those rare minds who are both bright as XKCD and willing to stay in the same channels, you'll reach a point where any IT job becomes just a money pump. You need to transcend.

    3. Re:Hell is other people by Mutatis+Mutandis · · Score: 4, Insightful

      Ah well, sometimes I think I am like that. Often, really. Yes: Actually, I do think that in comparison with everybody in our IT department, I am a better coder, and a better architect, and a better ontologist. Arrogant nuisance? You bet.

      So, from a certified jerk's perspective, let me tell what we need to be effective members of a team: An effective sparring partner. Seriously. What makes me a frustrated, tired and emotional team member, is that so many supposed team meetings are only unidirectional exchanges. Sometimes I sit there and watch the other members of the team grinding their way through all the little problems of system integration. Sometimes they sit there and watch me sketch a new ontology, architecture and object model.

      Such a grouping of people is not a team. It is a group of people sitting in the same room, but at cross-purposes, because we are not talking at the same level. At best we succeed in confusing each other, at worst only in boring each other. I think they are parasites. They think I am an arrogant jerk. Rate of progress, in that constellation? Nil.

      Yet I can work in a team. I've worked for years in highly effective teams, and with success. I can tell you what made all the difference: The presence of equals to debate issues with, so that we could talk each other through the problems and emerge from the session with the feeling that we had defined better solutions. Perhaps we are all arrogant nuisances, but as long as we understand and respect each other we keep each other in check, and can function as effective team members.

      The moral of the story, as far as I am concerned: Effective teams need a core group of several people with the same high level of skill. You can put in a few people with less skill, so that they can learn from the others. But you should never try to assemble a team of one wolf and five sheep, because that becomes either a classroom or a dinner opportunity, never a team.

  5. -1 brain fart by Anonymous Coward · · Score: 2, Insightful

    I fear TFA is not a joke! Unobtrusive script starts with valid markup, not garbage like this...

    <input type="star" name="rating" value="4.5" size="5" />

    That (type=star) is fine if you're going to pre-process it on the server, only a moron would boast about sending markup like this to the client. If the author of this rambling bullshit article knew what he was doing, he would have used an input image type and class name of "star".

    The rest of his article is similar 'junior developer above their station' type stuff. I do like the way the author of this article on code reuse makes a swipe at the concept of an "API" before going on to detail his own API (making a decorator with an Event_Manager $events property).

    Being charitable, I could say TFA is incoherent nonsense. I've almost made all my charity contributions for this fiscal year, hopefully the author will keep that in mind before writing any further ludicrous articles.

  6. Simple metaphors... by argent · · Score: 4, Insightful

    That should be called "the lesson of UNIX". UNIX provided an amazing simplification that provided almost everything users and developers needed with fewer than 40 system calls (maybe half a dozen frequently used) and a single way of talking to all the objects in the computer system. People who haven't used older operating systems can't really appreciate this, but just opening and reading files used to require understanding something the size of the X11 documentation, you typically had umpteen kinds of files with half a dozen access methods each, with different calls to read blocks, fixed-size records, variable-sized records, padded and unpadded records, three varieties of carriage control, and if you wanted to read or write to a terminal or printer or card reader you had completely separate sets of calls for each. And to simplify this you had record management systems which had their own walls of documentation. And you had to understand this if all you wanted to do was to read a report from a program, because of course every programmer had learned their own bits of this and used them... so even if you didn't care about block-padded variant numbered record files with Fortran carriage control, you had to be able to deal with it. When I ported a Forth interpreter to one system, I had the whole interpreter called from a Fortran main because that let me push the whole problem off on the Fortran runtime instead of figuring it out myself.

    This was worse than the line ending differences between UNIX and Windows, which are bad enough.

    It's like *every* file, even plain text files, was in its own OOXML format.

    Even if you only dealt with one computer and one OS.

    UNIX didn't do any of that. It just made everything into a stream of bytes. For the cases where that wasn't enough, you got the whole records-oriented stuff back... in libraries. And when you used those libraries you had to deal with all the old complexity, but you only had to deal with it when you actually needed to. And lots of old timers insisted that this was backwards, that the OS was the best place to do that, so all the programs worked the same way... but the fact was that all the programs didn't work the same way, because (just as for text files) they all handled their own files and didn't handle anyone else's, and you still had to have utilities to convert data from one format to another. And you had to do it for everything.

    When you're designing an API, look for simple metaphors. Look for a model where most of the time you don't need to specify any complex parameters or callbacks or helper routines. Leave a way to hook extensions in, sure, but for most software you should be able to do 80% of the things you want without having to turn to the second page of the documentation.

  7. Old School Old Fart by superid · · Score: 4, Insightful

    I'm probably going to be shouted down but in my 30 years of coding, I *rarely* reused code. Platforms change, toolchains and libraries change (glibc vs libc6), languages change, system architectures change (heavy client, client/server, n-tier, distributed) and system requirements change.

    Example, a lot of what I have done over the past 10 years uses some standard navigation libraries that probably could have been 100% portable. Lat/lon to range bearing, rb2ll, etc. We've never even discussed IF it would help to make a single standard project library, even though I can absolutely tell you we will rewrite these again on the next platform.

    I can't even look back on 10 years of coding and say "Oh things would have been so much better if we had shared code". I don't think that is the case. And fwiw, this is teams of 5-20 programmers on significant projects.

    1. Re:Old School Old Fart by Jerry+Coffin · · Score: 2, Insightful

      I'm probably going to be shouted down but in my 30 years of coding, I *rarely* reused code.

      Donald Knuth recently said: "I also must confess to a strong bias against the fashion for reusable code."

      Personally, I think a lot depends on the sorts of things you do, and (probably more importantly) the way you tend to think. A few decades ago (or so) when I started college, Pascal was the cool new thing, and top-down development was going to save the world. At least IMO, top-down development has some very good points -- but code reuse isn't one of them.

      OTOH, some people tend to work and think primarily bottom up. For them, work on a particular project basically consists of building a good library for that type of work, and once they have a good library, that particular project is little more than building a user interface to give access to those components.

      One big problem is that code reuse has been pushed as a good idea for long enough not that a lot of people who simply don't have the mindset to produce reusable code still feel that they should do so, and feel guilty if they don't. IMO, this is silly -- there's a lot of room for both kinds of development, and IME, successful projects rarely stick to one direction or the other -- rather, there's a tendency towards some people working bottom up, and others top-down, and the project as a whole is more or less a "meet in the middle" approach.

      Of course, getting this to work requires a fair amount of care -- in particular, you need to ensure against a major "fault line" where the top and bottom sides meet. Unfortunately, I don't have an easy prescription for preventing that -- if I did, I'd probably be the author of a famous book instead of some unknown guy writing on slashdot... :-)

      --
      The universe is a figment of its own imagination.
  8. Simple by pjt33 · · Score: 2, Insightful

    Without RFTAing, I would estimate that it's 95% certain that the question behind this story is "How can I get a few thousand people to hit my ad-laden page?" And the answer is "Anonymous posting of a link to Slashdot."

  9. Re:Saving the environment by marcosdumay · · Score: 2, Insightful

    I reluctantly have to say that if we want to avoid writting unnecessary code, we should abolish emacs, not vi.

    I'll miss it :(

  10. !saving environment by Anonymous Coward · · Score: 2, Insightful

    I tire of people who claim that _anything_ we do helps to "save the environment". Everything we do helps to _destroy_ the environment! So long as the "saving" factor is less than 100% of the damage we produce, we have done nothing to "save the environment".

    I'm sick of the "we want to have our cake and eat it too" attitude people have over these issues. The way corporations and the majority of consumers live today, almost NOBODY can claim to care about the environment. If you own anything manmade, you've directly contributed to the planet's destruction. Yes, really.

    1. Re:!saving environment by foniksonik · · Score: 2, Insightful

      Uh i tire of people who think that we humans are somehow not a part of the environment... and that everything we do somehow is "destroying it".

      We are a part of the environment and what we do certainly changes it but that doesn't mean we are destroying anything.... in fact the law of conservation of energy states very explicitly that we are quite incapable of destroying anything at all. We can only change things.

      Now given that we can and do change things, some changes we make impact ecosystems which otherwise would not be impacted by other natural phenomenon. The degree to which this can be construed as "destroying the environment" is debatable. As is the nature of this so-called "environment" which you speak of .

      So really what you want to say is :"Save MY environment... the one that i have come to know and love - as change scares me and i'm worried that whatever environment may result if we don't save this one could make my life difficult"

      --
      A fool throws a stone into a well and a thousand sages can not remove it.
  11. Re:Nothing to see here.... by Gorobei · · Score: 4, Insightful

    I think the article actually hints at a deeper problem. If we broadly divide programmers into categories:

    1. Code monkeys. Write code, happy when it kind of does what is required.
    2. Architects. Design and implement libraries and their APIs to make stuff easily usable.
    3. Ontologists. Design and implement philosophical frameworks that make big systems work.

    then we can put LISP macros somewhere between levels 2 and 3.

    In terms of reuse, level 1 code should just be ignored, level 2 code is a good candidate, and level 3 ideas will be automatically reused.

    Unfortunately, it is natural for programmers to want to crawl up the scale: code monkeys create bad APIs; architects create bad ontological systems; ontologists wander off into category theory. Sometimes, the developer gets it right, but 90% of the time she just leaves an attractive nuisance lying around.

    Given a big system (say 1m+ LOC,) I want something like 3 ontologies, 100 subsystem APIs, and 3000 enduser things (reports, feeds, GUIs, etc.) If I see another 5m LOC system with hundreds of AbstractFactories and XXXFacades and YYYAdaptors, I am going to start shooting people.

  12. This guy is behind the times! by Jane+Q.+Public · · Score: 2, Insightful

    I strongly suggest he read a few (5 or 6 year-old) books on Agile programming techniques, and maybe start working in a modern language like Ruby.

    Do not misunderstand! I do not dispute much of what he writes. The problem is: what he writes about are old problems that have already been addressed by others. Maybe he should spend a bit of time studying what others in the industry are doing/have done, before wasting his time writing what others have already written, and better. Far better.

    If you want to be a cutting-edge programmer (which is what you had better be if you are writing about how others should write their programs), I think it behooves the writer to be more-or-less up-to-date on the subject himself.