• MiserableOldGit (unregistered)

    I'm sure we've seen this before? .... although I guess it happens a lot, I've certainly seen lotsandlotsandlotsandlotsandlots of it.

  • Prime Mover (unregistered)

    I've seen enough apps in my time which do something tree-ish and nesting-ish, and the word is that there is a limitation to an arbitrary depth. When asking why that is the case, I get told, because it just is, all right?

    So, no actual business requirement, no words in the specification (apart from the post-hoc-propter-hoc weasel-words in the user docs), just a bossy-boots with the emotional development of a 6-year-old telling me it can't be changed Because. And no, we're not going to fix it just because you need it to work to 4 levels deep not 3.

    Of course, when you go to inspect the source code, you see exactly the same sort of blethering stupidities like we see here.

  • The Dave G (unregistered)

    And I suppose that adding meaninful comments as to the intent of the code is also something they are going to start doing...

    Although, based on the assertion that their code base is littered with code like this (copy paste), I'm also guessing that doing code reiviews is something they (as in their coworkers) also intend to start doing...

  • Foo AKA Fooo (unregistered) in reply to The Dave G

    I think the comment only refers to this blob of code which is copypasta in itself, but of course, this doesn't exclude the possibility there are more of those.

  • Brian (unregistered)

    "Works for now." There are few things more permanent than temporary code.

  • Hal (unregistered)

    I don't know whats worse copy-paste programmers that don't really understand recursion and are afraid to actually try it or copy-paste programmers that don't really understand recursion and run with it anyway.

    This is a good example where I suspect a loop (you pick your favorite) structure would be much more understandable and probably at least as efficient to execute and not much longer to express. It also does come with all the potential gotchas like stack exhaustion, will it ever terminate, for the amateur hour developer here.

  • Jay (unregistered)

    So he's formatting a long string by putting <br/> tags between words. He could re-write this with string.split:

    if (website_description.length() > 25) { String part1 = website_description.substring(0, 20); String other = website_description.substring(21); String parts = others.split(" "); websiteWrapped = part1 + "
    " +others.join("
    ") } else { websiteWrapped = website_description; }
  • conartist6 (unregistered)

    FTFY:

    if (website_description.length > 25) {
      website_description = website_description.replace(/(.{20}[^ ]*) /g, '$1<br/>');
    }
    
  • conartist6 (unregistered)

    Oooh my bad that's actually java not javascript. So FTFY should actually be:

    if (website_description != null && website_description.length() > 25) {
      websiteWrapped  = website_description.replaceAll("(.{20}[^ ]*) ", "$1<br/>");
    }
    
  • (nodebb)

    To do: write a meaningful comment, but this works for now.

  • (nodebb)

    If you're going to nest this deeply, the least you could do is use smaller indents.

  • (nodebb)

    Hardly a WTF, the code is correctly indented!

  • (nodebb)

    What's supposed to happen if:

    • There are more than 7 spaces?
    • The value of website_description.length() > 150?
    • There are no spaces after position 20?
  • Duke of New York (unregistered)

    Pick your poison:

    1. Jake's team doesn't review code changes.

    2. They review changes but, but Eddie is "that guy" who refuses to cooperate in the process.

    3. Someone reviewed and approved this code.

  • guilty as charged (unregistered)

    I'm definitely guilty of this sort of thing. When you know how far you need to go, sometimes it's just a whole lot quicker and easier than doing it the right way.

  • Carl Witthoft (google)

    How To Achieve Brevity:

    Sometimes you just have to recurse Sometimes you just have to Sometimes you just have Sometimes you just Sometimes you Sometimes

  • MiserableOldGit (unregistered) in reply to Hal

    I'd say one of the things I like about recursion is that if someone who doesn't know what they are doing attempts they usually spend so much time rebooting their computer and trying again that the end result never makes it anywhere near production.

    I'm sure someone here has good horror stories though.

  • Duke of New York (unregistered)

    This is a poor candidate for recursion in the first place, but besides that the first rule of writing recursive code on the JVM is: Don't

  • Anon E. Mouse (unregistered)

    Actually, I've HAD to do this because of the stupidity of the VBA handling of SQL large text fields. Even though both the VBA and SQL are large text, somewhere in the data flow path it truncates the 2000 character note field. So I had to write the most ghu awful code to look for a space somewhere around character 200, create a d1 field from 1 to that. Then look for a space around 400 and create a d2 from the first space to this one, etc.

    I did more than the usual Google searches and MSFT KB and found reports every couple years of this since 2003, never resolved.

    So although it's a horrible hack, I felt in good company.

  • Sole Purpose Of Visit (unregistered) in reply to Duke of New York

    Knowing nothing about the JVM (I work with .NET right now), I'm sympathetic with that view.

    Limited recursion, provided you obey the golden rule of reducing your data set on each call, is fine. Ish. But there's no tail recursion on either platform (neither is there on Python, because Guido famously objected to it). Effectively, this means that unless you use trampolining, you're gonna bust the stack at 256 frames ... and let's be honest, nobody ever thinks very hard about that limit.

    What happens in Function Programming ... stays in Functional Programming.

    (Mind you, I assume F# has a way round this. No idea what it might be.)

  • (nodebb) in reply to Brian

    There are few things more permanent than temporary code.

    That's a common phrase used about those temporary prefabricated classrooms you find in a lot of schools, you know the ones, older than most of the kids and yet somehow only supposed to be temporary.

    And yet, in the lycée (it's in France ==> it's a lycée) across the street from my appartement, they are (slowly) pulling down a bunch of them. (They've been standing empty and roofless for a week now, although the snowy cold might have something to do with that.=

  • Adam (unregistered) in reply to Sole Purpose Of Visit

    (Mind you, I assume F# has a way round this. No idea what it might be.)

    The CLR has native support for tail calls, there's a dedicated IR instruction for it. Although AFAIR nothing but the F# compiler emits it these days.

  • TheJayMann (github) in reply to Sole Purpose Of Visit

    Technically, the .NET runtime does have a tail. opcode, which must proceed a call to method, and allows the current stack frame to be destroyed before calling the method, rather than after. However, C# does not appear to make use of this opcode currently, which is why it would appear that .NET wouldn't support tail calls.

    In the case of F#, in addition to making use of the tail. opcode, the compiler will prefer to rewrite the recursion as a loop if it is able. As an example, if a recursive function is implemented as a pattern match over a DU, where some of the cases recursively call the function as the last operation in the expression, the IL emitted is actually br IL_0000, which is essentially a goto statement pointing to the first instruction of the method, essentially making the entire method a while(true) loop.

  • neveranull (unregistered)

    It's just as well they don't add a comment. They'd just copy/paste the comment along with the code.

  • (nodebb)

    Given their existing approach to co, co, coDING, refactoring is predictable. A recursive call just inside the top level "if" and then ... "turtles all the way down."

Leave a comment on “Self Improvement in Stages”

Log In or post as a guest

Replying to comment #522734:

« Return to Article