Updates and whatnot #1
I’ve decided to possibly keep a record of the stuff I’ve been working on every month or maybe even week, because there’s a lot of things I want to try and most of it won’t be written as a post. There’s just not enough content to write or I’m feeling not experienced enough at it to try writing any sort of guide for it. In short, this would probably end up being where I write my thoughts after trying out something new, or old.
Lately, I decided that I’ve put off learning web development for too long and went on ahead to try out Node.js and Express.js for backend development. I have had some experience with web frameworks, namely Vue.js but in working on that, the concepts of web dev had mostly slipped through my understanding so it was almost like learning new things either way. Following the MDN guide, there was a lot that came to mind as I worked through it.
I still don’t really like Javascript as a language. It’s a dynamically typed language, which makes it difficult to follow especially while debugging. I’ve seen the horror examples of default string conversion for sorting:
1
[1,2,4,11,20,33].sort() // which becomes [1, 11, 2, 20, 33, 4]
and the ==
versus ===
operators:
1
2
'66' == 66 // returns true
'66' === 66 // returns false
to which I wondered, why? Having learned languages like C++ and Java as my firsts, Javascript seemed to go against a lot of what were the fundamental ideas in those statically typed languages.
I eventually came to terms with it and, seeing how I never ran into those problems throughout the MDN tutorial, put those ideas aside. In the end, Javascript was mainly for event-driven programming and that was what Node did well. The one staple of Javascript that really threw me off was callbacks, however. To a non-JS person, functions being passed on to another function was foreign.
1
2
3
4
5
6
7
8
9
// example.java
public int A() {
//stuff
}
public int B() {
A(); // A() completes before B()
//stuff
}
This wasn’t helped by the weak types either
1
2
3
4
5
6
7
8
9
10
11
// script.js
function yo(name) {
//stuff
}
function sayHi(callback) {
var what = 'I am Bob';
callback(what);
}
sayHi(yo); // here |yo| is passed as the callback function, which is passed the |what| variable as the parameter
Another new concept was asynchronous operations, which had stumped me since working on Vue. In every other language I had learned so far, the next operation doesn’t execute until the previous one had completed. As such in Python, this was possible:
1
2
3
4
5
6
7
8
9
# testy.py
import time
def helloWorld():
print("Hi")
helloWorld()
time.sleep(3000) # the next "Hi" is printed 3 seconds after the first
helloWorld()
Something else happens in Javascript though:
1
2
3
4
5
6
7
// scripty.js
function yo() {
console.log('Pepperinos')
}
setTimeout(yo, 3000)
console.log('not pepperonis')
In the above script, “not pepperonis” is printed to the console 3 seconds before “Pepperonis”. Therefore, this would be where callbacks come in to run a function after the first one has completed. Another concept I’ve yet to get around to learning about is Promise, which is supposed to be an alternative to async operations.
To my understanding, the reason Javascript and Node works in this way though is because of its use in web applications. Generally, a user could click on a link to load information from a database. That would send a request for the server to handle, but at the same time the user could also interact with some other part of the web app. If synchronous operations were in use, the user wouldn’t be able to interact with anything on the page until the response has been processed, but with async and callbacks, other requests can be dealt with at the same time.
TLDR; Javascript does not write in ANY way like the languages I’ve learned beforehand
In other news, I probably should continue on ahead and learn about a whole stack, possibly MEAN so I would have to try out Angular.js. On the other hand, I could try Django, which is the Python alternative to Node for backend development. Probably not, although I’ve read that Django has a really good built-in ORM (object-relational model), as opposed to using mongoose on Node.
After that, I was planning on returning to some C++ and trying out OpenGL or work on some more game movement concepts in Unity. C# writes like the baby of Java who wanted to be C++ when he grew up. I guess this is where I put up the To Try list.