• (disco)

    paula! what's wrong?

    you're working too good!

    are you trying to save your job?

  • (disco)

    They also re-invented case-insensitive string comparison.

    For the record the enhanced for statement works with lists just the same, they could have done this:

    for (String s : brandSpecValues) {
    
  • (disco)

    True enterprise programmers don't hard-code this sort of splitting! They delegate it to a service via their Message Bus! Like that, the most cost-effective solution for their string-to-sequence processing needs can be found and purchased (via the dynamic contract negotiation service) without any need to bind anything to a fixed implementation at all. Flexibility for all!

  • (disco)

    Also they included valueable and monetizable performance gain potential by not short-circuiting the search. Enterprise!

  • (disco)

    Maybe some of brandSpecValues's elements are comma-separated lists, which they wanted to flatten?

    Also, does Java List's toString() really add [] around the list but not put each string element into quotes? :wtf:? Cause I don't see any code which would remove those quotes.

  • (disco)
    PHP GONE WRONG

    That a book about Java? :trolleybus:

  • (disco)

    AND it does brandSpecValueString.toUpperCase() on each comparison to a value from the array. Absolutely brillant.

  • (disco) in reply to dkf

    Additional advantage: there won't be a problem ifwhen Mr NIH decides they should reinvent the square wheel on-site.

  • (disco)

    Are there some lines of code omitted or did the programmer really make that horrible beginner's mistake not to escape square brackets and commas before all those operations?

    Additionally, to make code more concise, we could omit the variable listString altogether and assign arr with one line of code.

  • (disco) in reply to PWolff

    Those are plain replace and split, not the regexp variety (which would probably be more enterprisey, I guess).

  • (disco) in reply to Dave_Aronson

    Oh, and none on the initial list, so if for any reason the db returns values not in uppercase, boom no cigar.... (ok, the upper case could be handled in the database view, but i doubt that is the case...)

  • (disco)
  • (disco) in reply to accalia
    accalia:
    paula! what's wrong?

    you're working too good!

    are you trying to save your job?

    It's not going well: [image]
  • (disco)
    the array contains only 5 values ever

    But maybe, in the far future, in a parallel universe, somebody needs 5.5 values.

  • (disco) in reply to Khudzlin
    Khudzlin:
    Those are plain replace and split, not the regexp variety (which would probably be more enterprisey, I guess).

    Good point. So we can assume that the brand specifications per database entry are comma-separated, for additional WTFiness?

  • (disco) in reply to Khudzlin

    Which means if any of the strings in the list contain square brackets, well... they don't. Let's hope they're not supposed to contain bbCode.

  • (disco)

    Welcome to my world.

    I have seen this in various places - VB6, C#, Java, JavaScript and XML.

    I saw it in VB6 where they were passing data back and forth to JS - I forget what the reason was, but IIRC it has something to do with the limitations of passing data between the two in a scripted HTML page.

    I have also seen this in XML where the XML schema designer was too lazy (or more likely, too ignorant, or both) to define a list of child elements for the data, and instead they used an attribute to store a comma delimited list of data - hence anybody who needed to parse the XML and put it into memory, had to parse the comma delimited list.

    I have seen the brackets and commas too - where they had multiple comma delimited lists, separated by commas, contained inside square brackets.

    So it isn't necessarily the Java devs fault - although in my case, it was the Java devs who also designed the XML schema.

    These same people went on to use the same "solution" elsewhere to pass around said data - instead of using a list or array of strings, they passed around comma delimited data as a single param/variable.

    Fortunately, those people are gone, and if I ever catch any of my devs doing something like this, I will take a hammer to their fingers so they can never touch a keyboard again - or at least that is what I tell them.

  • oba (unregistered)

    What would happen if one of he string contained a ',' or a '[' or a ']'? could this be some sort of validation gone to Garbage Collection hell?

  • Aaron (unregistered) in reply to oba

    This code is bad. It's not just asking to be plagued by errors. It's also wrong and wasting space trying to be clever. The items are String already, so if he wanted an array, he only needed to ask: brandSpecValues.toArray(). That is 1/4 of his code and 10x easier to understand. A List is quite literally one of the most perfect and complete interfaces if the developer cared to check documentation.

    It's also a true pain to see that this block of code is just checking if a value /exists/. So at best this is a glorified helper function. The output is as useless as the input and implementation. Using String.toUpperCase() was some intelligence at least, but Java has this option: if (s.equalsIgnoreCase(bspecvalue.toString()))

    I've got coding experience in a few dozen coding languages. Java is a favourite, yet I see a lot of scary Java code that should've never happened. Amateurs abusing and neglecting Java's fantastic OOP implementation makes it a common source of WTFs.

    Despite this, I enjoy reading good Java libraries. Java libraries written by competent programmers are by far the one of the shortest learning curves I've found.

  • Diether (unregistered)

    Luckily we don't have to worry about characters like , and [ or ] in the list. It's reference data, and the list will only contain single character alpha values.

Leave a comment on “String Cheese”

Log In or post as a guest

Replying to comment #463522:

« Return to Article