DEV Community

loading...
Cover image for Why I shifted from C++ to JavaScript.

Why I shifted from C++ to JavaScript.

Voider
A CS student, I like coding, cycling, photography and coffee brewing.
・2 min read

In this article I will talk about shifting from a compiled language (CPP) to an interpreted language (JS).

Introduction

I have been coding for almost 3 years now and my native language has been C++ for most of that time, but recently I have been preferring JavaScript and I will cover why in this article.

Which is better?

Answering this question depends on what do you want to achieve, for example if you want speed then you should definitely choose C++, you can look up tons of comparisons online between the two languages.

Why am I preferring JS recently.

  • I am a very lazy person and I try to use my brain capacity to the very bare minimum, so using a tool that handles my frontend and backend at the same time saves me the hassle of integrating things together if they are of a different language.
  • It takes a whole lot less time (and brain capacity) to learn, I didn't even realize how hard C++ was until like a year later, but this will significantly help you as a software engineer.
  • You can do so much with so little code, for example let's say you have an array of animals that has a name and species:
var animals = [
  { name: 'Fluffykins', species: 'rabbit' },
  { name: 'Caro',       species: 'dog' },
  { name: 'Hamilton',   species: 'dog' },
  { name: 'Harold',     species: 'fish' },
  { name: 'Ursula',     species: 'cat' },
  { name: 'Jimmy',      species: 'fish' }
]

Enter fullscreen mode Exit fullscreen mode

and you want to copy the names of all the animals to another array, the normal way to do this is by:


var names = []
for (var i = 0; i < animals.length; i++) {
  names.push(animals[i].name)
}

Enter fullscreen mode Exit fullscreen mode

taking up 87 characters

but thanks to JavaScript's ES6 arrow functions we can do this in literally one line:

var names = animals.map((x) => x.name)
Enter fullscreen mode Exit fullscreen mode

taking up 38 characters

you literally just saved up writing 49 characters for yourself, if you can't see beauty in this I don't know when will you ever do.

Last word

Again this is not a comparison at all, I am just stating my personal experience, you should use what's best for what you are working on and what you feel most comfortable with. Thanks for reading.

Discussion (3)

Collapse
pengeszikra profile image
Peter Vivo

JS include lot of fun, for example object destruction:

const names = animals.map(({name}) => name);
Enter fullscreen mode Exit fullscreen mode
Collapse
voider profile image
Voider Author

i agree and i am lowkey in love with how handy it is

Collapse
rawanattia profile image
rawanattia

Too awesome! Keep it up!!