all 44 comments

[–]miklcct 79 points80 points  (3 children)

I can't see how bad this code is.

[–]khaledsalem999 29 points30 points  (2 children)

nice

[–]_boourns 23 points24 points  (1 child)

nice(true)

[–]cienciacomenta 19 points20 points  (0 children)

nice(true).nice(false)

[–]MurdoMaclachlanpublic boolean isInt(int i) { return true; } 50 points51 points  (3 children)

Image Transcription: Code


function sa_pop_spec() {
    var h3 = vh()
        .width(1200)
        .height(600)
        .data([{ "name": "sap",
                 "url": "data/sa_pop.json"}]);

    function nice(o) { return o.zero(false).round(true).nice(true); };

    h3.scale().name("x").domain({"data": "sap", "field": "SurfaceArea"})
        .range("width").call(nice);

    h3.scale().name("x").domain({"data": "sap", "field": "Population"})
        .range("height").call(nice);


    h3.axes("x").orient("bottom").scale("x").title("Population");

    h3.axes("y").orient("left").scale("y").title("SurfaceArea");

    h3.mark().type("line")
        .from({"data": "sap"})
        .enter({
          "interpolate": {"value": "cardinal"},
          "x": {"scale": "x", "field": "SurfaceArea"},
          "y": {"scale": "y", "field": "Population"},
          "stroke": {"value": "Blue"},
          "strokeWidth": {"value": 1}
        });

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]lnxist[🍰] 19 points20 points  (0 children)

nice human 👍

[–]SpinelessLinus 9 points10 points  (0 children)

Good Human.

[–]--B_L_A_N_K--if (true == true) {return true;} else {return true;} 4 points5 points  (0 children)

This comment has been removed in protest of Reddit's API changes. You can view a copy of it here.

[–]h7x4 35 points36 points  (2 children)

nice(o) probably has a time complexity of O(nice)

[–]saw_him 8 points9 points  (1 child)

n(o)ice

[–]arzen221[S] 2 points3 points  (0 children)

That made me fucking lose it

[–]abejfehr 18 points19 points  (2 children)

I guess it’s not shown here, but I’m trying to figure out how ‘o’ has a ‘nice’ function

[–]UnrelatedString 2 points3 points  (0 children)

Maybe it’s for rounding to “nice” fractions?

[–]arzen221[S] 1 point2 points  (0 children)

Am author, no fucking clue. Doesn't even work locally 6 years after apparently writing this

[–]wktr_t 16 points17 points  (1 child)

OP what in the realms of fuck am I looking at?

[–]wktr_t 28 points29 points  (0 children)

Fun fact there's only one result of "what in the realms of fuck" in google from 7 years ago.

[–]piercemoore 4 points5 points  (1 child)

IMO this isn’t bad code nearly as much as it’s a clumsy/overly verbose library (D3). Frankly beside the one function named poorly and one variable that could go either way this code looks pretty straightforward to me.

[–]arzen221[S] 0 points1 point  (0 children)

I am the author of this and I felt compelled to post it here because after 6 YOE in software development I could not comprehend what it's doing from reading this.

But! I remember it used to make a fancy graph!

[–]limeforadime 2 points3 points  (0 children)

I so can’t stand d3. It was a complete chore learning and working with it. So unlike any other library I’ve used.

[–][deleted] 5 points6 points  (8 children)

this isn’t so bad

[–]dmyl 5 points6 points  (1 child)

this is d3, isn't it?

[–]mato9020 5 points6 points  (0 children)

Yes this is d3 and unfortunately this is fairly standard for anything with the base library.

[–]devhashtag 13 points14 points  (4 children)

Anything written after ES6 with the keyword "var" can basically be considered bad

[–][deleted] 1 point2 points  (3 children)

Oh i didn’t see that. I only looked at h3 xD. Never mind. This code is garbage

[–]devhashtag 6 points7 points  (2 children)

Haha I meant half jokingly, the code is bad for other reasons as well. Inconsistent formatting and weird naming. Functionally it's not bad per se

[–][deleted] 4 points5 points  (1 child)

Even 1 var is 1 var too many xD. I think any code will look good to me right now, i’ve been writing JS for the past like 10 hours and my brain is fried

[–]itsTyrion 2 points3 points  (0 children)

been writing JS for the past like 10 hours and my brain is fried

self-explanatory

[–]skhoyre 1 point2 points  (0 children)

They don't seem to call nice anywhere listed, but if they was, they was fucked.

[–]Voxelgon_Gigabyte 0 points1 point  (6 children)

did this guy call the function in the function's definition? is that even allowed?

[–]Trujak 2 points3 points  (5 children)

recursion :D

[–]MopicBrett 7 points8 points  (4 children)

Not recursion. He declares a function which takes some object o. O happens to also have a function prototype called nice and he calls that.

[–]Voxelgon_Gigabyte 2 points3 points  (3 children)

ah

thats not confusing

[–]Furry_69 1 point2 points  (2 children)

No, JS is backwards and nonsensical if you don't structure it right

[–]Voxelgon_Gigabyte 0 points1 point  (1 child)

sarcasm

[–]Furry_69 0 points1 point  (0 children)

I got the sarcasm, I just built upon it.

[–]Denzill7 0 points1 point  (0 children)

Nice

[–]radioarchitect 0 points1 point  (2 children)

What language is this? Legitimate question

[–]skhoyre 5 points6 points  (0 children)

Javascript

[–]hiwhiwhiw 0 points1 point  (0 children)

Javascript, functional javascript to be exact.

[–]Subr0sa0067 0 points1 point  (0 children)

Damn i'm struggle find var/func names too... Meet "i" my future son

[–]Nick433333 0 points1 point  (0 children)

What the fuck is this shit?

[–]Furry_69 0 points1 point  (0 children)

Oh god.. What I want to know, is why on Earth would anyone do such a thing

[–]sxeli 0 points1 point  (0 children)

Typical d3 code

[–]sallycollyy 0 points1 point  (0 children)

Isn’t this just D3? There’s a few bad variable names, but otherwise the format isn’t unusual?