3 ms·
As a primarily Python dev (read: PEP-8 fan) who writes CoffeeScript as much as possible and wraps CS at ~100 cols, at what point is the ternary operator used on
by leetrout 13y ago
As a primarily Python dev (read: PEP-8 fan) who writes CoffeeScript as much as possible and wraps CS at ~100 cols, at what point is the ternary operator used on Line 22[1] actually readable and useful as a shortcut?
Honest question, because I see lots of people use the ternary operator to shortcut writing out a complete if statement but when the lines get that long I never do. Even on my 27" screen I use a tiling WM and Sublime cuts off at 120 cols and that line is >200.
[1] https://github.com/ENFOS/FlowupLabels.js/blob/master/src/jquery.FlowupLabels.js#L22 https://github.com/ENFOS/FlowupLabels.js/blob/master/src/jqu...
- taspeotis 13y agoYeah ReSharper would be all over that if it was C#: $this.val().length ? $this.parent().addClass(settings.class_populated).removeClass(settings.class_focused) : $this.parent().removeClass(settings.class_populated + ' ' + settings.class_focused);
- ryanthejuggler 13y agoI think it's very readable; I read it in my head like a dialogue where you're trying to quickly confirm something with someone. Lunch? Ok, we'll go to Chipotle. No? Ok, we'll stay here and work. (the colon becomes the "no?") After years of JavaScript the little voices in my head have at least become useful.
- missing_cipher 13y agoSeems like he improved readability just now. :) https://github.com/ENFOS/FlowupLabels.js/commit/eac25eda25346df487c3c79f3b22ebe1a440b73c https://github.com/ENFOS/FlowupLabels.js/commit/eac25eda2534...
- TheSisb2 13y agoThat's a valid point. My train of thought was probably something like: "This is a pretty simple plugin, I can get away with this" mixed in with simply not knowing how long that line was going to be when I started writing it that way. I've just updated the code to be more legible. I completely agree with your observation.