|
Pom Pey wrote: We ask Politicians ignore.
|
|
|
|
|
|
We certainly are doomed once enough people start getting their "news" and ideas from the Daily Mail...
|
|
|
|
|
Haha: it has been an awful long time since the DM was a "newspaper". It is now a purveyor of dumbed down sound bytes, fake news and Piers Morgan back-slapping pieces.
|
|
|
|
|
Well then, I'm going to Vegas before I die!
Jeremy Falcon
|
|
|
|
|
So, I force myself to write Javascript with this brace style, since it seems that that's what is the "correct" style (example):
function ajaxError(data) {
alertBad(data);
}
But then I see this HTML5 WebSockets
and their example uses the style I'm used to in C#.
So which is the "approved / standard / whatever" style? What style do you use:
1: Javascript style as per example?
2: Braces on separate lines style?
|
|
|
|
|
I don't have a definitive answer on such a religious question.
Use the coding style you are familiar with.
OR
Use the coding style already in place ( follow current style).
I'd rather be phishing!
|
|
|
|
|
Whatever the style, most important is the consistency of the style. I have my own style choices for my personal projects, but then when I have to dive into shared code, I adopt whatever the style which has been chosen. It doesn't prevent me from quickly getting a method or class functionality, provided there is some consistency across the codebase. Everything else are just opinions, and, well, you know about opinions, don't you?...
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
Use what pleases your eyes: you are the one looking at it !
I, personally (in all brace-using languages) would use a style similar to what you call javaScript, except I would put the closing brace aligned with the beginning of the block (i.e., under the 'f' in function. Similarly, under the 'i' in an if-block. My comfort zone for visual organization.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Same as you; mostly because I use the format document/selection menu option in Visual Studio to tidy up code and it's left at the defaults.
|
|
|
|
|
R. Giskard Reventlov wrote: Same as you; mostly because I use the format document/selection menu option in Visual Studio to tidy up code and it's left at the defaults.
Yeah, I just tried that -- VS formatted it back to option 1.
And it's such a useful feature with the html, I guess I'll have to either figure out if it's possible to tell the formatter to use C# style, or live with it, which I've pretty much gotten used to at this point anyways.
|
|
|
|
|
Marc Clifton wrote: VS formatted it back to option 1.
you can change this in VS options
Options --> text editor --> javascript/typescript
|
|
|
|
|
|
Slacker007 wrote: you can change this in VS options
Woohoo! Saved me a google search.
|
|
|
|
|
|
I used to use the format selection option all the time, until it mysteriously disappeared from the menu. Can't figure out how to get it back.
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
I agree with others that it's a matter of personal taste or it's defined by company's coding style / culture.
Whatever the case is, I think the only important thing is to stay consistent.
However, that example actually uses both styles so I don't think it's good idea to follow their styling...
|
|
|
|
|
I actually use both.
Since they both have accepted styles I've adapted and just go with the flow.
Someone's therapist knows all about you!
|
|
|
|
|
Be careful! With JavaScript, it is not just a matter of style[^]. Just use the K&R style or you may introduce subtle bugs.
Plus, K&R is the only true style
|
|
|
|
|
Nemanja Trifunovic wrote: Be careful! With JavaScript
Eep! That was quite informative!
|
|
|
|
|
Nemanja Trifunovic wrote: it is not just a matter of style[^] That is utterly disgusting. An interpreter that changes programmer intent based upon white space can't be trusted.Nemanja Trifunovic wrote: K&R is the only true style I was a K&R true believer for a long time. I like white space (line breaks) in my code to delineate things. When I started writing in C#, I discovered that Allman style[^] reduced the number of line breaks while retaining the visual separation.
Software Zen: delete this;
|
|
|
|
|
Gary Wheeler wrote: That is utterly disgusting. An interpreter that changes programmer intent based upon white space can't be trusted.
There's a reason why so many of us loathe javascript.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
It's stuff like this that reminds me to be glad I don't do web programming.
Software Zen: delete this;
|
|
|
|
|
Disgusting it most certainly is, but it's one of the rules (features, idiocies..) of the language. For something really disgusting try Python, where white space starts and finishes blocks - depending on how many spaces. I use Python, but hate the fascist insistence on the use of white space. I'm comfortable with Javascript, but slavishly terminate statements myself - rather than letting the interpreter/compiler. I have more, much more problems with Python, than Javascript.
|
|
|
|
|
I like you, refused to use 1TBS style braces (it's based on K&R and what JavaScript uses). I came from a C/C++ and PHP world after all. I was a real programmer. Besides, the style sucked. It's evil and ugly. Somewhere ponies will die if I used them.
However, there is a valid reason why 1TBS became so popular with JavaScript. That code on the site was simply written by a rookie to JavaScript. Check out section 3 in the following link...
Brace styles and JavaScript[^]
That one little tidbit is the only valid reason for it and it started it all. In other words, it's only way to return an object literal like that in a function. So the community just adapted this style.
Jeremy Falcon
|
|
|
|