• (nodebb)

    They failed to return Constants.FILE_NOT_FOUND!

  • (nodebb)

    How about the fact that a method named asUnicode does an HTML unescape?

  • (nodebb)

    like it or not, a null means something different than an empty string. Or, if we're going that far, we should be talking about using Optional or nullable types

    A null does, indeed, mean something different from an empty string. One is the absence of a value, while the other is an empty value. However ...

    Regardless of how you name them, "optional" types are just disguised nulls, and therefore aren't any better than nulls.

  • (nodebb) in reply to Dragnslcr

    Not to mention that the original author of the code would probably make a distinction between characters like 'W', 't', and 'f' on the one hand, and unicode characters on the other.

  • Guessed (unregistered) in reply to Steve_The_Cynic

    Optional types are not just nulls in fancy clothing. Optional<Optional<T>> is different from Optional<T>.

  • (author) in reply to Steve_The_Cynic

    I mean they're not disguised nulls, they're wrapped nulls. Calling them "disguised" like calling a burrito "disguised rice and beans". It's not disguised! It's put in a container to make it easier to consume!

  • Brian (unregistered) in reply to Steve_The_Cynic

    Optional/nullable types are a form of documentation. If you're using them consistently, then you're telling the reader -- and the compiler -- which values are allowed to be null and which are not. By doing that, you can shift your null checks to build-time rather than run-time, which simplifies your logic and significantly decreases the risk of some random null-reference exception.

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered)

    Plot twist: what if Constants.NOT_AVAILABLE is actually just an alias for null? Then the null check in the asUnicode() function might actually be needed.

  • (nodebb)

    I think the double null check is perfectly fine. Maybe asUnicode will get called by something else in the future that doesn't check for nulls. Better safe than sory.

  • OldCoder (unregistered) in reply to Dragnslcr

    Absolutely. Changing something to Unicode is not the same as unescaping HTML. The fact the two are intermixed here makes me wonder what else the author is getting confused. Nulls and empty strings, maybe?

  • (nodebb) in reply to OldCoder

    I'm not sure they are so dissimilar.

    I'm not at all an expert on this language, but when I searched for the descriptions of HtmlUtils.htmlEscape and HtmlUtils.htmlUnescape. I happened upon a library where one flavor of htmlEscape could be told to render an input string (presumably Unicode) into "US-ASCII" if that were the specified output encoding using &#xHex; as necessary. And where htmlUnescape would "Turn HTML character references into their plain text UNICODE equivalent."

    So, if someone wanted to represent a Unicode string (presumably wide characters) into US-ASCII, they could have found this library to be useful. And it might even be an intelligent choice if the library was already in the dependency list for other uses, perhaps to sanitize user input.

  • (nodebb) in reply to sibtrag

    Yes, the return of asUnicode in Unicode because htmlUnescape returns Unicode. However, it's still a poor indication of what the function actually does. It doesn't take ASCII string and convert them to Unicode. The only thing it does is take html escaped strings and convert those to Unicode unescaped strings. A really good name for this function would be "htmlUnescape", and maybe put it on a class named "HtmlUtils".

    Since javascript is unable to handle any other type of string encoding than Unicode (specifically UTF-16), the idea of calling out a function as returning Unicode is redundant.

  • Argle (unregistered)

    OK, I'm late to the comments today. How is it we've gone this far without a single comment about:

    if ( not x)
      do A
    else
      do B
    

    Sure, it's acceptable to write:

    if ( not x )
      do A
    

    But a negative test with an else is either bad thinking or lazy thinking; it doesn't matter what programming language.

Leave a comment on “Two Conversions”

Log In or post as a guest

Replying to comment #694654:

« Return to Article