Breaking

Wednesday, November 7, 2018

Advantages of Python over Java:Why Learn and Use Python first

the advantages of python over java
the advantages of python over java

Many people are skeptical with Python language, they keep asking are there any advantages of Python over other languages. Java and Javascript are more popular programming languages than Python. But Python is the fastest growing language on the planet. What are Python features that make so many developers want to master it.

As a Python programmer, I would surely promote all the goodness that Python has. Python has an extremely simple syntax without unnecessary symbols. This makes development of a product can be achieved rapidly. You can avoid writing verbose code that makes longer development of a product. Python as an interpreted language is slower than compiled languages. However, as the CPU and memory resources are not the most crucial factors in software development, developers are more interested in how quick they can deliver the end product. Above all, Python has plethora of libraries that will evade you from building anything from scratch.   

People are comparing a programming language over another in search of the most suitable programming language to solve their problem. We can find articles, blogs, chats, infographics and even memes comparing two or more languages showing which one is better than the other from the author's stand point.

However, we must understand that every programming language has its own strengths and a programmer will eventually master more than one language. They will use a certain programming language to solve a particular problem. Therefore, this article is not intended to advocate readers to only learn and use Python in his/her live. If you want to know the advantages of Java, you can Google it and find it elsewhere.


The main purpose of this article is to convince someone who wants to start learning a programming language to stick to one language until he/she is really proficient with a language. And that language should be Python. This is based on my own experienced as a self-taught programmer. My first language that I could use to create something was R. It was back in 2013, and then I decided to learn Python in 2015 when I haven't really finished learning R. Since then, I was constantly switching to learn HTML, JavaScript, JQuery, Flask and Django. Well, the last three are only frameworks but learning these frameworks also require a good determination.

The basic reason why I wasn't focus learning a single language was that I didn't have a firm goal and didn't prepare myself with a clear learning path. Initially, I learned programming so that I can become a data scientist. But I made up my mind that I have to be a web developer first when I learned Python fundamental. When I finished a tutorial, I didn't know what to learn next and which another tutorial to follow. I hope you do not experience something similar to mine. If you are convinced to learn Python first until you are really good at it, I will share reliable resources in the end of this post.

So, here are the advantages of Python over Java:

1. Syntax

First of all, Python doesn't use the semicolon. Semicolon is well known among programmers as the champion of hide and seek. Programmers wasted countless of working hours fixing bugs caused by missing or misplace the semicolon. This symbol is used as a sign that a statement has reached the end, like a full stop in the English language. Many programming languages, including Java use semicolon as statement terminator and this can be onerous work for a beginner to frequently checking this bug.

Secondly, Python use indentation instead of curly brackets to indicate a block of code. This will increase the readability of a program. Advance programmers won't consider that curly brackets add hustle to their work since modern IDEs puts automatically the closing curly bracket. But for novice programmers, rows of closing curly brackets in nested loops for example can be so confusing. Sometime, one of the closing curly brackets was accidentally deleted, creating another error which takes quite a long time for beginners to spot and fix.

Finally, Python is dynamically typed language. This means that we don't have to declare the type of a variable. On the other hand, Java is statically typed language in which the type of all variables must be declared explicitly and it must be cast it to a different type when needed. For example, a data with int type can be cast into a float type. The dynamically typed languages surely make code significantly easier to write and change. It essentially makes coding simpler because less words is needed.

2. Simplicity/Verbosity

Take a look at the 'Hello world' program of Python and Java. Something that can be done in one line in Python, must be written in lengthy code in Java. It contains more words than are necessary. In contrast, Python is so similar to plain English, everybody can understand it pretty quickly.

print("Hello World!")
public class HelloWorld {

    public static void main(String[] args) {
       // Prints "Hello World!"
       System.out.println("Hello World!");
    }

 }

Python's simplicity makes the life of programmers easier. They can put more focus on tasks rather than on the code they write. It is also really easy to understand other programmer's code when we read it. As a result, Python code can be rebuilt, rewritten or improved by other developers.

3. Productivity

Coding in Python boost developers' productivity. This is mainly because Python programmers type fewer lines of code and produce less syntax errors. The conciseness of Python increases at least five folds of programmers' productivity. Other aspects that support productivity in Python are clean object-oriented design, enhanced process control capabilities and its own unit testing framework. Python is a great choice for building scalable multi-protocol network applications.

The productivity gap can be reduced by Java programmers when they utilize an enterprise IDE. But for a beginner, the verbosity of Java is still a major hurdle to overcome. If you decide to learn Java as your first programming language, it will take a longer time to get use to the language.

4. Speed

All of the advantages of Python mentioned above come at a price, Python scripts run slowly. First of all Python code is interpreted at runtime instead of being compiled. Moreover, Python allows programmers to write programs that similar to how humans think, it abstracts the details of the computer.

The dynamically typed language also has a consequence. At the time the program executes, the interpreter must identify the types of each variable from the system. This gives interpreter more work to do at runtime.

Before you leave Python merely because it takes a longer time to run, better read this article first:

Yes, Python is Slow, and I Don’t Care

There is a trade off between time to run and time to market. Nowadays, the development time is more crucial than run time of a program. The critical point in today business is how fast you innovate, how fast you deliver your idea to customers hands. The problem with performance of a program can be reduced by adding more CPU and memory resources, which is not really expensive anymore.
If you are a programmer who love to brag about how fast a code should be, check out how giant tech companies use Python in their production. Google and Quora for example, they write speedy C++ functions to handle performance-critical code. And it is super easy to embed C or C++ functions into Python modules.

In addition, Python has adopted asynchronous programming since Python 3.4. Python introduced a standard library called asyncio, a framework for concurrency and asynchronous I/O management.

If you don't know what asynchronous programming is, you better check this blog which has really good explanation by using analogy of a chess master playing against multiple players. 

In short, Asynchronous programming doesn't speed up a program, it's just optimizing the time. Async eliminates or minimize time wasting on waiting around, it's always finding something to do. Async programming enables Python to soar high handling 186k request/second in the form of Sanic, a Flask-like Python 3.5+ web server that’s written to go fast.

5. Python has voluminous libraries

Python comes with comprehensive standard library. When you want to do something fascinating, all you have to do is importing pre-packages libraries available inside Python. These libraries incorporate functions to do text processing operations, advance mathematical calculations, time and calendar operations, handling data, files management and many more. 

Python built in libraries are awesome, but it's not everything you have. In fact, you will bolster your Python power by adding third party libraries. Currently there are more than 170,000 third-party libraries (and growing), ready to be downloaded.

The sheer number of Python libraries tell you how extensive the applicability of Python can be. You can find almost anything you need to deal with any problem you want to tackle. 

You will build applications in Python just like joining building blocks. Accordingly, developers save a lot of time and money because they don't have to build their tools from scratch.

In contrast, since early 2019 Oracle charges Java SE updates for commercial use. Java developers have two option to deal with it, rely on OpenJDK-related libraries or move to enterprise related libraries (source).

Conclusion 

Python
Java
Doesn't use semicolon

Use indentation instead of curly brackets

Dynamically typed
    Use semicolon (The hide and seek champion)

    Use curly brackets

    Statically typed
      Simple like plain English

      More focus on the tasks

      Easy to read other's code
        Verbose, contain more words

        More concern to the code to write
          Python programmers type fewer lines of code and produce less syntax errors.
          Must use enterprise IDE to increase coding speed.
          Python code run slower, but time to market is more important than time to run the app.
          Java code run faster.
          Have an extensive amount of third party libraries. Ready to be used building almost anything.
          Limited to OpenJDK libraries or move to Enterprise Libraries.

          Python has proven that it is an easier language to learn and use and also very robust programming language. Python is the right choice to be your gateway to enter programming world. 

          Now, if you believe that Python is the right language for you, you can start learning the essence aspects of Python programming from Lean Python book. You will learn only the core of Python without needing to learn something you'll never use.

          Don't forget to plan your Python learning journey by following Python Learning Roadmap.


          No comments:

          Post a Comment