68
Eithei
7y

Why not have a custom (500 line) JSON mapper... you know... fuck those auto mapping libraries out there...

Comments
  • 8
    1) WTF! 2) Does *no-one* in the whole damn world teach what a fucking 'switch' statement is!!
  • 1
    It might be for performance reasons. We used our own utility functions to do mapping, but on some places the code was called so often and at such crucial places that we had to do manual mapping.
  • 3
    @CrankyOldDev

    I don't know a lot about how java handles json, but whenever I hear "mapping a set of data to a differently formatted set of data" my brain starts to remove all if/switch/for/while constructs and replace them with higher order transformation functions. Preferably something which can easily run the transformation in parallel, depending on the size and complexity of the task.
  • 3
    No performance reasons; 7month old project, no build or dependency management tools used, no nothing. The guy has a "template" project he reuses for everything he does... :D
  • 2
    I have just started looking through the project :D give it time - if there is one, there will be a second!
  • 2
    @CrankyOldDev even that's a no.
  • 1
    At least he could switch not if... The branch prediction cries.
  • 0
    @bittersweet what kind of higher order transformation functions?
  • 1
    @theactionslacks At a very simple level you can use maps. In JS, you can replace a chain of if/else by defining an object: sound = {cow: 'moo', cat: 'meow'}, and asking what sound[theAnimal] makes. In many languages the both key and value can be take many forms, including functions to be evaluated later. You need to be careful about accessing undefined keys though, which would be handled the "else" to an if, or the "default" to a switch.

    A collection construct with methods like map, reduce, filter, sort, etc is very useful to abstract crap away in OOP languages -- it makes complex chains of mapping operations readable.

    In functional programming you have a powerful tool called lenses, where you can create very complex maps with enforced types, where "maybes" can be deferred or unwrapped, where multiple mappings can be composed to run in series/parallel, and where the whole set of "optics" (lenses, prisms, etc) will lazily evaluate only the necessary parts.
  • 1
    @Eithei please keep us posted on the next one you find 😉
  • 1
    @HackSonX Yes. I'll give you that. But if you haven't a notion how to map your data, at least know the fundamentals!
  • 0
    Hey! It could have been worse - only ifs without the elses! Screw performance even more...

    And what adds to this beautiful picture is that it maps it to a giant class which has just under 100 member variables :D

    I will see if I can "censor" some of the classes and show them here :) I don't want to give the name of the project away :D
Add Comment