• (nodebb)

    f r  i   s    t

    Addendum 2025-09-29 07:02: Lol: there's supposed to be an increasing number of space characters between each of the letters of "frist".

  • Jaloopa (unregistered)
    f r  i   s    t
    
  • (nodebb) in reply to jeremypnet

    Let's try a code block:

    s e  c   n    o     d

    Addendum 2025-09-29 08:03: This didn't work either.

  • (author)

    You need to either use &nbsp; entities or wrap it in a <pre> tag. For a change, this is more about how HTML treats whitespace than it is about our commenting system.

  • (nodebb)

    I can see the ever-increasing spaces in the first three posts just fine on both desktop and mobile. Perhaps Remy corrected them or something else is going on.

  • (nodebb)

    And I thought only apostrophes and ampersands were difficult...

  • (nodebb)

    While I do see an interest ion replacing empty strings with nulls (it means later code than then coalesce them using operators like C#'s ??), it is best done by a dedicated, explicitly-named method.

  • Joe (unregistered)

    I might be the odd one here, but a string function that replaces multiple whitespace characters with a single space sounds to me like a requirement that was given to the developer, not something the developer came up with on his or her own. I would venture to guess that the code is fine but the naming of the function is what's horrendous, here. Trim has a specific behavior that everyone understands (and of course is already available), and this isn't that - I can see why users might want this behavior for some fields. Maybe some contract got rejected by a counterparty because the address wasn't correct (because a user accidentally added a extra space between address components) and that headache prompted the new requirement from the business.

    I've had to add similar sanitation of strings coming from an upstream system where users would copy/paste values from Excel (an address field IIRC), and as you probably already guessed, the trailing newline character that Excel so conveniently adds would get saved and subsequently transmitted downstream to us. At the time I argued that the upstream system shouldn't allow newline characters in their input, but we just said screw it and handled it ourselves. If you want something done right, do it yourself, right?

  • Argle (unregistered)

    I'm with Joe on this. It's not really a re-implementation of trim, but something else entirely, only with the same name. Some months back, I was making some changes to some very old C++ code. To say that the code was awkward was an understatement, but I was also told that the code was written under a lot of time pressure. I think we all know what that means. But what got me was the presence of a cleanly and correctly written quicksort. I shook my head sadly and wondered why someone under pressure thought recreating a library function was a good idea.

  • (nodebb)

    Was it an early version of VB that didn't have Trim, but had TrimLeft and TrimRight and you would have to combine them?

  • (nodebb)

    This code was quite obviously written by someone who didn't like Whitespace , i.e. https://en.wikipedia.org/wiki/Whitespace_(programming_language)

  • (nodebb)

    @Argle

    When dealing with very old code, it's always important to remember a couple things.

    • Lotta libraries came into existence well after the language did. There was probably an era where quicksort wasn't available.

    • Before the advent of the whole WWW & open source universe, so say 1960 to about 2005, discovering the existence of 3rd party libraries, and having the licensing to use them was vastly harder than today. Lotta folks rolled their own do to the ~~difficulty~~ impossibility of locating and using libraries, plus concerns about IP ownership from the suits.

    I remember back in Ye Olde Darke Ageyes of .Net Framework 1.0, the WWW was alive and well. But the supply of 3rd party libraries for anything MSFT had not yet put into .Net was nil. We hand-rolled a lot of stuff that is now built-in or you now have your choice of a dozen 3rd party well-known widely used git packages.

  • Klimax (unregistered) in reply to Argle

    Remember, there is NO requirement to implement qsort as Quicksort. And IIRC back then there were many interesting implementations of C++.

  • (nodebb) in reply to WTFGuy

    Before the advent of the whole WWW & open source universe, so say 1960 to about 2005, discovering the existence of 3rd party libraries, and having the licensing to use them was vastly harder than today

    That's nice and all, but qsort(...) joined C's standard library in time for C89/90.

  • (nodebb)

    Maybe the issue was somewhere else they were splitting strings (say, a name) at the first space and assuming everything after was the other name? For example "John Smith" would be split into "John" and " Smith". Then they inserted " Smith" into the database but couldn't find it because they were looking for "Smith". And even explicitly searching for " Smith" would probably fail because they would " Smith".trim() the user's input.

  • Eric Riese (github)

    Interesting fact: That code basically uses the ASCII definition of whitespace. That's the same as Java's built in trim(). Only with Java 11 in 2018 did Java get String::strip(), which does the same thing: removing leading and trailing whitespace, except it uses the Unicode definition of whitespace.

  • SG (unregistered)

    I can see this being a workaround by someone having XML whitespace issues... e.g. taking text from a nicely-formatted XML string, and wanting to remove stray indenting, etc.

  • (nodebb)

    I always confuse strip() and trim() - they do the same thing in different languages, and when I switch between them I try to do the latest one of reflex.

  • (nodebb)

    A relatively minor WTF here is using StringBuffer when StringBuilder is the preferred alternative since Java 5, unless you need the synchronization. Though maybe this is very old code written before Java 5?

  • Lothar (unregistered)

    Instead of checking explicit values of a character, checking if a given character is a whitespace can simply be done by Character.isWhitespace(ch). This function exists for a very long time (if not even since Java 1.0).

  • matt (unregistered)

    Found a mangled space in your first paragraph: "some time" should be two words here.

    Found a dozen other mangled spaces in your continued use of terrible-looking and confusing half-spaced hyphendashes. (See, I'm being charitable in the context of this article.) PLEASE just use a real dash, or a --, or at least put a space on both sides if you must use a single hyphen.

  • IPGuru (unregistered) in reply to Joe

    [quote]At the time I argued that the upstream system shouldn't allow newline characters in their input, but we just said screw it and handled it ourselves. If you want something done right, do it yourself, right?[quote] WRONG input should always be treated as suspect & sanitised before it is used a trailing new line might be the least of your worries

Leave a comment on “Contracting Space”

Log In or post as a guest

Replying to comment #684847:

« Return to Article