At least it works... this time.



  • @Severity One said:

    @TheCPUWizard said:
    If you run a SED script against 5,000 source files, are you going to open each one and read the code? Having the compiler (or other tool in the chain) throw an error is always prefferable to somethan that depends on a person.
    I dont know how they do things where you work, but where I work, we find an IDE easier when it comes to writing code than sed.

    The tool (SED vs. IDE) is irrelevant. My point is that if you a major transformation on a large number of files, and a person is not going to visually review all of them. If something goes wrong, it is better to have the compilation fail (if possible) rather than produce an executable that is "messed up".


  • ♿ (Parody)

    @dhromed said:

    @boomzilla said:
    I'm not sure what your point is here. Do " 'if' and '}'" have anything to do with each other for anyone?

    He just wants { and } to be aligned vertically. It's an okay point, but there's no reason why one couldn't get used to the same-line style (apart from forced rationalizations about being a visual person (irrelevant) or finding X "impossible" to read (a lie)). It just doesn't matter one bit.

    OK, I guess I was just too focused on the single statement block issue.


  • BINNED

    @Severity One said:

    Well, I must be very bad then, because I leave out braces for single-statements blocks
    Yes, you are bad. Very bad. Go sit in the corner.



  • You know if so many developers didn't live in fucking 1972 they could just auto-format the code to their preferred style while editing it, then auto-format it back before committing it. Using this revolutionary new technology called the "IDE".



  • @blakeyrat said:

    You know if so many developers didn't live in fucking 1972 they could just auto-format the code to their preferred style while editing it, then auto-format it back before committing it. Using this revolutionary new technology called the "IDE".

    Eeek.. I have to agree with Blakeyrat on this one. In fact with most SCCM tools this can even be automated.

     ps: I dont live in 1972, but I do like to visit it. That was the year when I started programming. Computers had blinken lights and switches, and I still fire up the "old 8" every now and them [my freiends collection:  http://www.pdp8.net]


  • BINNED

    @blakeyrat said:

    You know if so many developers didn't live in fucking 1972 they could just auto-format the code to their preferred style while editing it, then auto-format it back before committing it. Using this revolutionary new technology called the "IDE".
    No argument here, but shouldn't that have been directed at the people arguing about whether to put the opening brace on the same line?



  • I'm just blasting it out to all you dumbasses. Like grapeshot. But more deadly. Deadly CLEVER.


  • BINNED

    @blakeyrat said:

    Deadly CLEVER.
    But not clever enough to understand git or apt.



  • Clever enough to understand the importance of usability.



  • @PedanticCurmudgeon said:

    @blakeyrat said:
    Deadly CLEVER.
    But not clever enough to understand git or apt.
    He understands them, they just suck balls.


  • ♿ (Parody)

    @blakeyrat said:

    Clever enough to understand the importance of usability.

    But not clever enough to utilize usability.



  • @Zecc said:

    @dhromed said:
    I can't really test your claim as-is, as the your second return is a syntax error, for reasons I cannot fathom.
    It was just a quick example I wrote, I hadn't actually run it. "invalid label", says Firebug. Strange.

    Note that it complains about an invalid (jump) label, not an invalid property name.

    In the first example, the parser expected an expression (as part of a return statement). Therefore it parsed { prop1: val1, prop2: val2 } as an object literal (prop1: and prop2: being property names in this case).

    In the second example, the parser expected a statement (following a return statement). Therefore it tried to parse the object literal as a block containing a labelled statement, like { foo: while(bar) { ... break foo; ... } } for example. The parser failed with an "invalid label" error because it expected an expression on the right side of the comma operator, but found the prop2: label instead.



  • @fatbull said:

    In the second example, the parser expected a statement (following a return statement). Therefore it tried to parse the object literal as a block containing a labelled statement, like { foo: while(bar) { ... break foo; ... } } for example. The parser failed with an "invalid label" error because it expected an expression on the right side of the comma operator, but found the prop2: label instead.
     

    Fun!

    Which leads to the question why JS tries to process { } as a block when there is no control keyword like if or for.



  •  Variable scope - you can localise vars within braces.



  • @dhromed said:

    Which leads to the question why JS tries to process { } as a block when there is no control keyword like if or for.
    You mean like in C and C++ ?

    Probably because there's some rule on the grammar that says that a block can be put whenever a statement can. You know, like, when you'd normally put a braceless statement after an if or a for.



  • @dhromed said:

    Which leads to the question why JS tries to process { } as a block when there is no control keyword like if or for.

    Why wouldn't it? All the languages JavaScript "borrows" its syntax from do. Nothing's wrong with arbitrary scope creation.



  • @Cassidy said:

     Variable scope - you can localise vars within braces.

    No, you can't. Not in JavaScript. This is a common mistake, because similar-looking languages like C and Java do work this way.

    JavaScript does not have block-level scope. It only has global scope and function-level scope. A local variable declared within a particular function is in scope everywhere in that function.



  • @Someone You Know said:

    @Cassidy said:

     Variable scope - you can localise vars within braces.

    No, you can't. Not in JavaScript. This is a common mistake, because similar-looking languages like C and Java do work this way.

    JavaScript does not have block-level scope. It only has global scope and function-level scope. A local variable declared within a particular function is in scope everywhere in that function even before its declaration in the function.

    FTFY



  • @blakeyrat said:

    You know if so many developers didn't live in fucking 1972 they could just auto-format the code to their preferred style while editing it, then auto-format it back before committing it. Using this revolutionary new technology called the "IDE".
    Yeah, that was the point I was trying to make, but according to some people here, I'm either irrelevant or a liar.



  • @Severity One said:

    @blakeyrat said:

    You know if so many developers didn't live in fucking 1972 they could just auto-format the code to their preferred style while editing it, then auto-format it back before committing it. Using this revolutionary new technology called the "IDE".
    Yeah, that was the point I was trying to make, but according to some people here, I'm either irrelevant or a liar.

     

    You were making a different point. Don't combine two different points and pretend they're one. That's just odd. I'm fully on board with the IDE things.

     



  • @Cassidy said:

     Variable scope - you can localise vars within braces.
     

    JS doesn't do that. Only functions create scope.


  • ♿ (Parody)

    @dhromed said:

    You were making a different point. Don't combine two different points and pretend they're one. That's just odd.

    Shhhh...You're not supposed to remember that. What, did you actually read the thread or something?!



  • I'm waiting for the day every individual can get the style they want locally but for the convert to happen automatically on check-in and check-out.

    That will be the end of all bracing wars.

    In the meantime, open braces on a new line please so they match up vertically with the closing ones.

    P.S. if you set the font in Visual Studio to Lucida Console 8 point, you get a lot more on the screen and I am perfectly capable of reading it anyway.

     



  • @Cbuttius said:

    I'm waiting for the day every individual can get the style they want locally but for the convert to happen automatically on check-in and check-out.

    That will be the end of all bracing wars.

    In the meantime, open braces on a new line please so they match up vertically with the closing ones.

    P.S. if you set the font in Visual Studio to Lucida Console 8 point, you get a lot more on the screen and I am perfectly capable of reading it anyway.

    In terms of braces/indents/etc - I set up a client with exactly that over 7 years ago (using the brand spanking new VS-2005 and TFS-2005). So the "bracing wars" can be ended, but stylistic wars will continue. Within the past 6 months, I have found wonders such as one developer changing iteration variables from "item" to "element", followed by another developer changing them back. Figuring out how each developer could have diferent variable names in their local copies is almost certainly going way to far.



  • @Cbuttius said:

    so they match up vertically with the closing ones.
     

    this doesn't matter



  • @Ben L. said:

    @Someone You Know said:
    @Cassidy said:

     Variable scope - you can localise vars within braces.

    No, you can't. Not in JavaScript. This is a common mistake, because similar-looking languages like C and Java do work this way.

    JavaScript does not have block-level scope. It only has global scope and function-level scope. A local variable declared within a particular function is in scope everywhere in that function even before its declaration in the function.

    FTFY

    Very true. That would be what I meant by "everywhere".

    They call this "hoisting", and while I've never actually been tripped up by it, it's one of those things that you just know is going to cause a really, really difficult to track down bug at some point.



  • @Someone You Know said:

    They call this "hoisting", and while I've never actually been tripped up by it, it's one of those things that you just know is going to cause a really, really difficult to track down bug at some point.

    I actually forgot about that when I posted. (SEE ASHERIDAN!!!!!)

    Fortunately, my IDE is smart enough to remind me I'm reusing "i" as a variable name if I put two for() loops in the same function, so if your IDE doesn't suck then it shouldn't bite you in the ass. So yet again, a problem that doesn't exist if you actually do development using modern development tools.



  • @blakeyrat said:

    @Someone You Know said:
    They call this "hoisting", and while I've never actually been tripped up by it, it's one of those things that you just know is going to cause a really, really difficult to track down bug at some point.

    I actually forgot about that when I posted. (SEE ASHERIDAN!!!!!)

    Fortunately, my IDE is smart enough to remind me I'm reusing "i" as a variable name if I put two for() loops in the same function, so if your IDE doesn't suck then it shouldn't bite you in the ass. So yet again, a problem that doesn't exist if you actually do development using modern development tools.

    Which IDE do you use for JavaScript development?



  • @Someone You Know said:

    Which IDE do you use for JavaScript development?

    Visual Studio, which has pretty awful intellisense for JS. But it's smart enough to catch two variables with the same name in the same scope at least.



  • @dhromed said:

    @Cassidy said:

     Variable scope - you can localise vars within braces.
     

    JS doesn't do that. Only functions create scope.

     

    Yeah, my bad. I just presumed it worked like perl. When SomeoneYouKnow posted his reply, I actually tried it out and... proved myself wrong.


     



  • @blakeyrat said:

    @Someone You Know said:
    Which IDE do you use for JavaScript development?

    Visual Studio, which has pretty awful intellisense for JS. But it's smart enough to catch two variables with the same name in the same scope at least.

    Interesting. I have very little experience with Visual Studio. I'm writing JavaScript code that runs on Rhino (a Java-based JavaScript interpreter) and there's a Java API that it often needs to interact with. Do you know if I can configure VS to do autocompletion and such based on that Java API somehow?



  • @Someone You Know said:

    Do you know if I can configure VS to do autocompletion and such based on that Java API somehow?

    AFAIK it can only auto-complete jquery. (And the JS standard functions, for what that's worth.)



  • @blakeyrat said:

    @Someone You Know said:
    Do you know if I can configure VS to do autocompletion and such based on that Java API somehow?

    AFAIK it can only auto-complete jquery. (And the JS standard functions, for what that's worth.)

    Visual Studio is "just a shell", and fully IDE capabilities can be implemented for any language (I have done a few oddballs + some DSL). There is probably a decent package already available (I dont do any significant Java or Javascript)



  • I don't think providing autocompletion for such a dynamic language is an easy task:

     

    var something = {};
    var propName = 'aProperty';
    

    document.onload = function(){
    something[propName] = 'aValue';
    }

    // something now may or may not have a property called 'aProperty'

    // Of course, that was a relatively stupid & contrived example,
    // and if you write this you have no one to blame but yourself for being 'clever'.

    // But about about the following?

    function stateYourName(obj){
    console.log(obj.name); // What options should have been offered here for autocompleting "obj."?
    //
    // And do you really expect your IDE to go around
    // digging deeply into the code finding every possible
    // type of object that may end being sent here?
    // Oh, well, I suppose it could be done eventually,
    // but think of the poor guys who have to implement it.
    }

    function Singleton(klass, inst) {
    // TRWTF is writing a singleton.
    // But I didn't feel like writing a more realistic example,
    // so imagine this is one of the many examples of
    // mimicking classes in JavaScript that abound on the net.
    if(!klass._instance){
    klass._instance = inst;
    }
    return klass._instance;
    }

    function Dhromed() {
    return Singleton(Dhromed, {
    name: 'dhromed';
    chooseRandomTagsForPost: function(){ return 'dick'; }
    });
    }

    function Blakeyrat() {
    return Singleton(Blakeyrat, {
    name: 'blakeyrat';
    evaluateUsability: function(software) { return 0; }
    });
    }

    stateYourName( new Dhromed() ); // TRWTF2 is using new for getting a singleton.
    stateYourName( new Blakeyrat() ); // Yes, this can be done, in case you've never thought about it.

     

    I'm using this thread as a place for writing bad code on purpose. Deal with it.
    I think the point I was trying to make still holds.


  • BINNED

    @Zecc said:

    function Blakeyrat() {
    return Singleton(Blakeyrat, {
    name: 'blakeyrat';
    evaluateUsability: function(software) { return (software.vendor == "Microsoft") ? 9001 : 0; }
    });
    }

    stateYourName( new Dhromed() ); // TRWTF2 is using new for getting a singleton.
    stateYourName( new Blakeyrat() ); // Yes, this can be done, in case you've never thought about it.

     

    FTFY


  • Considered Harmful

    @PedanticCurmudgeon said:

    { return (software.vendor == "Microsoft") ? 9001 : 0; }


  • BINNED

    Uhhh....that's the joke?



  • @Zecc said:

    I don't think providing autocompletion for such a dynamic language is an easy task:

    To be honest, I don't care if it can autocomplete the JavaScript stuff; I really only want it to autocomplete the names of methods in the Java API that's called from the JavaScript code.

    I need this mostly because the people who wrote the Java API have not been good about keeping to any kind of naming convention. For instance, if there's some object Foo, and it has a name, the method to get it might be Foo.getName(), or it might be Foo.getFooName(). Or Foo.getTitle() or Foo.getFooTitle(). Each of those schemes is in use for at least one value of Foo in the API. Fortunately there's a collection of Javadoc that lists all of it, but I hate having to look this stuff up all the time.



  • @joe.edwards said:

    @PedanticCurmudgeon said:
    { return (software.vendor == "Microsoft") ? 9001 : 0; }
    Filed under: It's over nine thousand!
    Saved before next tag cloud cleansing.



  • @dhromed said:

    @Cbuttius said:
    so they match up vertically with the closing ones.
    this doesn't matter
    It does not matter to the compiler, but it matters to me. What's so difficult to understand about that? Your car won't run any better if you clean all the bird shit off, yet people still do it.

     



  • @Severity One said:

    What's so difficult to understand about that?
     

    What's difficult to understand is why you think it matters, when it doesn't.

    Brace position newline or sameline does not affect readability once you're used to it, which takes about five minutes. Sameline is not objectively and permanently worse to newline braces. Having to get used to something is not an indicator of inferiority.

    I'm trying to help you prevent pointless friction when you end up at a shop where the prevailing coding style is sameline braces. I'm empowering you! You should be grateful! Give me money!

    @Severity One said:

    Your car won't run any better if you clean all the bird shit off, yet people still do it.

    You win a prize for least-applicable metaphor. Good job.

     



  • Dear everyone who cares about brace position,

    You want to find an editor that does this:

    Sincerely,
    pkmnfrk



  • @pkmnfrk said:

    You want to find an editor that does this:
     

    The only one that doesn't is Notepad.

     

    and Visual Studio.


  • ♿ (Parody)

    @dhromed said:

    @pkmnfrk said:
    You want to find an editor that does this:

    The only one that doesn't is Notepad.

    and Visual Studio.

    Is that really true? Or a configuration malfunction (which, as we've learned from blakeyrat, is actually a bug). Most text editors, let alone IDEs, do that or at least have that as an option.



  • @dhromed said:

    @pkmnfrk said:

    You want to find an editor that does this:
     

    The only one that doesn't is Notepad.

     

    and Visual Studio.

    Bullshit.

    Edit: I changed the colour to make it more visible, but the option is most definitely there.



  • @boomzilla said:

    Is that really true?
     

    Notepad doesn't know jack about brace matching or indent-guides or block-guides, therefore That is really true.

    VS does brace matching, but doesn't have indent or block guides, so I guess I was slightly dishonest there.

    Still, if we present the statement strictly as "You want to find and editor that does (brace matching && indentguides & blockguides)" then both Notepad and VS evaluate to false, and That is again really true.

    What I mean is logic goddamit.



  • @pkmnfrk said:

    Bullshit.
     

    You are correct! I already said I was dishonest, but you ninja'd me so that can't be helped.



  • @dhromed said:

    @boomzilla said:

    Is that really true?
     

    Notepad doesn't know jack about brace matching or indent-guides or block-guides, therefore That is really true.

    VS does brace matching, but doesn't have indent or block guides, so I guess I was slightly dishonest there.

    Still, if we present the statement strictly as "You want to find and editor that does (brace matching && indentguides & blockguides)" then both Notepad and VS evaluate to false, and That is again really true.

    What I mean is logic goddamit.

    Interesting. I'm not sure that including the intent guides is a good measure, at least for languages where braces matter. vim doesn't have them, nor does emacs or notepad (or visual studio). In fact, Notepad++ is the only editor installed on my PC right now that has them. If we exclude them, then VS evaluates to true, while Notepad still evaluates to false.

    Basically, what I'm saying is that brace positioning is completely irrelevant and we should all just live with it.



  • @pkmnfrk said:

    Basically, what I'm saying is that brace positioning is completely irrelevant and we should all just live with it.


    All matching braces must be a prime number of lines apart.

    Braces must always be used on else, including else if.



  • @pkmnfrk said:

    I'm not sure that including the intent guides is a good measure,
     

    I like 'em.

    They're coloured a really faint grey so that they're not in the way, but become visible when I look for them.

    @pkmnfrk said:

    Basically, what I'm saying is that brace positioning is completely irrelevant and we should all just live with it.

    And now for a beer.

     


Log in to reply