Open Side Menu Go to the Top

02-15-2016 , 10:57 AM
Quote:
Originally Posted by adios
I guess there are complexity analysis tools for JavaScript code and I am surmising from Russ's and GM's posts that they would rate code with more than 2 indent levels as highly/too complex.
Quote:
Originally Posted by gaming_mouse
yeah, those tools exist, i've used them for ruby, but there's no need for fancy code metrics or tools to see why nested indentation is bad. i mean, you can literally see it, right there in your editor, like digital vomit.
Quote:
Originally Posted by suzzer99
Ok indentation Nazis - tell me how this is bad code.

Code:
module.exports = function (grunt) {

    // All upfront config goes in a massive nested object.
    grunt.initConfig({
        html2js: {
            options: {
                // strip aways extra folder path info from templateKey 
                rename: function(moduleName) {
                    if (moduleName === 'xxx')
                        console.log("moduleName: " + moduleName);
                    ...
This is just a grunt task. Yeah I can define the rename function somewhere else. But whatever it's small and is easy to just throw in the config. This is pretty standard.

My point is there are massive levels of indentation all over the place. With AMD it seems like sometimes you're 4 indents in before you can even define a function you want to return with module.exports. So using 4 spaces instead of 2 just makes zero sense to me.
I was wondering if Suzzer would have something to state about this. What would a complexity checker for JavaScript indicate about this code?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
02-15-2016 , 11:46 AM
I like it. 4 "spaces" is easier to read than 2 for me. This is how I prefer to write JS. y u no es6?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 12:34 PM
Embarrassing Monday confession:

2 years into programming I finally mastered breakpoints and the debugger. Previously I'd just been tracing code on paper or my whiteboard, lol. This is way easier.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 12:46 PM
what language?

I found C++ was terrible for breakpoints and debugging. Sitting there stepping into a simple call that went behind the scenes for like 25-40 steps was a huge PITA
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 12:48 PM
also, y combinator considering 300 participants for a beta universal basic income program?

where do i sign up?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 12:51 PM
Quote:
Originally Posted by suzzer99
Ok indentation Nazis - tell me how this is bad code.

Code:
module.exports = function (grunt) {

    // All upfront config goes in a massive nested object.
    grunt.initConfig({
        html2js: {
            options: {
                // strip aways extra folder path info from templateKey 
                rename: function(moduleName) {
                    if (moduleName === 'xxx')
                        console.log("moduleName: " + moduleName);
                    ...
Nesting object properties isn't so bad, it's when you're nesting control structures several levels deep that it should set off alarms.

Quote:
Originally Posted by adios
I was wondering if Suzzer would have something to state about this. What would a complexity checker for JavaScript indicate about this code?
ESLint, for example, has no problems with Suzzer's snippet when max-depth is set to 2.

On the other hand, this would trigger an error:

Code:
/*eslint max-depth: [2, 2]*/

function foo() {
    for (;;) {
        if (true) {
            if (true) { /*error Blocks are nested too deeply (3).*/

            }
        }
    }
}
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 12:54 PM
Right. But half the stuff I look at is object properties or something else that's not pure code.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 12:55 PM
Quote:
Originally Posted by suzzer99
Ok indentation Nazis - tell me how this is bad code.

Code:
module.exports = function (grunt) {

    // All upfront config goes in a massive nested object.
    grunt.initConfig({
        html2js: {
            options: {
                // strip aways extra folder path info from templateKey 
                rename: function(moduleName) {
                    if (moduleName === 'xxx')
                        console.log("moduleName: " + moduleName);
                    ...
This is just a grunt task. Yeah I can define the rename function somewhere else. But whatever it's small and is easy to just throw in the config. This is pretty standard.

My point is there are massive levels of indentation all over the place. With AMD it seems like sometimes you're 4 indents in before you can even define a function you want to return with module.exports. So using 4 spaces instead of 2 just makes zero sense to me.
It's hard to say with such a small snippet, but based on what I see, yeah, I'm probably defining "rename" somewhere else so with ES6 it just says "options: { rename }".

I think pure config files are a different beast though, because those are essentially just a big object, and a nested data structure is far less problematic than nested control flow logic. Though even with data structures, excessive nesting does make them harder to look at, and I might consider defining it in pieces, so that the outer object makes reference to the named inner objects, rather than inlining them directly. That will cut down the visual indentation, though of course doesn't change the structure itself. I wouldn't necessarily do this in a config file, though, it would depend how long it was and how offensive it was to look it.

EDIT: ha, crossposted with ben who said almost the same thing
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 12:59 PM
Quote:
Originally Posted by Noodle Wazlib
what language?

I found C++ was terrible for breakpoints and debugging. Sitting there stepping into a simple call that went behind the scenes for like 25-40 steps was a huge PITA
C++. and yea that's why I was too lazy to bother with it. going through code with pen and paper is a good exercise though IMO
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 01:00 PM
Quote:
Originally Posted by suzzer99
Right. But half the stuff I look at is object properties or something else that's not pure code.
does it tax your brain at all to discern the overall structure?
do you find yourself folding a lot in your text editor to do so?

these are the kinds of cues i'd use to decide if it needed to be broken down.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 01:06 PM
Not really on either. I just want to maximize the amount of code I can see on the screen at one time. And right-left scrolling code is a huge PITA imo.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 01:12 PM
Quote:
Originally Posted by suzzer99
Not really on either. I just want to maximize the amount of code I can see on the screen at one time. And right-left scrolling code is a huge PITA imo.
1) obvs use 2 space indentation/tabstop
2) turn on line wrap in your editor

left-right scrolling is the devil and unacceptable in any circumstance
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 01:23 PM
if you stick to a ~80 char column width, then indentation problems take care of themselves. you're forced to refactor
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 01:37 PM
Quote:
Originally Posted by gaming_mouse
1) obvs use 2 space indentation/tabstop
2) turn on line wrap in your editor

left-right scrolling is the devil and unacceptable in any circumstance
#1 Yes this is my whole point. I use 2 spaces. But if I take a job with this other group I will be forced to switch to four space tab stops.

I also don't get the people who like to develop in one tiny little code window in their IDE that they don't even take pains to maximize. I feel like I'm developing through a periscope.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 01:46 PM
Quote:
Originally Posted by suzzer99
#1 Yes this is my whole point. I use 2 spaces. But if I take a job with this other group I will be forced to switch to four space tab stops.

I also don't get the people who like to develop in one tiny little code window in their IDE that they don't even take pains to maximize. I feel like I'm developing through a periscope.
agree. the 4 space thing is annoying but not a reason to avoid the job per se. however, a preference for 4 spaces doesn't speak well of their taste, and bad taste certainly correlates, albeit imperfectly, with bad programming skill. but it's just a small red flag, so far -- you need to dig more. can you schedule a lunch with them... if they order their steaks well done, eg, you can politely decline the whole opportunity.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 01:53 PM
Quote:
Originally Posted by gaming_mouse
agree. the 4 space thing is annoying but not a reason to avoid the job per se. however, a preference for 4 spaces doesn't speak well of their taste, and bad taste certainly correlates, albeit imperfectly, with bad programming skill. but it's just a small red flag, so far -- you need to dig more. can you schedule a lunch with them...if they order their steaks well done, eg, you can politely decline the whole opportunity.
+1. Huge (un-)red flag.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 02:10 PM
Most of them are Indian. Doubt they'll be ordering steaks.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 02:11 PM
Just found out yesterday how to enable sublime's 80-char vertical rule. So happy.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 02:21 PM
Quote:
Originally Posted by suzzer99
Most of them are Indian. Doubt they'll be ordering steaks.
lol
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 03:00 PM
Quote:
Originally Posted by jmakin
Embarrassing Monday confession:

2 years into programming I finally mastered breakpoints and the debugger. Previously I'd just been tracing code on paper or my whiteboard, lol. This is way easier.
Quote:
Originally Posted by Noodle Wazlib
what language?

I found C++ was terrible for breakpoints and debugging. Sitting there stepping into a simple call that went behind the scenes for like 25-40 steps was a huge PITA
Quote:
Originally Posted by jmakin
C++. and yea that's why I was too lazy to bother with it. going through code with pen and paper is a good exercise though IMO
Step Over instead of Step Into to avoid going in the library code.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 03:07 PM
Maybe it is my Python background and maybe due to my ****ty eyesight, but I don't like 2-space indentations.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 03:29 PM
2-space indentation seems like a gateway to write super nested code

sure 4 takes more room but it's objectively easier to discern than 2, and if the code isn't over-nested, it's not a big deal
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 04:51 PM
Quote:
Originally Posted by greg nice
if you stick to a ~80 char column width, then indentation problems take care of themselves. you're forced to refactor
I, too, like to pretend monitor resolutions haven't increased since the 1980s
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 05:15 PM
do you ever print out your code? (srs question)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-15-2016 , 05:31 PM
No, is that a thing people do??

I guess a limit would be useful in that case but I don't think I've ever seen anyone do that.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m