I tried out JavaScript

Pages: 12
Hi, guys. I got a small time job - they needed me to work with Javascript (which I haven't coded in before). Some of it looked similar to C++, but I couldn't really code with it, luckily they didn't need anything big.

The main experience to give was that I made a for loop, which simply multiplied a number (that could changed with every loop) by 2, it did this for 150 times. However, IT WAS SO SLOW. I could literally follow it as it did those calculations with the scroll bar (it was on a spreadsheet)! I didn't realize other languages could be so slow.

The loop was a roundabout way of solving a problem, since I cannot adequately code in Javascript. However, it seems it's only a solution in C++! It's simply too slow on Javascript to be considered a good solution.

Not looking for help or anything, just wanted to share my experience. Thanks guys.
I'll preface this by saying that I absolutely loathe JS. It has plenty of problems, from a completely brain-dead algebraic system[1] to its much-maligned asynchronous model. But being slow isn't one of them. It's definitely not so slow that you should be able to perceive a loop of 150 multiplications. Browser developers have spent quite a bit of effort improving JIT compilers for it.
There must have been some other part of the script stealing CPU time.



[1] '3' - 1 === 2, '3' + 1 === '31', [] + [] === '', [] + {} === (object), {} + [] === 0, {} + {} === NaN. This is all perfectly logical, what are you, stupid?
> [...] from a completely brain-dead algebraic system[1]

https://i.imgur.com/P6wGphG.png

also, relevant xkcd https://xkcd.com/1537/
Well, I trust you Helios. There may have been something else, but it was ONLY going through that one loop. Now, that being said, it was not a controlled environment, it was done on Google (it's what they wanted) through it's spreadsheet. It's very possible that every time it looped through, it had to update the spreadsheet through Google Drive.

Overall, the language was sluggish and slow, but if you say it isn't, then it was most likely the other factors involved with Google.

Thanks for the feedback, I don't know Javascript enough to hate it, but thanks for the heads up!

EDIT: Just took the time to examine the smaller text. If Javascript really handles math like that, I have no idea what to say..
Last edited on
ntchambers - thanks for the post. I guess Javascript really does do math like that. Well, I think it's time to quit my job, thanks for the eyeopener.
Don't quit your job just because of some dumb rules on primitives... not that I'm really defending Javascript, but there's plenty of dumb stuff in C and C++ where the answer is "don't do that".
Quit your job if there were red flags during the interview that your life would be living hell upon entering the job. Otherwise, I'd say at least give it a chance (I dunno how much you like web development).
Well, I'm not really quiting, but they do want me learning Javascript. Moreover, all the work will be done on Google, it's an awful experience to use Google for all the things they want me to do.

A man can dream.
The first programming language I learned was html, but from there went on to javascript. That is where I first started making simple games like tic tac toe and checkers. It may be a weak language, but I still get that itch and go back to it every now and then.

And if you have a bit of a mischievous side, you can use JS to play a lot of fun pranks on your co-workers!
HTML is not a programming language.
Hypertext Markup Language is the standard markup language for creating web pages and web applications. With Cascading Style Sheets and JavaScript, it forms a triad of cornerstone technologies for the World Wide Web.

You are right helios. You can't program a computer with html. But it is still a code, and there is a learning curve to it.
I'd say it's closer to a configuration format (especially since it stems from XML) than actual code.
Morse code is also a code, and it has a learning curve. Conclusion?
My conclusion is that they're both representations of specific types of data, while a programming language is a representation of algorithms.
Well, HTML5 + CSS3 is technically Turing complete. Programming language confirmed?
OK I did not mean to spark a debate here, sorry guys. My only point was JavaScript needs love too.
Love the debates that can get sparked up so easily (no sarcasm!). Still working with JavaScript, all I want to do is smash the language into little pieces.
At least be thankful you're not using it on the backend. One time I had to maintain a JS server a coworker had made and dealing with DB requests that had to be performed synchronously and were non-reentrant was a nightmare. Who ever thought that making every IO operation asynchronous by default was a good idea? We ended up getting race condition-like behavior in single-threaded code (which at that point I had not realized was possible) because one calls could enter the same function before another call had left.
What does that mean? Imagine that you have this function:
1
2
3
4
5
6
void increment_counter(){
    auto value = get_value();
    pause(); //first
    set_value(value + 1);
    pause(); //second
}
pause() makes it so that the function can be exited momentarily and then resumed at that same point later on, while in the mean time a different function, in the same thread, can run. What happens if, while in the first pause(), the same thread calls increment_counter() again?
1
2
3
4
5
6
7
8
auto value = get_value(); //A
pause(); //A
auto value = get_value(); //B
pause(); //B
set_value(value + 1); //A
pause(); //A
set_value(value + 1); //B
pause(); //B 

So what's the solution?
1
2
3
4
5
6
7
8
9
10
11
void increment_counter(){
    static bool locked = false;
    while (locked)
        pause();
    locked = true;
    auto value = get_value();
    pause(); //first
    set_value(value + 1);
    pause(); //second
    locked = false;
}
All the fun of preemption, without the performance.

EDIT: Oh, by the way, this server managed a database that kept track of money.
Last edited on
That sounds just awful. A server like that didn't have to be run with JS, right? Well, I'm glad I'm using JavaScript for petty things!

Thanks for sharing your experience !
Oh, BTW, did you guys hear about CoffeeScript? Made to try to improve usability of Javascript - anyone try it out??
That sounds just awful. A server like that didn't have to be run with JS, right?
Nope! Actually, I told my boss that the code was so awful that if that client ever came back with more work, I was going to rewrite the server in C# during the weekends for free. Really, JS should never have been used for that, I don't know whose idea it was.
I don't know whose idea it was.


The idea came from that guy over there, who only knows one language... JavaScript.

Besides, I thought JS was meant for automating web pages. What were you guys doing with it?
Pages: 12