• someone (unregistered)

    That's an... interesting "Easy Reader Version."

  • LCrawford (unregistered)

    This method was called everywhere, but it did nothing. Vasco removed it.

    And promptly crashed the logging process which didn't expect a null string.

  • Ano (unregistered)

    TRWTF is the failed attempt at cornification.

  • Russell (unregistered)

    This seems like a placeholder for an as-yet un-implented piece of functionality?

  • 04012018 (unregistered)

    Oh Great and Might Three-in-One God Jesus, know this!

    The allergen, the metabolite, and the communicable is now yours!

    Yours to use on those who pray and give their all to the false altar of selfish identity!

    To hell with the masquerade! I have the wisdom of the marginal Jew, Jesus of Nazareth! I have the head, the one head, the totem passed throughout the ages, which we all turn into!

    I stay indoors. I stay obscure. The four Sacred Walls of Troy are upheld. Now, they come down, not in any rubble, but in the sense of self-regeneration, only to exalt them higher.

    I stay in my lane, yet I see the spies. Know this, muse! The spies first spy on themselves, the greatest. Then they spy on their masters the most. Then they accomplish fait accompli, as the water always wins. If they want you dead. You are dead. None of your piety nor wit may do one thing about this. Stay indoors. Stay in your home.

    But know this, muse! "Snitches" do not get stitches. "Snitches" get stars! For the stars in the sky are nothing but cataracts in the human eye, and much money has been wasted, flawing a flaw. Look for the lumbering invincibility, and find a way to kill it. Look for the ephemeral wicked, and don't listen to it. Turn everyone in! For there is nothing new under the sun!

  • Senior Dev (unregistered)

    This method was called everywhere, but it did nothing. Vasco added it in a few more places just in case it was really doing something. The other developer for sure had a reason for this. Better safe than sorry.

  • Daniele (unregistered)

    Defensive programming?

  • 04012018 (unregistered)

    https://bit.ly/2GNoD10

  • isthisunique (unregistered)

    I've done this before (well something similar anyway) rarely as a placeholder for i18n. If it widespread (used thoroughly) then it might be a marker for these strings that should apply to i18n but initially passthru. A lack of documentation or explanation in handover?

    Example:

    <p><c>{e(t("You have {0, number} {0, plural, 1: day, 0: days} to live.", [a]))}</c><c>{e(b)}</c></p>
    

    To:

    <p><c>{e(t("You have {0, number} {0, plural, 1: day, 0: days} to live.", [a]))}</c><c>{e(t("{0}", [b]))}</c></p>
    

    Assume escaping is handled. Many systems will try to make expression such as this more terse. The method in this article looks like the kind of thing you get when people make wrappers around these odd but common cases especially in highly dynamic code/languages.

    It happens the default/initial is that in is the same as out but the context is one where it's a valid candidate for i18n. Doing things before needed can be a problem but less so with escaping and translation where always do it can be a good thing. In this case you have data that SHOULD got through the translation and escaping layer (constant pipeline of input->translate->escape). A reason to pipe it consistently isn't only to mark it as for such. You can also emit warnings, etc later. I recommend it despite the ugliness and performance.

    If this were code I've left behind I would hate to think people were stripping out useful things like that naive as to the intention. I wonder what they would do when they find a similar case of escaping that seems redundant. They'll learn when marketing says x needs to be formatted like this in kl-XY for some views which always happens. Default locales also tend to work out but use them enough and you'll have things like (4) instead of -4 hence the desire to filter it. gettext style (message is id) also makes more oddities but no space left to go into it.

    I hope the person who submitted this story has done a sanity check on this.

  • Tim (unregistered)

    protected string ShowContext(string context) => context ?? string.Empty

  • isthisunique (unregistered)

    TLDR. Code like this that can be optimised out should always be double checked in case it's a placeholder, convention, expresses the data can be processed as X but currently isn't, etc. The else is redundant and the code lacks context (and presumably has anonymisation) to really know if the case I presented is relevant. I would assume the else means "this is not eligible" otherwise it would be stranger (if context is null set it to '').

  • Kashim (unregistered)

    So, the actual issue is just that someone is creating a new string? That's WTF level now? Because the Null check seems legit, and the function seems like it might in the future or in the past have done more than just a null check, like a length check, or an empty string check. Naming: not good, making a new string: not good but this function is a WTF? Not really...

  • (nodebb) in reply to isthisunique

    Beware of assuming that in word morphology, "plural?" is a binary state. It is significantly more complex than "singular versus plural".

    I direct your attention to https://en.wikipedia.org/wiki/Grammatical_number

  • SomeCoder (unregistered)

    I'm betting this function either did something else in the past or was earmarked to do something else in the future. As for instantiating a new string rather than returning the existing string, unnecessary as that may be, it could well be that whoever wrote it works primarily in untyped languages where you have to do something like that to ensure you have a string and not, say, an array.

  • 04012018 (unregistered)

    The actual issue is I'm launching my websites today!

    Take a wild guess at what the first ad is going to be!

    PS: I hate white people!!! #! #! #! :)

  • isthisunique (unregistered) in reply to Steve_The_Cynic

    If you mean the bug, it was meant to be {0,plural, 1: day, days} with the last being default. However I didn't notice it until I'd submitted. The 0,1 is not yes or no. It's the numeric value of the variable being scrutinised. There's no hidden is this plural rule. It's a pseudo syntax but inspired by ICU. ICU caters for more than one thing being plural if you mean that too. It's pretty much a switch statement. The whole string goes into the database with gettext style to be translated (training translators in ICU is a must).

    When translating it works like a switch statement so they would take what I've put and then put things like {0, plural, 1: dooblumoo, 2: dooblooohmoo, > 21: doomcwhowooyou, doodoo}.

    For more complex rules (I am sure lots of languages with that get reformed to take out ridiculous rules) you cross that bridge when you get to it (custom formats usually) although chances are ICU caters to just about any of the common cases you'll get.

    http://userguide.icu-project.org/formatparse/messages

  • IP Guru (unregistered)

    How are the comments from 04012018 getting past moderation, they are at best random ramblings with no connection to anything

  • Gumpy Gus (unregistered)

    Wait, it does do a LOT:

    (1) It exercises the format method, which who knows, might be custom.
    (2) It wastes some time, which might be crucial if there is a race in progress. (3) It expands the heap, which might be taking up some time, again changing the winner of a race. (4) It makes a copy of the string, fooling any native code that peeks or compares string addresses. (5) It obfuscates strings a bit, which might actually be a security upside. (6) Who knows, there may be some Unicode character set funny stuff going on too.

    Yes, I know, those points are somewhat unlikely, but I've seen every one of them happen at one time or another.

  • Slartibartfast the third. (unregistered) in reply to Gumpy Gus

    Wasting time or expanding the heap is not a reliable way to fix a race condition. That's a WTF in itself.

  • isthisunique (unregistered) in reply to Gumpy Gus

    I think out of those only #1 borders not being a WTF.

  • Llarry (unregistered) in reply to isthisunique

    But if you're using it as a placeholder for a potential future use, you comment it that way. If a later programmer finds this sort of structure with no explanation, it's not unreasonable to guess that it's unnecessary and potentially harmful.

    Same goes for Grumpy Gus' litany of "clever" ways to use this to manipulate timing. Comment it, or it's going away.

  • Anon (unregistered)

    The "Easy Reader Version" does nothing. It should be removed.

  • (nodebb) in reply to 04012018

    Yeah, well, they probably hate you too.

  • Jeremy Hannon (google) in reply to Gumpy Gus

    The "Format" method is standard in .Net, and this appears to be C#.

    The real problem with the overhead this creates is that the way the Format function is implemented for strings is it creates a StringReader object and uses it's format method to parse the string and put in substitutions. That is a whole lot of work, object creation, memory allocations, object destruction, to do absolutely nothing as .Net also caches string references, so it likely just puts the internal pointer back exactly the way it was in the end.

  • Zenith (unregistered) in reply to Llarry

    So? I should never do something remotely clever just in case some dopey duhveloper stuffing orders of magnitude more wasteful stupidity into the codebase might wander by and be confused or frightened by a few artifacts here and there?

    Clearly, this call used to, or was intended to, format a string and it probably stuck around because A) it doesn't matter or B) everybody was too frightened of "risk" to just delete it, see what broke in a compile attempt, and undo the checkout.

  • Sole Purpose of Visit (unregistered) in reply to Kashim

    The WTF is not very well explained, although I'm sure Remy knows what it is. Either the calling site can accept a null "string," or it cannot. In the former case, you're doing something completely pointless. (Possibly elided by the Jitter. In the latter case, you're lying to the calling site, which has of course accepted that null string from somewhere else as far as you know. This, I suppose, is great, because you don't throw an exception at some Heisenberg point down the line. But unfortunately it masks the fact that you were given a null string in the first place -- which is a decision best left to the calling site.

  • 04012018 (unregistered)

    blah blah spam, something something spam, spammy spammy spam spam

  • 04012018 (unregistered)

    Wow, it seems you can get anything through using this "04012018" username. What a great spam filter this site has!

  • HK-47 (unregistered)

    Spam is here just to make the site look more active. I guess the owners are the ones writing it.

  • Derf Skren (unregistered)

    It does make a new copy of the string, which could be the whole point.

  • (nodebb) in reply to someone

    I actually thought this was the first good ERV in a while. It demonstrates the point exactly.

    Remy: please don't feel the need to make an ERV just because it's become a tradition. If there's nothing much that needs to be said, you don't need to say anything. I'd rather see no hidden comments (including the ERV) than see ones that just seem to be there for the sake of having something there.

  • JimTonic (unregistered)

    My guess is that it had another purpose earlier, for example to add some information to the string, but was removed. I would check the source's history before removing it (svn blame or whatever people are using nowadays).

  • Smash (unregistered) in reply to isthisunique

    <quote>... The else is redundant and the code lacks context... </quote>

    No it doesn't. It's the only parameter in the function, for crying out loud.

  • aaronburro (unregistered)

    This is what you would call "anti-interning"

Leave a comment on “Without Context”

Log In or post as a guest

Replying to comment #:

« Return to Article