Poem: The Spider and The Serpent
One of them was quiet, The other liked to hiss; I never knew they'd bite me once They leaned in for a kiss; The venom power's strong, I fell right for their trap; One spun a bed of web, The other tripped me for a nap.
I watched a YouTube video the other day where the speaker spoke about powerful languages like Lisp and Tcl. I asked myself, "Why don't I know these languages?" Then I thought, "because I know Python and JavaScript!"
These are not the best programming languages out there, I haven't tried enough languages to make that claim. But they are very effective in helping me to get things done.
But what makes them so effective for me?
They both use modules
Modules are files that contain bits of code. These modules can be imported into other code files. In both Python and JavaScript, modules can be aliased and can help you contextualize your code better.
For example, in Python:
from shapes.square import Area as SquareArea
from shapes.circle import Area as CircleArea
side = 4
SquareArea().calculate(side);
radius = 4
CircleArea().calculate(radius);
For example, in JavaScript:
import { Area as SquareArea } from "./shapes/square";
import { Area as CircleArea } from "./shapes/circle";
const side = 4
new SquareArea().calculate(side);
const radius = 4
new CircleArea().calculate(radius);
Being able to split your code neatly into smaller files also makes maintaining code easier.
They are both interpreted
Interpreted languages like Python and JavaScript do not have to compile before they are run, making rapid application development (RAD) possible. No building is required at all1.
For Python, restart python
. For JavaScript, refresh the browser.
They both have REPLs
REPL stands for read-eval-print loop. It's pretty much a computer programming environment where you can:
- put in commands (i.e. the computer reads the command)
- press Enter on your keyboard (i.e. you request the computer to process the input)
- wait for the computer to process what you put in (i.e. the computer evaluates the command)
- wait for the computer to show the results on your screen (i.e. the computer prints the results it got)
This is basically how a shell works.
This makes debugging and testing so easy and quick because you don't have restart the entire program each time. I love this feature and it really comes in handing when writing websites, even this blog.
For Python, you would just call the python
command to enter the Python shell. Then you can type commands as you like:
$ python
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
For JavaScript, you can inspect any element on the webpage by right-clicking and selecting Inspect, then switch over to the Console tab of your browser. From there, you can access the DOM:
>> $0.nodeName
"IMG"
They both are used for the web
I like that I can write any program for the web using these languages (along with HTML and CSS). I just need to restart the server and/or refresh the browser to see my changes.
They are easy to read
Reading through some well-written Python and JavaScript code is very relaxing to the brain. Ideas can be expressed so neatly.
They both use weak typing
Strong typing is not a language flaw at all, but in some contexts, it could be really distracting. I love languages where the chosen names by the programmer make the code more legible than using the types.
In my experience, I only care about typing when I need to debug an issue. Also, splitting my code well into proper contexts makes types less useful.
Here is an example of no typing with JavaScript:
class BankAccount {
constructor(owner, balance = 0) {
this.owner = owner;
this._balance = balance;
}
deposit(amount) {
if (amount > 0) {
this._balance += amount;
console.log(`${this.owner} deposited $${amount}.`);
}
}
withdraw(amount) {
if (amount > 0 && amount <= this._balance) {
this._balance -= amount;
console.log(`${this.owner} withdrew $${amount}.`);
} else {
console.log('Insufficient funds or invalid amount.');
}
}
get balance() {
return this._balance;
}
}
// Usage
const account = new BankAccount('Alice');
account.deposit(100);
account.withdraw(40);
console.log(`Balance: $${account.balance}`);
And strong typing with Typescript:
class BankAccount {
private owner: string;
private balance: number;
constructor(owner: string, balance: number = 0) {
this.owner = owner;
this._balance = balance;
}
deposit(amount: number): void {
if (amount > 0) {
this._balance += amount;
console.log(`${this.owner} deposited $${amount}.`);
}
}
withdraw(amount: number): void {
if (amount > 0 && amount <= this._balance) {
this._balance -= amount;
console.log(`${this.owner} withdrew $${amount}.`);
} else {
console.log('Insufficient funds or invalid amount.');
}
}
get balance(): number {
return this._balance;
}
}
// Usage
const account = new BankAccount('Bob');
account.deposit(200);
account.withdraw(50);
console.log(`Balance: $${account.balance}`);
Which do you prefer to read? Which one makes sense faster?
They are both easy to teach
Compared to lower-level languages like C and C++, Python and JavaScript are easier to become proficient in, as the programmer does not need to understand low-level concepts to get things done. For example, a knowledge of pointers does not help much in writing Python or JavaScript code.
Additionally, it makes it easier for programmers who already know C and C++ (like me) to learn. I also think this is why I appreciate the Python and JavaScript.
They both have clear goals and domains
In the words of Guido van Rossum (the creator of Python):
My goal is to make Python a language that is fun to use, and one that is so easy to learn that it brings the joy of programming to as many people as possible.
JavaScript has the goal to be the language for the web.
Brendan Eich's goal for JavaScript was to create a lightweight, interpreted scripting language for the web that could make web pages interactive.
Python has many domains such as machine learning, web development, data science, automation, game development, embedded systems, finance and fintech, desktop applications and many more.
JavaScript, once again, has the web, though it has also been ported to many platforms with technologies like Node.
They both are easy to maintain
Since they are easy to read and easy to write, they are also easy to maintain.
They both are easy to test
You can test either of them directly from shell (i.e. the terminal for Python and the web console for JavaScript). To test a function added to a class, you simply enter the shell, create an instance of the class and run the function.
They both can be extended
If functionality is missing from the main libraries, Python can be extended with C, C++ and many other languages; JavaScript can be extended with WebAssembly and web components.
They both have a plethora of libraries
Not only do they have a lot of libraries, each one can be added to your project using a package manager: pip
for Python and npm
for JavaScript2.
They both are well supported
They have strong communities that are willing to help and support you. Developer forums like Stack Overflow3 are full of solutions.
They both empower the entrepreneur
As someone that wants to make money on the web someday, they both help my life quite a lot. It doesn't take much to get anything working quickly in these languages, depending on the tasks at hand of course.
Bottom line
If you are looking for languages that are easy to set up and get straight to it, look no further than Python and JavaScript. They can got you covered!
-
I know what I've previously said about building, but I don't think that building is bad. I think that building on the web is bad. Modifying web pages should be a breeze for me. ↩
-
Once again, I'm not a fan of using many libraries but it's nice to know that the community has got your back, even if it's just for testing. ↩
-
Who still uses Stack Overflow when ChatGPT is around? ↩