WTF Bites


  • đźš˝ Regular

    @topspin said in WTF Bites:

    extension methods

    Why doesn't C# have a Substring method on string objects accepting an index larger than the string length, or converting null strings to empty strings?

    Oh wait. Now it does.


  • kills Dumbledore

    @bobjanova said in WTF Bites:

    but it really breaks your link of where to find code unless you're using an IDE with click through.

    Why would you not?


  • Considered Harmful

    @Zecc said in WTF Bites:

    @topspin said in WTF Bites:

    extension methods

    Why doesn't C# have a Substring method on string objects accepting an index larger than the string length, or converting null strings to empty strings?

    Oh wait. Now it does.

    ?? "" is just too hard.

    JS lets you tack on your own methods (or even replace builtin ones) on object prototypes... and most of the time, it is a terrible idea (at least in terms of modifying existing objects, not defining new ones).


  • Considered Harmful

    @topspin said in WTF Bites:

    @GÄ…ska said in WTF Bites:

    UFCS (the dot-syntax-for-free-functions thing)

    Since there's probably no way we're ever getting extension methods1, I'd gladly take this instead. If they ever managed to ship it before I retire.

    1 What's the common opinion about them in C#? Look neat to me, but since I've never used them I don't know if the feature is actually good.

    I put them in the category of "more often abused than used." Used properly, they enable LINQ (a great thing). Used improperly, well... Sturgeon's law is in full effect.


  • Discourse touched me in a no-no place

    @Bulb said in WTF Bites:

    the C API just can't do that

    The C API doesn't try. It does the actual I/O bits.

    Of course, the really ghastly bit of the C++ stream API shows up once you want to do localization. Want to put values in your message in a different order for grammatical reasons? You just need to change the source around a bit…


  • đźš˝ Regular

    @error said in WTF Bites:

    ?? "" is just too hard.

    More like maybeNull?.MySubstringWhichDoesntThrowNullRefExceptions() ?? "".
    But yes.


  • Java Dev

    @dkf said in WTF Bites:

    @Bulb said in WTF Bites:

    the C API just can't do that

    The C API doesn't try. It does the actual I/O bits.

    Of course, the really ghastly bit of the C++ stream API shows up once you want to do localization. Want to put values in your message in a different order for grammatical reasons? You just need to change the source around a bit…

    That's not your only worry. In many languages, the inflections in the string which needs translating from English actually depend on the (grammatical) gender and count of the bits you're filling in.


  • Banned

    @Bulb said in WTF Bites:

    @Gąska … and it's actually the limitations of the syntax that forced the idiotic stateful formatting flags.

    It was caused by the insistence on using that syntax, instead of regular functions and methods like every other fucking language does.

    The C++ standard library originally doubled as a showcase of language features. >> was used for streams mostly to show off the C++'s ability to repurpose old operators for something completely different with entirely new semantics. It wasn't just by design - it was the main goal. Same with std::vector<bool>. The only reason it exists is to show off just how different a specialization class can be from its base template, and how powerful the iterator abstraction is. The implementation itself makes no fucking sense, especially when you consider that STL was officially released in 2003, when the 7 wasted bits per item wasn't a problem at all but the performance penalty of bit fiddling on every read and write was very real.



  • @Bulb said in WTF Bites:

    The stream API is an eldrich abomination, but it's the only extensible thing the C++ standard library has. I prefer to be able to define formatting for my types, if nothing then for sake of easier logging, and the C API just can't do that.

    You can define custom formatters for it as well. C++20 though (unless you go with the fmtlib implementation that the standard one is based of).



  • @cvi said in WTF Bites:

    unless you go with the fmtlib

    I changed all my existing stream code to that not too long ago.


  • BINNED

    @Bulb said in WTF Bites:

    Typeclasses are superior, but they require thick pointers, which would be difficult to retrofit in C++.

    Don’t Rust traits work like that? (I think so but don’t know)

    Also, there’s a library out there for this that let’s you build your own object model / method dispatch / whatever you like in a super generic way. So you could build the normal v-table approach for some parts, fat pointer-like approach for others, or whatever else you can think of.
    Don’t actually remember the name, but it was something very boost-like in the approach, with all the positive and negative aspects of that. Super generic, let’s you solve all the problems you never had “elegantly”, looked stupidly confusing and I bet it makes Hello World take 3 hours to compile. So I noped out before looking much further.


  • Banned

    @topspin said in WTF Bites:

    @Bulb said in WTF Bites:

    Typeclasses are superior, but they require thick pointers, which would be difficult to retrofit in C++.

    Don’t Rust traits work like that? (I think so but don’t know)

    Traits are mostly used for static dispatch, so thin pointer is used most of the time, but when you do dynamic dispatch then yes, fat pointers are used. Also, slices (think: array views) use fat pointers to encode size.



  • @dcon said in WTF Bites:

    I changed all my existing stream code to that not too long ago.

    Same. Although I was using a different type safe printf() replacement before fmtlib, and just printf() before that. Screw iostreams.


  • Notification Spam Recipient

    @cvi said in WTF Bites:

    Screw iostreams.

    Unf... :giggity:





  • @HardwareGeek Hey, if somebody can somehow find joy in the C++ iostreams ... who are we to criticize that? Certainly rare enough.


  • BINNED

    @cvi said in WTF Bites:

    @HardwareGeek Hey, if somebody can somehow find joy in the C++ iostreams ... who are we to criticize that? Certainly rare enough.

    Masochism thread is :arrows:



  • @dkf said in WTF Bites:

    @Bulb said in WTF Bites:

    the C API just can't do that

    The C API doesn't try. It does the actual I/O bits.

    Of course, the really ghastly bit of the C++ stream API shows up once you want to do localization. Want to put values in your message in a different order for grammatical reasons? You just need to change the source around a bit…

    I've used boost.format for that in one project (was still stuck in C++98 by 2016 as last compiler supporting one still needed target platform was VS2008), and in another project before that I cooked something of my own (but that was back around 2007, and basically plain Win32).

    The boost.format uses a format string, but abuses yet another operator, %, for it's builder pattern. I used chained methods for the version I did myself (possibly inspired by what Qt, which does something similar).

    @cvi said in WTF Bites:

    Same. Although I was using a different type safe printf() replacement before fmtlib, and just printf() before that. Screw iostreams.

    As ugly as the streams are, the boost.format being built on top of them had the benefit of having standard way of defining the formats. They are slow as molasses too though. I wonder whether the fmtlib and format are faster, but given the output iterator is probably a stream one I wouldn't be too hopeful.



  • @Bulb fmtlib is not based on the iostreams, so it has that going for it. There are some benchmarks by the fmtlib authors: https://github.com/fmtlib/format-benchmark. Looks fairly competitive, i.e., it even outperforms sprintf() in their tests.

    Haven't benchmarked myself; it's definitively not a bottleneck in my stuff, so haven't had any reason to do so. I'd be more worried about the compile times (e.g., due to compile time format string checking). So far, it's OK in my use cases.



  • @PleegWat said in WTF Bites:

    @dkf said in WTF Bites:

    @Bulb said in WTF Bites:

    the C API just can't do that

    The C API doesn't try. It does the actual I/O bits.

    Of course, the really ghastly bit of the C++ stream API shows up once you want to do localization. Want to put values in your message in a different order for grammatical reasons? You just need to change the source around a bit…

    That's not your only worry. In many languages, the inflections in the string which needs translating from English actually depend on the (grammatical) gender and count of the bits you're filling in.

    Gettext and similar libraries only handle number (Arabic has whopping six variants depending on number). Usually the thing you fill in are either numbers or identifiers, in which case the gender depends on the generic noun and is the same for any identifier. Sometimes you have be a bit creative in the translations though.

    The biggest “fun” is people's names. In addition to the notorious problems—that still most coders and designers fail to take into account—like order (Asians usually put family name first) and number of names (Spaniards often use two surnames, and often two given names too and you never know which one to prefer) there are things like vocative, where you address person in different case than you refer to them.

    Then there is the format used in Java and ICU, which allows switching on these other cases too, but I am not sure most translators would be able to use it properly, especially the early versions with the '-escaping.

    And then there is the crazy-flexible fluent that I really doubt any translator—thinking about professional translator a random company hires to translate all texts in their application to some language, not a geek translating some open-source thingamajig to their native language for fun—will be able to handle. Especially given the strings will get extracted and given to the translator by some random code monkey that has absolutely no idea what context the translator might need to do a proper job. Especially from English known for its verbing, nounisation and propensity to reuse random words for new concepts.



  • @topspin said in WTF Bites:

    @Bulb said in WTF Bites:

    Typeclasses are superior, but they require thick pointers, which would be difficult to retrofit in C++.

    Don’t Rust traits work like that? (I think so but don’t know)

    When used for dynamic dispatch yes. And so do Go interfaces, and I believe Swift uses the same technique and possibly Dart as well. Note that neither Rust nor Go have inheritance, so references to concrete types are thin and methods on them can always be dispatched statically. Only trait/interface references need dynamic dispatch.

    The “typeclass” name comes from Haskell, but that is defined on high level, so I don't know what it's compilers actually use. It only requires dynamic dispatch for the foreach feature, anything else can be resolved statically, but I think the compilers actually compile to dynamic dispatch to avoid blowing up the code too much as there is indirection to support the laziness anyway.



  • @cvi said in WTF Bites:

    @Bulb fmtlib is not based on the iostreams, so it has that going for it. There are some benchmarks by the fmtlib authors: https://github.com/fmtlib/format-benchmark. Looks fairly competitive, i.e., it even outperforms sprintf() in their tests.

    Haven't benchmarked myself; it's definitively not a bottleneck in my stuff, so haven't had any reason to do so. I'd be more worried about the compile times (e.g., due to compile time format string checking). So far, it's OK in my use cases.

    Hm, the fmtlib seems to even have its own streams—but only the formatting itself was co-opted into the standard library so the streams still haunt there.



  • After some scratching my head why the hell the tests I am trying to diagnose don't log what I needed, I ran across this representative enum:

    enum class Enum : int {
        LogLevel_FATAL = 0,
        LogLevel_ERROR = 1,
        LogLevel_WARNING = 2,
        LogLevel_DEBUG = 3,
        LogLevel_INFO = 4,
        LogLevel_TRACE = 5
    };
    

    No, the log levels don't have this order. The severity decreases in the usual order of FATAL, ERROR, WARNING, INFO, DEBUG, TRACE. And when you want to change it, you specify it as number via a homebrewed IPC mechanism.

    … the enum is actually auto-generated from XML with xmlplus, which is the only free xml binding generator for C++ I've ever seen, and pretty crappy. The numbers come simply from the order of the elements, which just makes it stupider to use them anywhere.

    … of course the log4cplus that it uses under the hood has it's own :sideways_owl: definitions:

        const LogLevel OFF_LOG_LEVEL     = 60000;
        const LogLevel FATAL_LOG_LEVEL   = 50000;
        const LogLevel ERROR_LOG_LEVEL   = 40000;
        const LogLevel WARN_LOG_LEVEL    = 30000;
        const LogLevel INFO_LOG_LEVEL    = 20000;
        const LogLevel DEBUG_LOG_LEVEL   = 10000;
        const LogLevel TRACE_LOG_LEVEL   = 0;
        const LogLevel ALL_LOG_LEVEL     = TRACE_LOG_LEVEL;
    

  • Discourse touched me in a no-no place

    @Bulb said in WTF Bites:

    enum class Enum

    An enum called Enum? Who'd have thought of that?!



  • @dkf said in WTF Bites:

    @Bulb said in WTF Bites:

    enum class Enum

    An enum called Enum? Who'd have thought of that?!

    The XML binding generator. The XML schema has a <simpleType> with <restriction base="string"><enumeration value="FATAL">… and xmlplus generates a class for the type derived from XMLSchema::Types::bt_string with member types Enum for the values, and Parser doing the conversion.

    The XML binding generator is the only free one there seems to be, but it's crap. It does not deserialize into plain old objects, it deserializes into a generic DOM object that it wraps in a type-safe facade it generates. The predictable result is that reading a 1 MB XML file can easily eat almost 100 MB of memory and then the 250 MiB memory this older device has starts to be quite tight.


  • Considered Harmful

    @Bulb said in WTF Bites:

    … of course the log4cplus that it uses under the hood has it's own :sideways_owl: definitions:

    You can never know if somebody might need want (INT_MAX - 7) additional log levels:

    const LogLevel REALLY_TOTALLY_OFF_LOG_LEVEL = INT_MAX,
    const LogLevel PINKY_SWEAR_OFF_LOG_LEVEL = REALLY_TOTALLY_OFF_LOG_LEVEL - 1,
    const LogLevel DEBUG_AND_SOME_MILD_CURSING_LOG_LEVEL = 15000,
    const LogLevel ALMOST_BUT_NOT_QUITE_ENTIRELY_UNLIKE_OFF_LOG_LEVEL = 42,
    


  • @Applied-Mediocrity I don't think you can have more than 60000, because 60000 is OFF and so values above that may not be allowed.


  • Discourse touched me in a no-no place

    @Bulb said in WTF Bites:

    The XML binding generator is the only free one there seems to be, but it's crap.

    I'm more used to the Java ones, which are… well, not too great either TBH, but at least are freely available and not catastrophically awful.


  • Discourse touched me in a no-no place

    @Applied-Mediocrity said in WTF Bites:

    You can never know if somebody might need want (INT_MAX - 7) additional log levels:

    const LogLevel REALLY_TOTALLY_OFF_LOG_LEVEL = INT_MAX,
    const LogLevel PINKY_SWEAR_OFF_LOG_LEVEL = REALLY_TOTALLY_OFF_LOG_LEVEL - 1,
    const LogLevel DEBUG_AND_SOME_MILD_CURSING_LOG_LEVEL = 15000,
    const LogLevel ALMOST_BUT_NOT_QUITE_ENTIRELY_UNLIKE_OFF_LOG_LEVEL = 42,
    

    FILE_NOT_FOUND_LOG_LEVEL when?



  • @dkf said in WTF Bites:

    @Bulb said in WTF Bites:

    The XML binding generator is the only free one there seems to be, but it's crap.

    I'm more used to the Java ones, which are… well, not too great either TBH, but at least are freely available and not catastrophically awful.

    The Java one does the right thing of generating plain old objects and deserializing into them, so it does not have the insane overhead of that C++ one. So does the .нет one. There are some non-free ones for C++ that do as well. There is a talk of replacing the xmlplus with one to cut down the overhead, but it's a big change (the application lives and breaths xml), so nobody got around to actually doing it though the replacement was chosen almost two years ago



  • @dkf JAXB is a bit clunky but yeah it does the job pretty well, at least with a bit of configuration around it. We use it quite widely (our application does stuff with XML APIs) and don't have any major issues.



  • Just waiting until some mugger thinks a $24M diamond is worth more than the front of this dude's head.

    ("Embedded" seems to be a little misleading. Apparently, it's just a piercing, so it's not like the mugger would have to pry it out of his skull, or something. Still, it seems like the sort of thing it would be a bad idea to flash around the 'hood.)



  • @bobjanova said in WTF Bites:

    @dkf JAXB is a bit clunky but yeah it does the job pretty well, at least with a bit of configuration around it. We use it quite widely (our application does stuff with XML APIs) and don't have any major issues.

    JAXB seems to be the best binding there is. The clunkiness is mostly because of XML itself, and XSD, are overcomplicated mess.


  • BINNED

    @HardwareGeek said in WTF Bites:

    Rapper Lil Uzi Vert got a $24 million pink diamond embedded in the middle of his forehead

    The WTFs per sentence caused an overflow error.
    Who are these people? Or maybe in the words of 5 year olds who still ask deep questions: why are these people?



  • That's a waste of a perfectly good diamond.



  • @HardwareGeek said in WTF Bites:

    Just waiting until some mugger thinks a $24M diamond is worth more than the front of this dude's head.

    ("Embedded" seems to be a little misleading. Apparently, it's just a piercing, so it's not like the mugger would have to pry it out of his skull, or something. Still, it seems like the sort of thing it would be a bad idea to flash around the 'hood.)

    If Diablo taught me anything, it's "Don't stick the gem in your forehead." Looks like we'll all be in trouble pretty soon. Get ready to head to the East.



  • @Zerosquare said in WTF Bites:

    That's a waste of a perfectly good diamond.

    Don't want to disagree, but what else are you going to do with it?


  • BINNED

    @cvi said in WTF Bites:

    @Zerosquare said in WTF Bites:

    That's a waste of a perfectly good diamond.

    Don't want to disagree, but what else are you going to do with it?

    Something something super-villains, something something lasers?


  • Discourse touched me in a no-no place

    @Bulb said in WTF Bites:

    @bobjanova said in WTF Bites:

    @dkf JAXB is a bit clunky but yeah it does the job pretty well, at least with a bit of configuration around it. We use it quite widely (our application does stuff with XML APIs) and don't have any major issues.

    JAXB seems to be the best binding there is. The clunkiness is mostly because of XML itself, and XSD, are overcomplicated mess.

    It's challenging to get a truly good binding written, but I've done it in the past (both code-first and schema-first). Heck, I've still got the repositories with how I did it. I've also made binding classes that would go to and from both XML and JSON (the service would use content type negotiation to take whatever was given and deliver whatever was wanted). That works really quite well… provided you don't use more than one XML namespace. Multiple namespaces and JSON bindings mix awfully.

    I prefer other languages' approaches that instead make XML and JSON into (effectively) first-class objects so you just manipulate them directly. And ignore the official DOM API.


  • BINNED

    @topspin
    Hmm no sharks?



  • @Luhmann said in WTF Bites:

    Hmm no sharks?

    Embed the diamond in a shark's forehead?

    ...

    Eh. Whatever. You guys do you.


  • Notification Spam Recipient

    @cvi said in WTF Bites:

    @Zerosquare said in WTF Bites:

    That's a waste of a perfectly good diamond.

    Don't want to disagree, but what else are you going to do with it?

    Fuck with it, of course! Who doesn't love fuckin' diamonds?!




  • Java Dev

    @Tsaukpaetra said in WTF Bites:

    Fuck with it, of course! Who doesn't love fuckin' diamonds?!

    Diamonds was a fun game. I played it a lot on a friend's Mac way back in the day. Also, like all old causal games, it had a heavily compressed 10-second loop from a popular song as the background music. That, or a bad MIDI version seemed to be the go-to thing.





  •    


  • Notification Spam Recipient

    @Zerosquare Orgasmic.



  • I'm... huh... glad you enjoy it. But I suddenly feel dirty.


  • Notification Spam Recipient

    @Zerosquare said in WTF Bites:

    I'm... huh... glad you enjoy it. But I suddenly feel dirty.

    WTF Bite achieved!



  • Ran into the following bug, or one of its cousins:

    Yes, the save command (in any of the forms) doesn't actually save the file. No error, no warning, just no save.

    Look, VisualStudio, you're essentially still a glorified text editor, and despite all the extra bells and whistles, one of the core jobs is to allow me to (a) edit files and (b) fucking save those changes to disk. FFS.


  • Notification Spam Recipient

    @cvi said in WTF Bites:

    Ran into the following bug, or one of its cousins:

    Yeah, I remember getting into a similar state when Perforce was being dodgy.


Log in to reply