|
Perhaps someone has mentioned this but haven't read *all* the responses
There is actually a bit of a caveat with JS: it terminate some lines automatically (like an invisible semi-colon)
Open your browser and go to the dev-tools (typically F12) and enter the following:
var f1 = function() {
return {
value: 'the-value'
};
}
var f2 = function() {
return
{
value: 'the-value'
};
}
Now have it execute
f1() and then
f2() . You'll quickly see the difference
It is better to stick with the "standard" with braces on the same line. For my C# code it's is quite different.
|
|
|
|
|
Generally follow the standards / style guide at your place of work.
However, with JavaScript there can be gotchas; due to semicolons being optional, as per this example:
javascript - Why does a results vary based on curly brace placement? - Stack Overflow[^]
So you have to be cautious that in such cases you use the code that works over the dictated style; and put a comment so no one decides to clean up your formatting not realising that they're introducing a bug.
If you're defining a style, I'd say it's best to pick one which avoids this issue, so going with some variant of K&R makes sense for this language, to avoid such pitfalls & any cognitive load related to spotting them.
For most other languages (i.e. where placement is solely formatting), I'd typically recommend Allman style for clarity (personal preference); though I may suggest K&R for any projects where the same developers are likely to work with JavaScript; again so they don't have to think about it (i.e. when switching languages).
Regarding my personal preference; historically I was a K&R advocate, but later realised that the Allman style allows lining up the open and close brackets, which is more obvious than lining up the code responsible for the bracket. Once you develop the habit of thinking "the line before the open brace is the one defining this block" rather than "the first line of the block defines the block & ends with the opening brace" it pays off. You do use up more screen real estate; but often (at least for developers with large monitors), that's good, since it removes clutter.
|
|
|
|
|
The obsessive compulsive in me hates the 'brace on same line' style. It
feels like you're deliberately starting something on the end of a sentence. Start
a statement/block at the start of a line, that's easiest for most of us to read. I
think.
(If that paragraph was a little harder to read than normal, my point is made).
There's a good case for the vertical compression that the K&R style offers, showing more code on screen at the same time makes it easier for the reader to take in more at once. Ideally, he/she should be able to see any function/method onscreen at once.
Conversely, if you have nested blocks, I find the Allman style far clearer in determining which brackets match with which.
Ideally the editor would just display according to the preferences of the viewer, but as per the js example above, it's probably not always feasible. I don't know if source-comparison tools are smart enough to determine "nothing changed apart from indentation/non-printing characters, so mark nothing as changed".
|
|
|
|
|
Yes, it is the "correct" style for Javascript, even though I hate using it. When I program in other languages, I always use a new line for a brace, either opening brace or closing brace.
But in Javascript, if you use the opening brace in a new line, Javascript may automatically insert a semicolon in the previous line.
Try searching the Internet about this "feature". For example, you may consult javascript - Why does a results vary based on curly brace placement? - Stack Overflow[^]
|
|
|
|
|
The simple solution is to use a text editor that can be customized. The first thing I do to when I get a source code file is use my editor's auto-format feature to reformat the file to my preferences.
|
|
|
|
|
Tel Aviv: I'm told it Israeli a fun place to go.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
bring a partner, always more fun when you kosher
Installing Signature...
Do not switch off your computer.
|
|
|
|
|
Jewish mate!
... such stuff as dreams are made on
|
|
|
|
|
Well Galilee, that was a tough one to catch. There's Eilat to be said for visiting Israel.
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 |
|
|
|
|
|
Ask for them cookies[^] and pray they don't colonize your arse.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
That one was so bad, I have Haifa mind to report it as abuse.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
|
His posts are so bad, it makes me think he has a Holon his head.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
|
That pun Gaza ginst all my principles. Jewish to repent?
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
|
Aaand another one Uzis soon the drain...
|
|
|
|
|
Oh Meirs - I am Begin you to stop this. Peres the thought that this might Sharon the Netanyahus started spreading it around.
I'm pretty sure I would not like to live in a world in which I would never be offended.
I am absolutely certain I don't want to live in a world in which you would never be offended.
Freedom doesn't mean the absence of things you don't like.
Dave
|
|
|
|
|
There is weekly quiz on the German c't computer magazine web page. This week you have to identify system crash screens. I reached at least more points than 50% of the participants. I failed to get those of Windows 8.1 (never used that; only 7 and 10).
But it raises the question for me when I last had one. As far as I remember it is about 6 years ago where a defective RAM module was the reason.
For those who want to try it even not knowing German (which is not really necessary for doing the quiz but makes it a little bit harder when not uderstanding the short questions which contain sometimes additional information): #TGIQF - das Quiz: Crash mich noch mal! | heise online[^]. Just click "Quiz starten", the (hopefully correct) answer (be quick; short times count for points), and "Weiter" (Next) to continue.
|
|
|
|
|
|
For me it looks more like a glory hole (within mine the computers are at least properly stacked) ![Big Grin | :-D](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_biggrin.gif)
|
|
|
|
|
... ohhh ... "weiter" ...
(werde ich sie ausknocken)
|
|
|
|
|
Pshaw. My recently-retired old work computer blue-screened slightly more often than once a day.
Software Zen: delete this;
|
|
|
|
|
Gone are the days where you make a piece of shareware-type software and expect to make serious money for it. For instance, I use Sublime Text 3 a lot. It's awesome. The peeps that made that did a fantastic job. It's fast and lightweight and very customizable. And it's only $80 to register. Yes, there are free alternatives but few are as zippy as Sublime. Here's the kicker though, every tutorial you see online using Sublime usually says unregistered more times than not in the titlebar. Which I don't get... it's only $80 and the amount of work that went into making the software must've been insane. And you can use one license at home and work with very few restrictions. It's great.
I know in the world of GPL and with so many young kids online now, free is where it's at on the surface. And people will gladly give up human rights, privacy, their first born's livelihood, etc. as long they have the illusion of free by not costing dollars upfront. But, let's just assume developers also have bills like the rest of the world and so money is useful. I'm curious how y'all monetize software these days since clearly, unless it's a very niche piece of software then there's usually a free alternative to whatever we're making now.
Anyone still using the ol' shareware try before you buy model? I know there are some people that'll have two product offerings. A dinky one that's free to get them in the door and a real one that's complimentary that costs money. I know people will pay for perceived value, it's just software is becoming so common place it's perceived value is going down in and of itself (for average stuff online, not LOB software). So it's either go niche or go home, or create a service people will rely on.
Right now the best model I can see with niche software, that is not a service, is to keep the software "free" but then sell any required knowledge to actually make use of it. Which like LOB apps, also require business domain knowledge to really make use of. Knowledge is still valuable and certain things take a skill to make work. So it has a low barrier to entry on the surface, but realistically it won't do you one bit of a good unless you know what you're doing with it and really know what you're doing outside of faking it.
To use an analogy, basically let's say I have a hammer (the software). If I give someone a hammer, nobody realistically expects a person to magically be able to a build a house with zero training now. On the flip side, for those that can build homes, you need a hammer to do so. So you give the shiny hammer away for free knowing full good and well, it's going to be useless to the untrained hand. But now you have my hammer and know my company name. So, the hammer is considered the cost of customer acquisition now and sell the info required to train people to use the hammer.
I'm there are other ways to make money with software I'm not aware of. So, I'm curious. Is there anyone in CP land actually making any real money with software outside of LOB apps or services? And if so, what model are you using?
Jeremy Falcon
modified 17-Nov-17 9:28am.
|
|
|
|
|
Jeremy Falcon wrote: Gone are the days where you make a piece of shareware-type software and expect to make serious money for it. Take a look at "Stardew Valley"; created by a single person, and still a commercial game.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|