Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?
Programming Microsoft

Visual Studio Gets Achievements, Badges, Leaderboards 353

bonch writes "Microsoft has introduced a gamification plugin for Visual Studio that lets users win achievements and badges as they compete on leaderboards by writing code. The full list of achievements includes gems like 'Go To Hell' for using goto, and 'Potty Mouth' for using five different curses in one file. This is another example of Gamification, one of the latest trends to hit social media."
This discussion has been archived. No new comments can be posted.

Visual Studio Gets Achievements, Badges, Leaderboards

Comments Filter:
  • by Robadob ( 1800074 ) on Thursday January 19, 2012 @10:33AM (#38747566)

    You can use labels in java to break out of nested loops?

  • by Anonymous Coward on Thursday January 19, 2012 @10:36AM (#38747594)

    What's your problem? Java supports loop labels [wikipedia.org].

  • by Anonymous Coward on Thursday January 19, 2012 @10:52AM (#38747798)

    Was why GOTO is a bad idea every explained to you?

    The honest fact is that, if you go low level enough, it (equivalent) is the only method of not proceeding to the next instruction, so you'd think that it would make sense to have it in all the higher languages.
    However, the difference there is each label is (generally) only used once, and the state of all registers will be the same before and after. The problem with goto is that it requires the compiler to work out the meaning of all the variables at the point it jumps to, and to deal with loading those all into memory as part of the jump operation. At least with breaking out of a loop, you're going to be in the same scope as leaving it through the loop's condition becoming false. Returning from that context will move up (or, if you view things the other way, down) a scope, which is reasonable to deal with

    GOTOs, on the other hand, used to allow jumps into noticeably different scopes, where variable contexts could lead to information not having the right meaning. And, that's where the raptors break through.

    [citations needed]

  • by jps25 ( 1286898 ) on Thursday January 19, 2012 @11:01AM (#38747886)

    The Linux kernel uses goto statements. About 95000 times..

  • by VGPowerlord ( 621254 ) on Thursday January 19, 2012 @11:32AM (#38748208)

    Oddly enough, GOTO does have a legitimate use in C#. Switch statements in C# don't fall through. If you want a switch statement to fall through, you have to use a goto ; to force the fall through.

    Unless it's an empty switch statement. Those are allowed to fall-through.

  • by Twylite ( 234238 ) <twylite@cr[ ].co.za ['ypt' in gap]> on Thursday January 19, 2012 @11:34AM (#38748222) Homepage

    Judicious use of GOTO can dramatically simplify resource cleanup when exception handling is not supported. A function that must grab N resources in order (and free them in reverse order on success or failure) requires N nested blocks if you don't use GOTO (and no nesting if you do use GOTO). Often the only way to refactor such logic into sub-functions is by using continuation passing style, which is clear as mud.

  • by gstoddart ( 321705 ) on Thursday January 19, 2012 @11:44AM (#38748338) Homepage

    Interesting comment, but I'm with Dijkstra on this one:

    One of my profs once laughed at me when I said his code had a goto and we shouldn't do it that way (because that's what we'd been taught in class).

    Then he sat me down and walked through the code, and explained what the code was doing, and the failure modes that made it necessary to use a goto. This was OS-level code, and performing some very fiddly things, and several layers deep in looping structures. You'd have had to put in twice as much code to check the error conditions necessary to peel out of that, and since it was essentially working on bare metal, there was simply no room to add much more overhead.

    He did manage to convince me that a goto isn't something you do because it's convenient, but that in some code, in some languages there simply isn't a better alternative to bail out of some code in the event of a failure.

    I have worked in a couple of languages (one being C, the other proprietary) in which a goto was the cleanest/only way to get out of the code, and get to a place where you could do all of your cleanup and get out cleanly.

    It has its place, but it should definitely be used sparingly. Blindly saying never use a goto doesn't always give you the best solution.

  • by ais523 ( 1172701 ) <ais523(524\)(525)x)@bham.ac.uk> on Thursday January 19, 2012 @11:50AM (#38748426)
    The purpose of goto is to stand in for whatever control structures your language needs but doesn't have. Goto for error cleanup in C is one of those examples: it's the best way to do it in C, but if the language had better support for doing that, a goto wouldn't be necessary.
  • by Karrde712 ( 125745 ) on Thursday January 19, 2012 @12:04PM (#38748576)

    GOTO is certainly very useful in some circumstances. For example, a common pattern in the samba and SSSD sources is this (taking advantage of the talloc() hierarchical memory allocator):

    tmp_ctx = talloc_new(parent_ctx).
    *allocate memory on tmp_ctx *
    do stuff or fail and goto done.
    *allocate more memory on tmp_ctx *
    do stuff or fail and goto done.

                    return result;

    It's really handy to be able to just jump directly to the done: tag on any error and know that any memory you allocated is cleaned up appropriately.

  • by Twylite ( 234238 ) <twylite@cr[ ].co.za ['ypt' in gap]> on Thursday January 19, 2012 @12:21PM (#38748812) Homepage

    [citations needed]

    Citations won't be found, because the explanation is incorrect. There is no technical issue with compilers implementing 'goto' so long as the destination is in the same lexical scope (C has this limitation). Nor is it worth considering execution context at the level of the CPU, as any high-level loop or branch instruction must be translated into one of a limited number of conditional or non-conditional, relative or absolute jumps. Ultimately whether you use 'goto' or some other control construct you are attempting to express the same programmatic flow, and the compiled instruction stream will be sufficiently similar that it's not worth splitting hairs over.

    The reason 'goto' is "considered harmful" is because structured programming [wikipedia.org] theorizes that any computable function can be expressed by combining simpler programs using sequence, selection and iteration; and this provides the opportunity for a constructive approach to program correctness. Dijkstra argues [utexas.edu] that we are cognitively limited and can benefit from code that is structured so that we can tell at any point where we are and where we have come from (a gross paraphrasing of what Dijkstra calls "coordinates"). But "[t]he unbridled use of the go to statement has as an immediate consequence that it becomes terribly hard to find a meaningful set of coordinates in which to describe the process progress". In other words careless use of 'goto' makes it hard to reason about your code.

    Knuth contended that one could created structured programs with 'goto' statements [snu.ac.kr], and provided examples of how 'goto' make the program more elegant.

    It is important to realise that the claimed advantages of structured programming are undone by the use of break, continue, or exception handling. There are limited forms of goto, and using them prevents proofs of correctness (under the assumptions of structured programming; other techniques may be available) and reasoning using Dijkstra's "coordinates".

  • by TheLink ( 130905 ) on Thursday January 19, 2012 @01:08PM (#38749406) Journal

    I would skip GOTO in favor of putting some of that logic into a function. Then I can simply return;

    Sometimes that makes the code harder to read - you have to go look up what each function does, when it's actually a different but simple thing each time.

    Visual Studio does make the looking up quite easy (and you can nav back to the original place from the function), but it still takes longer than just looking at everything in one page and then scrolling a bit to see the rest.

    And lastly, you often have to come up with decent names for those functions ;). Sometimes coming up with good names takes longer than just writing the code...

  • by Grishnakh ( 216268 ) on Thursday January 19, 2012 @04:46PM (#38752682)

    Nowadays, the idea of using goto as a 'jump to function end' is reasonable, and a lot less expensive than throwing an exception to do the same thing... yes, I've seen them used for that.

    It's extremely common in Linux kernel code (particularly device drivers), as it's used for error handling there, so that you can perform resource-freeing operations in reverse order very simply without a lot of indentation and braces.

    ret = do_op1();
    if (!ret)
            goto fail1;
    ret = do_op2();
    if (!ret)
            goto fail2;
    ret = do_op3();
    if (!ret)
            goto fail3;
    ret = do_op4();
    if (!ret)
            goto fail4;
    return 0;

    return -1;

    Try rewriting that in C, without goto, in an unconvoluted way. And don't exceed 3 levels of indentation, and don't create any additional functions.

Nothing ever becomes real till it is experienced -- even a proverb is no proverb to you till your life has illustrated it. -- John Keats