Why should Python not be your first language?
krishnaa192

krishnaa192 @krishnaa192

About: I am a back-end web developer who specialises in Python and Django. I am pursuing engineering in the ECE branch. I am a Machine Learning Enthusiast

Location:
Bengaluru
Joined:
Aug 31, 2021

Why should Python not be your first language?

Publish Date: Feb 14 '24
16 29

While Python is the most hot topic these days, either in web development (not that much), data science, or AI/ML,. Python provides rich libraries for such applications and is kind of cool.There are certain aspects where Python may not be the best choice as a first language when compared to Java or C++.I have discusssed 10 points regarding that.

  1. Data Type Declarations: Variables can be declared without specifying their data type in Python. Dynamic typing offers flexibility and convenience, but it can sometimes lead to challenges related to understanding data types and their limitations.Dynamically typed languages provide less type safety compared to statically typed languages like Java. In Python, you can assign values of different types to the same variable without explicit declarations or checks. In Python, variable x need not be defined explicitly but in a language like Java or C++. ```

int x ;
float x;
x=10.2 //correct
x=10 // will be wrong declaration

While in Python 3.It fails in some constraints,might give errors or not suitable  to set up datatype constraints.
Enter fullscreen mode Exit fullscreen mode

x =10 #be treated as int
x=10.2 #treated as float

 Beginners learning programming with dynamically typed languages should pay attention to understanding data types and their limitations to write robust and maintainable code. Additionally, exploring statically typed languages can provide valuable insights into type systems and their role in software development.

2.**Basic understanding of data structure** Python's built-in data structures, such as lists, dictionaries, tuples, and sets, are powerful and versatile. 
However, Python's built-in data structures may be perceived as limited compared to other programming languages like Java or C++, which offer a wider range of built-in data structures such as arrays, linked lists, stacks, queues, and trees.
Beginners who want to learn and understand these advanced data structures may need to implement them from scratch or use third-party libraries, which can add complexity to the learning process.The availability of comprehensive educational resources for understanding more advanced data structures and algorithms in Python may vary compared to other languages.

3.**Less Exposure to Low-Level Concepts:**

Python abstracts many low-level details, making it easy for beginners to start coding without understanding some fundamental concepts such as memory management or pointers. While this abstraction is beneficial for beginners initially, it may limit their understanding of how computers work at a lower level.
In languages like C and C++, pointers are fundamental concepts that allow programmers to directly manipulate memory addresses. While Python does not have direct support for pointers, understanding them in languages like C or C++ can provide valuable insights into memory management and data storage.
Pointers facilitate efficient data storage by enabling dynamic memory allocation and manipulation. For example, pointers can be used to create dynamic data structures like linked lists, trees, and graphs, where memory allocation is not predetermined at compile time. Understanding pointers helps beginners grasp how data is stored and accessed in memory, enhancing their comprehension of data structure implementations.

Enter fullscreen mode Exit fullscreen mode

include

int main() {
int x = 10; // integer variable
int *ptr; // pointer to an integer

ptr = &x;     // pointer points to the address of x

printf("Value of x: %d\n", x);     // output: Value of x: 10
printf("Address of x: %p\n", &x);  // output: Address of x: <memory address>
printf("Value of x using pointer: %d\n", *ptr);  // output: Value of x using pointer: 10

return 0;
Enter fullscreen mode Exit fullscreen mode

}

In this example, ptr is a pointer variable that stores the address of the integer variable x. By dereferencing ptr with *ptr, we can access the value stored in x. This example demonstrates how pointers are used to manipulate memory addresses and access data stored in memory.

4.**Transition to Other Languages:**


If beginners plan to transition to languages with different syntax or paradigms later on, starting with Python may lead to challenges in adapting to those languages. Learning a language with a more rigid syntax upfront may provide a stronger foundation for learning other languages in the future.This is the  most common problem faced by people.


 5.**Indentation Sensitivity:**

Python's use of indentation for block structure can be confusing for beginners who are used to languages with explicit block delimiters like braces. While indentation can improve code readability, it may also lead to errors if not used consistently.Other languages use brackets to define blocks,sometime makes less complex to understand.
In Python

Enter fullscreen mode Exit fullscreen mode

for i in range(0,100):
print(i) #this will give indentation error
print(i) #corect output.

In Java

Enter fullscreen mode Exit fullscreen mode

for(int i =0 ;i<100;i++){
//in this block we can write anywhere related to for statement without caring indentation.
}


 6.**Performance Limitations:**

Python is an interpreted language, which generally means it is slower than compiled languages like C++ or Java. While Python's performance is usually sufficient for most applications, it may not be the best choice for performance-critical tasks or projects where speed is crucial.
As you can see from the figure, Java and Python behave differently with the same logic.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1bhcc17ekjhjhewnbbc.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hc76rcwxjn4hiy1ianhy.png)

7.**Reliance on Built-in Functions:**


Python's extensive library of built-in functions and methods for data structures can lead to an overreliance on these functions without understanding the underlying principles.
Beginners may use built-in functions without fully understanding how they operate, hindering their comprehension of data structure algorithms and implementations.
Built-in functions like sort() simplify tasks but understanding their workings is crucial for beginners.

Certainly! Here's a more concise version:

Built-in functions like sort() simplify tasks, but understanding their workings is crucial for beginners.

Example: Using sort() to sort a list:

Enter fullscreen mode Exit fullscreen mode

numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
numbers.sort()
print("Sorted list:", numbers)

Understanding sorting algorithms enhances problem-solving skills.Learning sorting algorithms exposes beginners to key algorithmic concepts.The hands-on practice with sorting algorithms reinforces learning and practical experience.

Python boasts an abundance of built-in functions, unlike other languages such as C++ and Java, which also offer their own sets of built-in functions.

8.**Influence of Python's Ecosystem:**

Python's ecosystem, including popular libraries and frameworks, may influence beginners to prioritise application development and higher-level programming paradigms over understanding low-level data structure concepts.
Beginners may gravitate towards using libraries and frameworks that abstract away data structure implementations, limiting their exposure to underlying data structure principle

In Python, beginners may rely on libraries like Pandas,numpy etc for data manipulation, abstracting away data structure details. In contrast, in Java, beginners are more likely to directly engage with data structure implementations, fostering a deeper understanding of underlying principles.


9.**Limited Exposure to Algorithmic Complexity:**


While Python provides implementations of basic data structures, it may not expose beginners to the complexities of data structure algorithms and their computational efficiency.
Beginners may not fully appreciate concepts like time complexity and space complexity without delving into more advanced data structure and algorithm topics.
In Java, beginners are more likely to encounter explicit implementations of data structures and algorithms compared to Python. Let's illustrate this with a comparison:

Enter fullscreen mode Exit fullscreen mode

Python code for linear search

def linear_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
return -1

Example usage

my_list = [4, 7, 2, 1, 9, 6]
target_element = 9
result = linear_search(my_list, target_element)
if result != -1:
print(f"Element {target_element} found at index {result}.")
else:
print(f"Element {target_element} not found in the list.")

In Java

Enter fullscreen mode Exit fullscreen mode

// Java code for linear search
public class LinearSearch {
public static int linearSearch(int[] arr, int target) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == target) {
return i;
}
}
return -1;
}

public static void main(String[] args) {
    int[] myArray = {4, 7, 2, 1, 9, 6};
    int targetElement = 9;
    int result = linearSearch(myArray, targetElement);
    if (result != -1) {
        System.out.println("Element " + targetElement + " found at index " + result + ".");
    } else {
        System.out.println("Element " + targetElement + " not found in the array.");
    }
}
Enter fullscreen mode Exit fullscreen mode

}

In Python, the linear search algorithm is implemented using a function, abstracting away some details, making it easier for beginners to start coding without worrying about lower-level concepts.

In Java, the linear search is implemented in a class with a main method, requiring beginners to understand classes and methods from the start. Java's explicit approach provides a deeper understanding of core concepts like data structures and algorithms.
10. **Less Emphasis on Performance Optimisation:**


Python's focus on simplicity and readability may lead beginners to prioritize writing clear and concise code over optimizing performance.
Beginners may overlook opportunities for performance optimization in data structure implementations, such as using more efficient algorithms or data structures tailored to specific use cases.

In Python, the focus on simplicity and readability may lead beginners to prioritize writing clear and concise code over optimizing performance. This is exemplified by the following Python code snippet for finding the factorial of a number:

Enter fullscreen mode Exit fullscreen mode

def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)

result = factorial(5)
print(result) # Output: 120

While this Python code is concise and easy to understand, it may not be the most efficient implementation for calculating factorials, especially for large values of n.

On the other hand, in languages like Java, beginners are often introduced to concepts like performance optimization early on. Here's an example of a Java code snippet for calculating the factorial of a number using iteration instead of recursion:

Enter fullscreen mode Exit fullscreen mode

public class Factorial {
public static int factorial(int n) {
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}

public static void main(String[] args) {
    int result = factorial(5);
    System.out.println(result);  // Output: 120
}
Enter fullscreen mode Exit fullscreen mode

}

n this Java code, the factorial is calculated using a simple loop, which can be more efficient for larger values of n compared to the recursive approach used in the Python code.

## Summary

As a newcomer, I initially felt confident in my decision to start with Python, but over time, I encountered challenges that made me reconsider. While Python's simplicity and readability are beneficial, its limited exposure to low-level concepts and performance optimisation may hinder a beginner's understanding. Comparing Python with Java or C++ highlights these drawbacks for beginners.I gave comparision with Java but all these concepts are applicable for C++too.
Although for experience, Python's extensive ecosystem, dynamic typing, and automatic memory management make it versatile and accessible, supporting various applications from web development to data science and machine learning. Despite its limitations, Python will be my favourite language.
Enter fullscreen mode Exit fullscreen mode

Comments 29 total

  • Carla Crija
    Carla CrijaFeb 14, 2024

    Very nice

  • Tom Nijhof
    Tom NijhofFeb 15, 2024

    I would say the lack of datatypes, low level things ect makes Python BETTER for beginners

    Those new to programming need to get started as soon as possible, more roadblocks and points of frustrations will turn people away from programming

    The only point against Python is the fact it is not easy to create a visual result easily beside prints

    • Scott Reno
      Scott RenoFeb 15, 2024

      I agree!

    • krishnaa192
      krishnaa192Feb 17, 2024

      but then we might not understand how actually things work internally.

      • Tom Nijhof
        Tom NijhofFeb 17, 2024

        Is that the point of a FIRST language?
        A first language should be welcoming to newcomers, help them get started, and remove as many roadblocks as possible.
        Once people are comfortable with the basics you can introduce new or deeper subjects

    • Aatmaj
      AatmajFeb 19, 2024

      I agree with @wagenrace

  • Dawid
    DawidFeb 15, 2024

    I started my journey in school with C++, which isn't the easiest language to start with, let's be honest. But this + few months with C on the studies had probably the biggest impact on my developers skills. The way you need to deal with pointers, memory allocation etc. changes the way you're looking at a program and programming itself. Today I don't use low level languages, but the ideas and knowledge related to them are still useful.

  • NotFound404
    NotFound404Feb 15, 2024

    Python was created to replace the more ancient language, The Perl language.
    Perl was created to make unix shell code more powerful and organizable.
    A lot packages which was formerly written in Perl are now written in Python in Unix/Linux system.
    Python is now the infrastructure of Linux shell.
    The indentation sensitive feature derived from languages like BASIC and Fortran is not good for sharing and reading.
    I don't encourage use Python for new projects, I would like use node.js instead. :)
    As for beginners, JavaScript is a more available choice.

    • krishnaa192
      krishnaa192Feb 17, 2024

      Most people are using Nodejs these days.

  • Tyler V. (he/him)
    Tyler V. (he/him)Feb 15, 2024

    I think this advice might be better as a list of things for people to learn about if they started with Python and are looking to either learn more advanced topics or transition to using one of these languages - growing from Beginner to Intermediate level developer type framing.

    My philosophy for getting someone started with development is to start with the path of least resistance - it makes for a more encouraging start instead of running into frustrations about things that really don't matter if you're just getting started with programming.

    • krishnaa192
      krishnaa192Feb 17, 2024

      thanks for mentioning another way of approach.Haha.As a developer also you need to understand a few concepts—some I experienced.

  • Ian Pride
    Ian PrideFeb 16, 2024

    Although I'm not the biggest fan of Python (though I've certainly written my fair share over the last 30+ years) it's certainly a great scripting language for AutoKey in Linux! My point being (and as you have made clear) that it has its useful place. Only thing I hate is the use of indention for blocks...
    Appreciate the article.

  • James 'Dante' Midzi
    James 'Dante' MidziFeb 16, 2024

    I watched an interview with Dr. Chuck and he actually said:

    1. Python
    2. C

    youtu.be/6uqgiFhW0Fs

  • Fatih Kurt
    Fatih KurtFeb 16, 2024

    I absolutely agree, the first language I learned was python and that's why I had adaptation problems when switching to another language, fortunately I overcame this problem when I was still a junior by reading and trying to understand programs written in other languages and other developers' code, I remember it was a bit difficult, I also remember that my friend who wrote php could read my python code while I could not read his php code, so I definitely do not recommend python to someone new

    • krishnaa192
      krishnaa192Feb 17, 2024

      yeah I felt same when I started learning Java .

  • Vivienne Medrano
    Vivienne MedranoFeb 16, 2024

    I totally get what you're saying about Python being popular, especially with its cool libraries for web dev, data science, and AI/ML. But, you've rightly pointed out some quirks, like Python's flexible variable types, which can trip up beginners. Exploring languages like Java or C++ and checking out their setup in a software development team structure might be a good call for a more rounded coding journey.

  • Jima Victor
    Jima Victor Feb 16, 2024

    When I started, I dabbled with c++, and I couldn't understand pointers and the reason for that is probably due to the fact that I didn't need them at that point. If you are a beginner programmer and you begin to notice the downsides of using python as a programming language, it means you've leveled up and it's time to move over to a more complex language.

    Those advanced features in other programming languages gives the programmer more control, and they are appreciated by advanced programmers because they understand the need for them. But for a beginner, those things do not matter to them.

    Python was created to be easy to read and write. And as a beginner, you don't need things in a programming language that are going to make you hate programming.

    Start with python, and when there is a need to use something more complex, you change.

    • krishnaa192
      krishnaa192Feb 17, 2024

      Agree. I just shared my experience.Surely I love Python the most

  • Tom Nijhof
    Tom NijhofFeb 16, 2024

    Why python SHOULD be your first language 🐍

    dev.to/wagenrace/why-should-python...

  • krishnaa192
    krishnaa192Feb 17, 2024

    Yeah, I agree. But we can easily switch from one language to another if we learn the first one properly. In India, colleges still teach C to First-year students. So, if we give a bit of attention to it, we can get away with advanced concepts and learn Python too. My suggestion was for college students as they have plenty time of for 4 years.

  • Xulin Zhou
    Xulin ZhouFeb 20, 2024

    For the 1st problem you addressed, there are some modern libraries to parse types and constraints for functions and classes at runtime such as utype and pydantic

    • krishnaa192
      krishnaa192Feb 20, 2024

      thanks for your information. will see

  • Shrijal Acharya
    Shrijal AcharyaFeb 20, 2024

    @kwnaidoo I Strongly agree with your thought on this one.
    reach++

Add comment