|
Don't confuse "optional" type checking with "impossible" type checking. You were never been on the other side, where in some random language (I don't want to mention names) you are enforced to write a specific type, where the parameter must be one type if the first parameter has a specific value and another one if it has another value.
|
|
|
|
|
As a general rule, I hate interpreted languages, in the sense: Languages where the syntax the basic semantics are not checked for all the code before execution starts. Some languags would be suitable for such checks even though they are (semi)interpreted languages, but leave the checking to independent lint-like tools (which reminds me: By my definition, good old K&R C comes very close to the 'interpreted' class!) - use them if you care to, but you may ignore them if you want.
There is one readon why some interpreted langages (barely) tolerable to me: I was responsible for maintaining a program system of roughly 100K lines of Tcl - a language having a syntax which is roughly
<token>*
The permitted sequence of tokens, and the semantics of them, are totally context dependent. You don't know if a line is a string constant or an active statement until you encounter it during execution. Or rather, any time you encounter it. In one context the line may be an active statement, a moment later it may be a string literal.
Coming from Tcl to a language where an 'if (<expr>) {...}' really is a conditional statement, always and every time, is a great relief. I sure wish that <expr> was verified to be a boolean expression before we start, but even without that, we are way better off than with Tcl.
But if at all possible, I try to avoid interpreted languages. And dynamic binding. And plugins (well, they are a special case of dynamic binding). Whatever can be checked statically, should be checked statically. And that should be as much of your code as possible, preferably 100%.
|
|
|
|
|
I only use it once in a blue moon so maybe I am missing something but so much of it seems like guesswork - tools such as intellisense don't work with it because objects could be anything. I spend at least 80% of my time in javascript trying to work out what I have and what I can do with it.
|
|
|
|
|
JavaScript is an aberration. Any efforts to make it more manageable (i.e. TypeScript) is just putting lipstick on a pig.
|
|
|
|
|
Agreed, and to really understand the future of JS:
once upon a time people said BASIC would go away, it really needed to happen
well years, no decades later, not just still here, but the super tankers of lipstick applied to it over the years has resulted in such a huge steaming mountainous POS it would choke the black hole in the center of the Milky Way.
and yes, that's where java script is headed.
|
|
|
|
|
I have written quite a bit of complex JavaScript in my time as a corporate developer.
And I am still amazed at why anyone would use such an awful language as their primary language for web development when there are other more mature options available such as not using it altogether and make the bloody server call...
Steve Naidamast
Sr. Software Engineer
Black Falcon Software, Inc.
blackfalconsoftware@outlook.com
|
|
|
|
|
JavaScript is a terrible language and you have plenty of justification to hate it. It is only used because it is the only option on browsers. If another existing language was suddenly supported by all browsers today, it would probably take over JavaScript quickly.
JavaScript is so terrible, many developers prefer not to code in it. Many are creating new languages such as CoffeeScript, TypeScript, etc., that compile to JavaScript. Many are writing compilers for known languages (python, C#, etc.) that compile to JavaScript.
Even the most popular JavaScript libraries (Angular) are written in TypeScript, not JavaScript, and those libraries recommend that we do the same.
|
|
|
|
|
Although it won't make you hate JavaScript any less, you could use a countify factory function to make your existing functions pedantic about the number of arguments they receive:
function argsLength(func) {
return (func + '')
.replace(/[/][/].*$/mg,'')
.replace(/\s+/g, '')
.replace(/[/][*][^/(*)]*[*][/]/g, '')
.split('){', 1)[0].replace(/^[^(]*[(]/, '')
.replace(/=[^,]+/g, '')
.replace(/[\(\)]/g, '')
.split(',').filter(Boolean)
.length;
}
function countify(fn) {
var expectedArgsCount = argsLength(fn);
return function() {
var receivedArgsCount = arguments.length;
var expectedDescription = expectedArgsCount === 1 ? "argument" : "arguments";
var receivedDescription = receivedArgsCount === 1 ? "argument" : "arguments";
if(arguments.length !== expectedArgsCount) {
var errorMessage = ["Expected",
expectedArgsCount.toString(),
expectedDescription + ",",
"received",
receivedArgsCount.toString(),
receivedDescription + "."];
throw new Error(errorMessage.join(" "));
} else {
fn.apply(this, arguments);
}
}
}
Then, with initializePage , you could change its definition to
var initializePage = countify(function(raceList, hlsList) {
});
but, since changing the function definitions of functions you want to countify is a pain, you could just do
initializePage = countify(initializePage)
anywhere after initializePage is defined. As a bonus, you can use this approach to countify library code as well, as long as you don't countify a function that does different things depending on the number of arguments it receives.
Heck, with a few small modifications, you could make countify check argument types as well, by making it take two arguments: an array containing the types of the function arguments, and then the function itself. Adding the checks will of course add a small amount of overhead at run time, but it won't be noticeable at all unless your function is being called tens of thousands of times in a tight loop...and maybe not even then, aside from the tens of thousands of error messages you'd see if you have the browser dev tools open.
As you mentioned, a lot of people will say "just use TypeScript!" which isn't a bad suggestion, but it's not always an option when you've got an existing code base and limited time.
|
|
|
|
|
|
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
It's not because it's a tiny place that it should not be protected
You always obtain more by being rather polite and armed than polite only.
|
|
|
|
|
/ravi
|
|
|
|
|
My front yard has the following signs, starting at 100 yards, spaced 50 yards apart, and extending to 300 yards out:
"If I can still see you, you're still in range."
Interesting factoid: The ground is level, and there is no viable cover behind which you can "hide".
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Do you own something that could be lethal at 300 yards ? I thought you only were in handguns, not in riffles.
|
|
|
|
|
Let's just say the signs are accurate...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Besides which, no self-respecting redneck would live in a cracker box POS like that pictured... That's not a home; it's a prison.
Will Rogers never met me.
|
|
|
|
|
Those are British town houses, like you can see in all the decent residential areas of London. If the rednecks don't want them, I'll be glad to take them off their hands.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
I like the gate that keeps out the...well, maybe the drunks?
|
|
|
|
|
Right!
At least I wasn't Rick rolled!
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Hey, how did you land here ?? This post is about 3 years old !!
|
|
|
|
|
I heard a rant earlier about stackoverflow being pretty useless. Well I tried to improve a solution and it told me I needed 50 points. Well I have been a programmer now for too many years, and worked with C# for over 10 years. No wonder one does not get answers.
|
|
|
|
|
You can actually post a better answer though, you just can't comment.
|
|
|
|
|
Yes, but then you'll get flamed, because you should have posted it as a direct reply, rather than a new comment.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Of course you get flamed, anything in the Big Ego tags gets flamed unless the poster has a brazillion rep points.
|
|
|
|
|
Clifford Nelson wrote: Well I have been a programmer now for too many years, and worked with C# for over 10 years. So how come you don't even have 50 lousy points yet?
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|