Join us
@dridhone ă» Dec 27,2021 ă» 8 min read ă» 1123 views
JavaScript vs Python : Which Should You Learn? | dridhOn
Like many marketers, you may fantasize about the amazing things you could do if you learned to code. But before you get there, you need to decide which language to learn.
Several languages come up: Python, SQL, Bash, JavaScript. But only two are full-fledged programming languages â JavaScript and Python. If youâre interested in programming, these are the two languages that you should compare.
Deciding between the two should be based on:
Your interest in other fields.
This article discusses the pros and cons of JavaScript and Python to help you determine which one you should go for.
Python for data and automation geeks
Python is a better fit for marketers who specialize in data analysis and visualization. Python has a complete set of tools that make it ideal for data science, math, machine learning, and data visualization.
Here are some practical marketing use cases for Python:
JavaScript for SEO, PPC, CRO, and analytics
JavaScript is a better fit for many other specialties. Marketers interact with JavaScript all the time, whether they like it or not (as youâll see in the examples below). Itâs also the most widely used programming language â by a longshot.
learning JavaScript. Specialists in PPC, SEO, CRO, and product marketing benefit heavily from
Here are some problems JavaScript can help you solve:
If youâre still not sure which language is right, there are three other factors to take into account:
Learning curve: Which language is easier to learn?
I learned both languages from scratch at different stages of my life. For me, JavaScript was harder to learn compared to python.
Learning JavaScript
Initially, JavaScript seems easy because it runs on the browser. To see JavaScript in action, all you have to do is open the JavaScript console and start writing code.
For example, most of you probably know that you can use Inspect Element to edit elements on a web page, but instead of doing that, write this in the console:
document.body.contentEditable=true
Thatâs not just some cool trick â itâs JavaScript accessing the Document object that represents the page and using one of its properties to change the way the page behaves.
But JavaScript becomes complex pretty fast, especially compared to Python. Since JavaScript is first and foremost a client-side language, it puts the user first and the developer second.
For example, letâs discuss Asynchronous JavaScript. Hereâs a piece of code you may recognize:
<!â Global site tag (gtag.js) â Google Analytics â>
<script async
src=âhttps://www.googletagmanager.com/gtag/js?id=UA-XXXXXXâ></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(âjsâ, new Date());
gtag(âconfigâ, âUA-139561223â1â, { âoptimize_idâ: âGTM-XXXXXXâ});
</script>
This is a Google Optimize script. To let Optimize make changes on your site, you must put it in the <head> of your document. Now, letâs say weâve created a basic headline test. What exactly is going on under the hood?
Thatâs the annoying flicker effect. Thatâs also why Google released the anti-flicker snippet. The snippet keeps the page blank until the Optimize data is returned.
In some cases, itâs necessary to mitigate the flickering since the JavaScript snippet is running asynchronously. While it fetches data, it continues to run and loads the rest of the page (until it receives the new version and alters the UI).
You may find the flicker effect annoying, but what if JavaScript werenât asynchronous? Imagine you had a bug in your setup, and you couldnât get data from the server. Your page would never load, and the user would never come back.
Asynchronous JavaScript is a pain point when writing code because it requires additional syntax. You have to state explicitly that the script should wait for a result, or else everything breaks. And itâs not the only hurdle.
Here are some core concepts that you have to learn to really âgetâ JavaScript:
Itâs not super easy. But once you get it, itâs as powerful and amazing as programming gets.
Learning Python
Python, on the other hand, takes a bit longer to set up. You canât run Python in the console, and you canât make alterations to the front end to get by as a hacker. To install Python, you also need to do a bit of reading (depending on your system).
But Python is clean, readable, forgiving, and easy to learn. You can read a Python script like itâs written in English. Check out the code from this article on how to scrape tweets:
import requests
from bs4 import BeautifulSoup
all_tweets = []
url = âhttps://twitter.com/TheOnionâ
data = requests.get(url)
html = BeautifulSoup(data.text, âhtml.parserâ)
timeline = html.select(â#timeline li.stream-itemâ)
for tweet in timeline:
tweet_text = tweet.select(âp.tweet-textâ)[0].get_text()
print(tweet_text)
This is just beautiful.
Using Requests (an HTTP request library) and Beautiful Soup (a web-scraping library), the author was able to scrape and print tweets with eight lines of code.
JavaScript can do that by using the console or Node.js. Hereâs a similar post about achieving the same result in Node.js and Cheerio. This is the code:
const request = require(ârequestâ);
const cheerio = require(âcheerioâ);
var URL = âhttps://twitter.com/hashtag/photography?src=hashâ;
request(URL, function (err, res, body) {
if(err){
console.log(err);
}
else{
let $ = cheerio.load(body); //loading content of HTML body
$(âli.stream-itemâ).each(function(index){
var tweet = $(this).find(âp.tweet-textâ).text();
console.log(tweet); //tweet content
});
}
});
JavaScript just isnât as elegant. But it gets better once you get used to it. It may even âforceâ you to understand more about how the web works, which is a good thing.
But Python really is nice to look at.
The bottom line: JavaScript has a steeper learning curve.
Versatility: Which language can you do more with?
Both Python and JavaScript can be used to achieve many things, but JavaScript is more versatile.
As I mentioned, JavaScript is in everything â from your website to your script tags. Itâs responsible for the UI, but it can also run on the back end with a library called Node.js.
Pythonâs versatility comes from its advantage in data science. While more niche, Pythonâs machine learning, statistics, and automation tools provide a relatively easy-to-use and comprehensive data-science playground, which JavaScript lacks.
For example, Python has a package manager called Anaconda that lets you install a complete data-science suite on your computer. Libraries like Pandas and NumPy cover any number-crunching need youâll ever face. And libraries like scikit-learn let you use machine learning to run predictions based on existing data.
Support: Which language has the strongest communities and libraries?
Python has high-quality libraries, some of which are better than current JavaScript alternatives (especially in data visualization and web scraping/automation).
Here are a few Python libraries that marketers should know about:
Conclusion
JavaScript and Python are both amazing programming languages. Learning either will make you a better marketer.
Python Is a booming Language in the Market and the varieties of Libraries present in python will Amaze the real world implementation especially in the field of Data Science , Machine Learning .
So I would suggest Both Java and python are strong compotators but Python has a more upper hand keeping all points discussed above in the Presentation.
Join other developers and claim your FAUN account now!
Founder, www.dridhon.com
@dridhoneInfluence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.