Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
1) WTF! 2) Does *no-one* in the whole damn world teach what a fucking 'switch' statement is!!
-
Bikonja23837yIt 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.
-
@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. -
Eithei877yNo 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
-
Eithei877yI have just started looking through the project :D give it time - if there is one, there will be a second!
-
@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. -
@HackSonX Yes. I'll give you that. But if you haven't a notion how to map your data, at least know the fundamentals!
-
Eithei877yHey! 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
Related Rants
Why not have a custom (500 line) JSON mapper... you know... fuck those auto mapping libraries out there...
undefined
clean code
json
best practices
java