Comments on: Labelled blocks, useful? https://j11y.io/javascript/labelled-blocks-useful/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.4 By: Regent https://j11y.io/javascript/labelled-blocks-useful/#comment-1895 Wed, 31 Mar 2010 07:03:36 +0000 https://j11y.io/?p=1504#comment-1895 This is fun!
In some projects, there is quite a big operation on the same level of nesting in code. Then help conditional comments, but not so good.

I Experiment with blocks!

]]>
By: Jani Hartikainen https://j11y.io/javascript/labelled-blocks-useful/#comment-1894 Wed, 24 Mar 2010 16:11:13 +0000 https://j11y.io/?p=1504#comment-1894 Just wait until they implement goto. Then these will be very much useful! 😉

]]>
By: Graham https://j11y.io/javascript/labelled-blocks-useful/#comment-1893 Wed, 24 Mar 2010 11:35:51 +0000 https://j11y.io/?p=1504#comment-1893 Interesting idea, but I think this actually decreases code readability. Using labels and blocks in that manner gives them the impression of being name / properties of an object literal, at first glance anyways.

]]>
By: Shanpeng https://j11y.io/javascript/labelled-blocks-useful/#comment-1892 Wed, 24 Mar 2010 03:03:37 +0000 https://j11y.io/?p=1504#comment-1892 Good idea! In some cases it can help to classify the codes.

]]>
By: James https://j11y.io/javascript/labelled-blocks-useful/#comment-1891 Tue, 23 Mar 2010 20:07:11 +0000 https://j11y.io/?p=1504#comment-1891 @V1, good point, although I don’t think how-we-code should be affected by how-it-will-compress.

@Pete, I tend to prefer curly braces AND white-space as opposed to just white-space. Although I guess I’ve been conditioned quite a bit by all of these C-style langs.

@David, another good point! I can see it being useful as a general form of annotation although comments may be better in some instances.

@JGarrido, Labels are programatically useful only when you use the continue or break statement to exit a block or continue a loop (for/while/do):

outerLoop: while (true) {
    /* stuff */
    while (true) {
        /* more stuff */
        break outerLoop;
    }
}

AFAIK, there’s no other way to use labels.

]]>
By: JGarrido https://j11y.io/javascript/labelled-blocks-useful/#comment-1890 Tue, 23 Mar 2010 19:23:42 +0000 https://j11y.io/?p=1504#comment-1890 Definitely looks like a handy little tip to have at our disposal, thanks for sharing that! You can never have too many control structures, I always say.

I found a quick reference guide while Googling for more info:
http://snipplr.com/view/8255/javascript-labels/

Douglas Crockford doesn’t think too highly of the labels though, for some reason (he doesn’t get into much detail here):
http://javascript.crockford.com/code.html#compound%20statements

Here’s a question though: Can the label be referenced or used in any way programmically, or is it strictly a visual reference?

]]>
By: David Droddy https://j11y.io/javascript/labelled-blocks-useful/#comment-1889 Tue, 23 Mar 2010 14:18:12 +0000 https://j11y.io/?p=1504#comment-1889 for a less advanced programmer this could also, in some cases, lead to helpful hints of where to refactor. The labeled blocks could, ultimately be extracted into reusable functions.

]]>
By: Pete B https://j11y.io/javascript/labelled-blocks-useful/#comment-1888 Tue, 23 Mar 2010 13:49:04 +0000 https://j11y.io/?p=1504#comment-1888 Interesting, but I think I’ll stick with comments.

I actually prefer the look of languages that avoid the need for curly braces altogether, like Python.

]]>
By: V1 https://j11y.io/javascript/labelled-blocks-useful/#comment-1887 Tue, 23 Mar 2010 13:33:35 +0000 https://j11y.io/?p=1504#comment-1887 They do improve readability, but it would suck ball to minify it

]]>