Categories
Community Tips

Debugging Techniques For Python Developers

Debugging is an essential skill for any programmer. Mastering this skill can help you identify problems quickly and effectively in your Python code. Without knowing how to debug code, developers will face endless hours of frustration trying to solve problems.

Fortunately, Python’s built-in tools and debugging techniques make it easy for developers to identify and fix errors without wasting too much time. To help you get the most out of your Python coding experience, this article contains a list of the top debugging techniques for Python developers. But first, you must know the importance of debugging and its practical use cases in the developer community.

The Importance of Debugging

As mentioned, debugging is among the essential Python skills that all developers need to know. A common misconception of debugging is that it’s only necessary for complex projects. In reality, debugging should be part of the development cycle of any project, regardless of its size or complexity. 

This process helps you identify and fix bugs in your code quickly and efficiently. It can also help you better understand the program’s flow of execution, which enables you to make more informed decisions about improvements or modifications to the code. 

Debugging Use Cases

A common mistake of new developers is to assume that debugging is only done to correct errors in code. In reality, debugging is used for more than just fixing errors. Here are some of the most common use cases:

  • Handling Python code errors that occur during program execution. Errors can be caused by incorrect syntax, type errors, name errors, etc. Different types of errors can occur in each code, and good debugging skills can get you out of a jam.
  • Investigating problems with code logic or implementation. This could include issues such as unintended infinite loops or unexpected output from functions. Debugging can help programmers determine the root cause of these issues and identify solutions.
  • Testing code for desired behavior. Debugging can be used to test if the code is working as intended. This could include checking for outcomes from functions, or ensuring that calculations are performed correctly.
  • Locating and removing code that is no longer necessary. As a developer, you should know that code can become obsolete over time. Debugging allows you to identify and remove obsolete or redundant code from your project. This could include dead code, duplicate functions, or redundant variables. 
  • Identifying potential performance issues in your program. Poorly written code can significantly slow the running time of a program. Thus, accurately tracking and diagnosing these problems is essential for efficiency. And yes, debugging can help with that.

Common Debugging Techniques For Python Developers

Now that you understand the importance of debugging and its various use cases, here are some of the most helpful techniques for Python developers:

The “print()” Function

The simplest way to debug a program is by using the print() function. This can be used to debug programs by displaying values in real time. But how, you may ask? This function allows you to print out variables and values to gain insight into what is going on with your program. It also helps you identify errors that appear during the execution of your code. Through this function, you can easily track the program’s flow of execution and identify any potential problems along the way.

Integrated Development Environment (IDE)

An IDE provides a suite of tools to help debug code more effectively. With features such as syntax highlighting, auto-completion, debugging consoles, and breakpoints, it allows you to quickly identify and fix errors without having to search through your code manually.

An IDE is present in almost every programming language, and Python is no exception. Popular IDEs include PyCharm and Visual Studio Code as the go-to choices for many developers. If you have the resources, you can try out different IDEs and find the one that works best for you.

Debugger

A debugger is a powerful tool used to step through code line by line. It can be used to inspect variables, set breakpoints, and trace functions as they execute in real-time. This helps you identify the exact source of an issue quickly and easily.

The Python debugger, known as pdb, comes installed with Python. It allows you to inspect the flow of control in your code. You can also set breakpoints with pdb which allows you to pause at specific points during program execution so that you can investigate what is going on at that time.

Logging

Logging can be used to keep track of errors and detect any unexpected behavior during the program’s runtime. This provides you with a record of events that can be used for further investigation into the cause of an issue. Many seasoned developers use logging as a reliable way to track errors and identify improvement points.

The logging module in Python allows you to create basic loggers that can be used for debugging purposes. This module also includes more advanced features such as custom levels, filtering, and formatting, making it even more powerful!

Conclusion

Debugging is one of the most critical aspects of development that every professional developer should learn. You can quickly identify and solve problems in Python code by learning and mastering the debugging techniques listed above. Remember, debugging is an essential part of the development process, so learning how to use these techniques efficiently will help you become a more productive and successful developer!

Categories
Community

Why Python is the perfect choice for AI & ML project

With most companies using Artificial Intelligence and Machine Learning technology, it’s significant to use a programming language that reduces the code complexity and offers simple implementation. 

Though developers have ample opportunity to use different programming languages, Python gives them an edge over other available languages. Python offers a large number of libraries with simple and flexible tools, which makes the job easier. 

Plus, it is one of the leading solutions that can work for ML and AI. Python has gained an extensive advantage over different programming languages and is being used for different projects. You can hire Python developers to know more about compatibility. 

Let’s dive deep and look into what makes Python an ideal choice. 

1. Huge frameworks and libraries 

Building different ML and AI projects can be time-consuming. And at times, the coding process can be a complex one. However, many libraries are prewritten and compatible with Python, so developers prefer it over other languages. 

The libraries available in the stock make the process seamless for new developers. Developers can pick a library based on the need of the project. For instance, the Pybrain is used for machine learning, and Scipy is specifically used for advanced computing. 

Also, programmers can save a lot of time by using the approach, which is a unique library. 

2. Flexible platform 

Python is a highly flexible platform and is suitable for every purpose. The programming language offers the benefit of choosing between scripting and OOPS. Plus, you can consider recompiling the source code in project development. 

It’s easier to bring any changes, which saves time. Additionally, it allows the developers to choose from different programming styles, following which they can combine various styles to create better projects. 

The language is suitable for linking different data structures and offers perfect backend solutions for programmers. Moreover, it’s the most feasible choice for programmers who are often stuck between different algorithms – providing them with the power to check the code.

3. Its quite popular 

Python is quite popular among the developer community for creating projects. It’s one of the top programming languages, and most developers love to use it for simple stacks and tools. 

Moreover, it is one of the most commonly used languages for new developers. Developers can easily choose from the many Python packages available online. With a wide choice of packages, choosing the one for the project becomes simple. 

Leading companies have been using the language for years, so it’s the most preferred choice for the AI community. It is also the number one choice for developers who work on machine learning projects.

4. Platform-independent nature

Python has a platform-independent nature and that’s why most developers prefer the language. It makes the entire process of building solutions more seamless and simple. 

Developers can work on multiple platforms without errors. By tweaking the codes, they can make the applications ready to run or go live in no time. Additionally, they can run the apps on different OS. 

By choosing Python, developers can save a lot of time they otherwise waste on testing applications. The flexibility of coding is the main feature of Python. 

5. Better visualization options 

As discussed earlier, Python comes with a variety of libraries that are available online, and those libraries come with visualization features and tools. Moreover, when it comes to AI, the developers need to develop visuals for a project. 

They need to highlight the visuals for accuracy and attention. Plus, it plays a vital role in presenting the data. For instance, libraries like Matplotlib can be helpful for programmers and data scientists. 

It allows creating of different charts and histograms and – creating plots for data comprehension. The tools help in visualization and representation, which helps the developers to build better reports. 

6. Clear readability 

With Python, you will get the benefit of readability, which is an important aspect of technology. It is a simple language, easy to use, and beginners can change the code. 

Unlike other programming languages, Python is not complex. Besides, ease of use plays a vital part in exchanging ideas, algorithms, and tools. As a result, AI professionals can use the language to bring minor or big changes to the project at any given time. 

Apart from the readability, there are tools available to create an interactive design. The external tools can help in debugging and tab completion. It can also help in testing. Additionally, it also plays a part in facilitating the work schedule. 

7. Rapid development and community support 

Python offers the benefit of prototyping, and if the developers are familiar with stacks, it saves time. Also, the developers don’t have to waste time in the integration of AI. Most developers consider Python simple as far as readability and writing are concerned. You won’t need to learn the complicated codes. 

Python offers extensive community support – backed by experts and professionals in the field. Additionally, it provides the developers with all the essential resources they need to work on. 

New developers can work quickly and hassle-free. Besides, the experts are always preparing to rescue new developers if they are stuck with the project. In every phase of the development cycle, you can take the help of experts. 

Wrapping up,  

AI and ML technology is constantly evolving and bridging gaps between companies. Implementation and integration can help increase efficiency and productivity. 

Additionally, the use of Python for the two technologies is providing solutions to real-life problems. Plus, you can expect a customised user experience with Python. 

Categories
Tips

11 Tips And Tricks To Write Better Python Code

Here are 11 tips and tricks that will help you write better Python code and become a better programmer:

1. Iterate with enumerate instead or range(len(x))

In Python, we generally use a for loop to iterate over an iterable object. A for loop in Python uses collection based iteration i.e. Python assigns the next item from an iterable to the loop variable on every iteration. The usual usecase of a for loop is as follows:

values = ["a", "b", "c"]

for value in values:
  print(value)

# a
# b
# c

Now, if in addition to the value, you want to print the index as well, you can do it like this:

index = 0

for value in values:
  print(index, value)
  index += 1

# 0 a
# 1 b
# 2 c

or another common way to do this is by using range(len(x)):

for index in range(len(values)):
  value = values[index]
  print(index, value)

# 0 a
# 1 b
# 2 c

However, there is an easier and more pythonic way to iterate over iterable objects by using enumerate(). It is used in a for loop almost the same way as you use the usual way, but instead of putting the iterable object directly after in in the for loop, or putting using it as range(len(values)) , you put it inside the parentheses of enumerate() as shown below:

for count, value in enumerate(values):
  print(count, value)

# 0 a
# 1 b
# 2 c

We can also define a start argument for enumerate() as shown below :

for count, value in enumerate(values, start=1):
  print(count, value)

# 1 a
# 2 b
# 3 c

The enumerate() function gives back two variables:

  • the count of the current iteration
  • the value of the item at the current iteration

Just like the loop variables in a for loop, the loop variables can be named anything, for instance, we can call then index and value and they’ll still work. enumerate() is more efficient than a for loop as it saves you from the hassle to remember to access the value inside the loop and use it correctly and then also remember to advance the value of the loop variable, it is all handled automatically by Python.

2. Use list comprehension instead of raw for loops

List comprehension is an easier and elegant way to define an create lists based on the existing lists. They are just a single line of code consisting of brackets containing the expression that is repeatedly executed at each iteration. Hence, they are more time and space efficient than loops and transform iterative statements in a single line of code.

The usual syntax of a list comprehension looks like this:

newList = [ expression(element) for element in oldList if condition ] 

Here’s an example of list comprehension in code:

# Using list comprehension to iterate through loop
List = [character for character in 'HackerNoon']
 
# Displaying list
print(List)

# Output
# ['H', 'a', 'c', 'k', 'e', 'r', 'N', 'o', 'o', 'n']

3. Sort complex iterables with sorted()

The Python sorted() function sorts the elements of an iterable object in a specific order (ascending or descending) and returns them as a sorted list. It can be used to sort a sequence (string, tuple, list) or collection (set, dictionary, frozen set) or any other iterator.

The syntax of the sorted() function is as follows:

sorted(iterable, key=None, reverse=False)

sorted() function takes at max three parameters:

  • iterable: It could be any iterator
  • key: It is an optional argument that serves as a key for sort comparison.
  • reverse: It is also an optional argument that is used to specify a reversed sorted list as the output

4. Store unique values with Sets

A Python Set stores a single copy of the duplicate values into it. Hence, it can be used to check for unique values in a list. For example:

list_inp = [100, 75, 100, 20, 75, 12, 75, 25] 

set_res = set(list_inp) 
print("The unique elements of the input list using set():\n") 
list_res = (list(set_res))
 
for item in list_res: 
    print(item)

So the output of the above program would look like this:

The unique elements of the input list using set():

25
75
100
20
12

5. Save memory with Generators

The basic function of the generator is to evaluate the elements on demand. It is very similar to the syntax for list comprehension, where instead of square brackets, we use parentheses.

Let’s consider an example where we want to print the square of all the even numbers in a list:

myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print("The given list is:", myList)
mygen = (element ** 2 for element in myList if element % 2 == 0)
print("Elements obtained from the generator are:")
for ele in mygen:
    print(ele)

The output of the above code would look like this:

The given list is: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Elements obtained from the generator are:
4
16
36
64
100

Having said that their syntax is quite similar to list comprehension, you must be wondering how it is different from list or set comprehension. Unlike list or set comprehension, generator comprehension does not initialize any objects. As a result, you may utilize generator comprehension instead of list or set comprehension to lower the program’s memory requirements.

6. Define default values in Dictionaries with .get() and .setdefault()

.setdefault() method allows to set dict[key]=default if key is not already in dict.

The syntax of .setdefault() looks like following:

dict.setdefault(key, default=None)

Here’s an example code snippet to understand how to use .setdefault():

a_dictionary = {"a": 1, "b": 2, "d": 4}
a_dictionary.setdefault("c", 3)

print(a_dictionary)

The output of the above code would look like:

{'a': 1, 'b': 2, 'd': 4, 'c': 3}

The same thing can also be achieved by using .get() method by passing a default value for the key, as you can see below:

a_dictionary = {"a": 1, "b": 2, "d": 4}
print(a_dictionary.get("c", 3))

print(a_dictionary)

The output of the above code would look like following:

3
{'a': 1, 'b': 2, 'd': 4}

7. Count hashable objects with collections.Counter

The Collections module supports high-performance container datatypes (in addition to the built-in types list, dict, and tuple) and contains a variety of useful data structures for storing information in memory.

A counter is a container that keeps track of the number of times equal values are added.

It may be used to implement the same algorithms that other languages employ bag or multiset data structures to implement.

Import collections makes the stuff in collections available as:

import collections

Since we are only going to use the Counter, we can simply do this:

from collections import Counter

It can be used as follows:

import collections

c = collections.Counter('abcdaab')

for letter in 'abcde':
    print '%s : %d' % (letter, c[letter])

The output of the above code would look like this:

a : 3
b : 2
c : 1
d : 1
e : 0

8. Format strings with f-Strings (Python 3.6+)

f-strings, also called as “formatted string literals“, are a new and more pythonic way to format strings, supported by Python 3.6+. They are a faster, more readable, more concise, and a less error prone way of string formatting in Python.

As the name “f-string” says, they are string literals that have an f at the beginning and curly braces containing expressions that will be replaced with their values at the runtime and then formatted using the __format__ protocol.

f-strings can be used as following:

name = "Eric"
age = 74
print(f"Hello, {name}. You are {age}.")

# 'Hello, Eric. You are 74.'

9. Concatenate strings with .join()

In Python, we can use the .join() method to concatenate a list of strings into a single string. The usual syntax for this method looks like below:

'String to insert'.join([List of strings])

It can be used in multiple ways — if you use the empty string ““, [List of strings] is simply concatenated, and if you use a comma, a comma-delimited string is created. When the newline character \n is used, a newline is appended after each string. See the example below:

l = ['aaa', 'bbb', 'ccc']

s = ''.join(l)
print(s)
# aaabbbccc

s = ','.join(l)
print(s)
# aaa,bbb,ccc

s = '-'.join(l)
print(s)
# aaa-bbb-ccc

s = '\n'.join(l)
print(s)
# aaa
# bbb
# ccc

10. Merge dictionaries with {**d1, **d2} (Python 3.5+)

The easiest way to merge dictionaries is by using the unpacking operator (**). The syntax for this method looks like this:

{**dict1, **dict2, **dict3}

Here’s an example to understand this method better:

d1 = {'k1': 1, 'k2': 2}
d2 = {'k3': 3, 'k4': 4}

print({**d1, **d2})
# {'k1': 1, 'k2': 2, 'k3': 3, 'k4': 4}

11. Simplify if-statements with if x in list

Assume we have a list with the primary colours red, green, and blue. And somewhere in our code, we have a new variable with a colour, so c = red. Then we’ll see if this is one of our primary colours. Of course, we might check this against each item on our list as follows:

colors = ["red", "green", "blue"]

c = "red"

# cumbersome and error-prone
if c == "red" or c == "green" or c == "blue":
    print("is main color")

However, this may become quite time consuming, and we can easily make mistakes, such as if we have a typo here for red. It is more simpler and far preferable to just use the expression if x in list:

colors = ["red", "green", "blue"]

c = "red"

# better:
if c in colors:
    print("is main color")

Conclusion

Python is a widely used programming language and by using the above tips and tricks, you can become a better Python programmer.

I hope this article was helpful. Keep reading!

Categories
Analysis

Infographic: Programming languages adoption trends 2021

In our last infographic, JavaScript was the most popular programming language. What has changed in terms of the sizes in the last six months? You can find the answers in this infographic with key findings from our Developer Economics 20th edition survey, which ran between November 2020 and February 2021 and reached 19,000 developers worldwide.

Javascript is the queen of programming languages

JavaScript is the most popular programming language by some distance, with nearly 14M developers using it globally. More importantly, the JavaScript community has been growing in size consistently for the past three years. Between Q4 2017 and Q1 2021, more than 4.5M developers joined the community – the highest growth in absolute terms across all languages. Even in software sectors where JavaScript is not among developers’ top choices, like data science or embedded development, about a fourth of developers use it in their projects.

Python is conquering the world

Since it surpassed Java in popularity at the beginning of 2020, Python has remained the second most widely adopted language behind JavaScript. Python now counts just over 10M users, after adding 1.6M net new developers in the past year alone. That’s a 20% growth rate, the highest across all the large programming language communities of more than 6M users. The rise of data science and machine learning (ML) is a clear factor in Python’s popularity. Close to 70% of ML developers and data scientists report using Python. For perspective, only 17% use R, the other language often associated with data science.

Kotlin’s rise continues

The fastest growing language community in percentage terms is Kotlin. In fact, it’s one of the two communities – the other being Rust – that has grown more than two-fold over the last three years, from 1.1M developers in Q4 2017 to 2.6M in Q1 2021. This is also very

evident from Kotlin’s ranking, where it moved from 11th to eight place during that period – a trend that’s largely attributed to Google’s decision to make Kotlin its preferred language for Android development. Even so, Kotlin still has a long way to go to catch up with the leading language in mobile development, Java; there are currently twice as many mobile developers building applications in Java than in Kotlin.

Swift was recently outranked by Kotlin, after attracting slightly fewer net new developers in the second half of 2020 (100K vs 300K). Even so, Swift is currently the default language for development across all Apple platforms, which has led to a stagnation in the adoption of Objective C. This gradual phase-out of Objective C from the Apple app ecosystem is also matched by a significant drop in its rank, from ninth to 12th place. 

The more niche languages – Go, Ruby, Rust, and Lua – are still much smaller, with up to 2.1M active software developers each. Go and Ruby are important languages in backend development, but Go has grown slightly faster in the past year, both in absolute and percentage terms. Rust has formed a very strong community of developers who care about performance, memory safety, and security. As a result, it grew faster than any other language in the last 12 months, more than doubling in size. Finally, Lua was also among the fastest growing language communities in the last year, mainly attracting AR/VR and IoT developers looking for a scripting alternative to low-level languages such as C and C++.

Sign up to our community to have your say in our next developer survey.

Infographic: Programming languages adoption trends 2021
Categories
Languages

Infographic: Programming languages adoption trends 2020

Languages are a beloved subject of debate and the kernels of some of the strongest developer communities. The choice of programming language matters deeply to developers because they want to keep their skills up to date and marketable. They matter to toolmakers too, because they want to make sure they provide the most useful SDKs. So which programming languages had notable changes in adoption trends in the last 3 years? Find the answers in our infographic with key findings from our Developer Economics 19th edition survey, which ran in June-August 2020 and reached 17,000 developers in 159 countries. 

JavaScript is the most popular programming language

As of Q3 2020, 12.4M developers globally were using JavaScript. We also estimate that in mid-2020 there were 21.3M active software developers in the world. So, 58% of all developers use JavaScript. Notably, the JavaScript community has been growing in size consistently for the past three years. Between Q2 2017 and Q3 2020, nearly 5M developers joined the community – by far the highest growth in absolute terms across all languages. Even in software sectors where JavaScript is least popular, like data science or AR/VR, over a fifth of developers use it in their projects. 

It’s a good idea to learn Python

For the second half-year period in a row, Python is the most widely adopted language behind JavaScript. Python now counts 9M users, after adding 2.2M net new developers in the past year alone, outranking Java at the beginning of 2020. The rise of data science and machine learning (ML) is a clear factor in its popularity. An impressive 77% of ML developers and data scientists currently use Python. For perspective, only 22% use R, the other language often associated with data science.

What’s new with Java and other well- established programming languages?

Java, with over 8M active users worldwide, is the cornerstone of the mobile app ecosystem – Android – as well as one of the most important general-purpose languages. It’s adoption may have remained stable in the past six months but, in the overall picture, the Java community has gained 1.6M developers since mid-2017, which corresponds to a 24% growth.

The group of major, well-established languages is completed with C/C++ (6.3M), PHP (6.1M) and C# (6M). The fact that C# lost three places in the ranking of language communities during the last three years is mostly explained by its slower growth compared to C/C++ and PHP. C and C++ remain core languages in IoT projects (for both on-device and application-level coding), whereas PHP is still the second most commonly used language in web applications, after JavaScript. On the other hand, C# may be sustaining its dominance in the game and AR/VR developer ecosystems, but it seems to be losing its edge in desktop development – possibly due to the emergence of cross-platform tools based on web technologies.

Android developers behind Kotlin growth

Kotlin is one of the fastest growing language communities, having increased more than two-fold in size since the end of 2017, from 1.1M in Q4 2017 to 2.3M in Q3 2020. This is also very evident from Kotlin’s ranking, where it moved from 11th to ninth place during that period – a trend that’s largely attributed to Google’s decision to make Kotlin its preferred language for Android development. 

Swift surpassed Kotlin in popularity this year, after attracting slightly more net new developers in the first half of 2020 (400k vs 300k). Since Swift became the default language for development across all Apple platforms, the adoption of Objective C has been decreasing steadily. This phase-out from the Apple app ecosystem is also matched by a significant drop in the rank of Objective C, from ninth to 12th place. 

Finally, the more niche languages – Go, Ruby, Rust, and Lua – are still much smaller, with up to 1.5M active software developers each. Ruby and Lua have been around for more than two decades now, but their communities have essentially stopped growing in the last three years. On the contrary, Go and Rust appear to be actively adding developers, although it is still unclear whether the two languages will climb the programming language ranking in the coming period.

What’s your favourite programming language? Take our Developer Economics 20th edition survey to support your choice!

Infographic: Programming languages adoption trends 2020
Categories
Languages

The Queen of Programming Languages with 11M+ Users

The choice of programming language matters deeply to developers because they want to keep their skills up to date and marketable. Programming Languages are a beloved subject of debate and the kernels of some of the strongest developer communities. They matter to toolmakers too, as they want to make sure they provide the most useful SDKs.

Here is an update on Programming Language Communities, from our State of the Developer Nation Report 17th Edition.

It can be hard to assess how widely used a programming language is. The indices available from players like Tiobe, Redmonk, Stack Overflow’s yearly survey, or Github’s Octoverse are great, but mostly offer only relative comparisons between languages, providing no sense of the absolute size of each community. They may also be biased geographically, or skewed towards certain fields of software development, or open source developers.

The estimates we present here look at active software developers using each programming language, across the globe and across all kinds of programmers.

They are based on two pieces of data:

First, our independent estimate of the global number of software developers, which we published for the first time in 2017. We estimate that in mid 2019 there are 18 million active software developers in the world.

Second, our large-scale, low-bias surveys which reach tens of thousands of developers every six months. In the surveys, we consistently ask developers about their use of programming languages across ten areas of development, giving us rich and reliable information about who uses each language and in which context.

JAVASCRIPT REMAINS QUEEN OF PROGRAMMING LANGUAGES

11M+ developers use Javascript

The most popular programming language by a wide margin is Javascript, including derivatives like TypeScript and CoffeeScript. The Javascript community counts over 11 million active developers. Even in software sectors where Javascript is least popular like machine learning or on-device code in IoT, over a fifth of developers use it for their projects. 

Programming language communities Q2 2019
Programming language communities Q2 2019

The rise of machine learning is a clear factor in the success of Python:

8 in 10 machine learning developers use Python in their work (compared to just 25% using R, the other language often associated with data science). Java, of course, is a cornerstone of the mobile app ecosystem (Android) as well as a great general-purpose language.

Language use is not static: developers drop and adopt new languages all the time

It would appear that it is not meaningful to speak of “Java developers” or “Python developers” in any fundamental sense, other than that they use those languages at a certain point in time. While we see a net decline in the use of most languages by our repeat respondents, some languages reverse that trend and show significant growth. The first of these is Kotlin, which we are confident to say is the rising star in the programming language firmament.

Kotlin’s rank among programming languages moved from 11th to 8th place in just a year, and one in ten developers now use the language.

Rank of programming language communities 2017-2019
Rank of programming language communities 2017-2019

Tracking the ever-changing landscape of the software development ecosystem is why we run our Developer Economics surveys twice a year and there is one live right now. To track changes on programming languages, tools and platforms we need you to share with us your coding experiences!  We would be very interested to know what programming languages, hardware, frameworks and platforms you use, and the types of projects you’re working on.

Has the new Oculus Quest piqued your interest and restarted the heart of VR development? Or is AR and mixed reality where it really is? Help us tell the technology leaders what you think, and by doing so become part of the change you want to see in the tools you use.

Categories
Languages

JavaScript remains the Queen of Programming Languages

Welcome to another update on programming languages communities. The choice of programming language matters deeply to developers because they want to keep their skills up to date and marketable. Languages are a beloved subject of debate and the kernels of some of the strongest developer communities. They matter to toolmakers too, as they want to make sure they provide the most useful SDΚs.

languages_graph

 

It can be hard to assess how widely used a programming language is. The indices available from players like Tiobe, Redmonk, Stack Overflow’s yearly survey, or Github’s Octoverse are great, but mostly offer only relative comparisons between languages, providing no sense of the absolute size of each community. They may also be biased geographically, or skewed towards certain fields of software development, or open source developers.

The estimates we present here look at active software developers using each programming language, across the globe and across all kinds of programmers. They are based on two pieces of data. First, our independent estimate of the global number of software developers, which we published for the first time in 2017. Second, our large-scale, low-bias surveys which reach more than 20,000 developers every six months. In the survey, we consistently ask developers about their use of programming languages across nine areas of development1, giving us rich and reliable information about who uses each language and in which context.

JavaScript is and remains the queen of programming languages. Its community of 11.7M developers is the largest of all languages. In 2018, 2.5M developers joined the community: the highest growth in absolute numbers and more than the entire population of Swift, Ruby, or Kotlin developers, amongst others. New developers see it as an attractive entry-level language, but also existing developers are adding it to their skillset. Even in software sectors where Javascript is least popular like machine learning or on-device code in IoT, over a quarter of developers use it for their projects.

Python has reached 8.2M active developers and has now surpassed Java in terms of popularity. It is the second-fastest growing language community in absolute terms with 2.2M net new Python developers in 2018. The rise of machine learning is a clear factor in its popularity. A whopping 69% of machine learning developers and data scientists now use Python (compared to 24% of them using R).

Java (7.6M active developers), C# (6.7M), and C/C++ (6.3M) are fairly close together in terms of community size and are certainly well-established languages. However, all three are now growing at a slower rate than the general developer population. While they are not exactly stagnating, they are no longer the first languages that (new) developers look to.

Java is very popular in the mobile ecosystem and its offshoots (Android), but not for IoT devices. C# is a core part of the Microsoft ecosystem. Throughout our research, we see a consistent correlation between the use of C# and the use of Microsoft developer products. It’s no surprise to see desktop and AR/VR (Hololens) as areas where C# is popular. C/C++ is a core language family for game engines and in IoT, where performance and low-level access matter (AR/VR exists on the boundary between games and IoT).

PHP is now the second most popular language for web development and the fifth most popular language overall, with 5.9M developers. Like Python, it’s growing significantly faster than the overall developer population, having added 32% more developers to its ranks in 2018. Despite having (arguably) a somewhat bad reputation, the fact that PHP is easy to learn and widely deployed still propels it forward as a major language for the modern Internet.

The fastest growing language community in percentage terms is Kotlin. It grew by 58% in 2018 from 1.1M to 1.7M developers. Since Google has made Kotlin a first-class language for Android development, we can expect this growth to continue, in a similar way to how Swift overtook Objective-C for iOS development.

Other niche languages don’t seem to be adding many developers, if any. Swift and Objective-C are important languages to the Apple community, but are stable in terms of the number of developers that use them. Ruby and Lua are not growing their communities quickly either.

Older and more popular programming languages have vocal critics, while new, exciting languages often have enthusiastic supporters. This data would suggest that it’s not easy for new languages to grow beyond their niche and become the next big thing. What does this mean for the future of these languages and others like Go or Scala? We will certainly keep tracking this evolution and plan to keep you informed.

The Developer Economics survey is now Live.
Have your say in which should be the next programming language Queen and you may win amazing prizes and gear. Discover more.

Want more developer insights on programming languages?

The State of Developer Nation report is free to download.

programming_languages_banner

Categories
Languages

What is the best programming language for Machine Learning?

Q&A sites and data science forums are buzzing with the same questions over and over again: I’m new in data science, what language should I learn? What’s the best machine learning language?

machine-learning-programming-language

There’s an abundance of articles attempting to answer these questions, either based on personal experience or on job offer data. Τhere’s so much more activity in machine learning than job offers in the West can describe, however, and peer opinions are of course very valuable but often conflicting and as such may confuse the novices. We turned instead to our hard data from 2,000+ data scientists and machine learning developers who responded to our latest survey about which languages they use and what projects they’re working on – along with many other interesting things about their machine learning activities and training. Then, being data scientists ourselves, we couldn’t help but run a few models to see which are the most important factors that are correlated to language selection. We compared the top-5 languages and the results prove that there is no simple answer to the “which language?” question. It depends on what you’re trying to build, what your background is and why you got involved in machine learning in the first place.

Which machine learning language is the most popular overall?

First, let’s look at the overall popularity of machine learning languages. Python leads the pack, with 57% of data scientists and machine learning developers using it and 33% prioritising it for development. Little wonder, given all the evolution in the deep learning Python frameworks over the past 2 years, including the release of TensorFlow and a wide selection of other libraries. Python is often compared to R, but they are nowhere near comparable in terms of popularity: R comes fourth in overall usage (31%) and fifth in prioritisation (5%). R is in fact the language with the lowest prioritisation-to-usage ratio among the five, with only 17% of developers who use it prioritising it. This means that in most cases R is a complementary language, not a first choice. The same ratio for Python is at 58%, the highest by far among the five languages, a clear indication that the usage trends of Python are the exact opposite to those of R. Not only is Python the most widely used language, it is also the primary choice for the majority of its users. C/C++ is a distant second to Python, both in usage (44%) and prioritisation (19%). Java follows C/C++ very closely, while JavaScript comes fifth in usage, although with a slightly better prioritisation performance than R (7%). We asked our respondents about other languages used in machine learning, including the usual suspects of Julia, Scala, Ruby, Octave, MATLAB and SAS, but they all fall below the 5% mark of prioritisation and below 26% of usage. We therefore focused our attention on the top-5 languages.

Python is prioritised in applications where Java is not.

Our data reveals that the most decisive factor when selecting a language for machine learning is the type of project you’ll be working on – your application area. In our survey we asked developers about 17 different application areas while also providing our respondents with the opportunity to tell us that they’re still exploring options, not actively working on any area. Here we present the top and bottom three areas per language: the ones where developers prioritise each language the most and the least.

Machine learning scientists working on sentiment analysis prioritise Python (44%) and R (11%) more and JavaScript (2%) and Java (15%) less than developers working on other areas. In contrast, Java is prioritised more by those working on network security / cyber attacks and fraud detection, the two areas where Python is the least prioritised. Network security and fraud detection algorithms are built or consumed mostly in large organisations – and especially in financial institutions – where Java is a favourite of most internal development teams. In areas that are less enterprise-focused, such as natural language processing (NLP) and sentiment analysis, developers opt for Python which offers an easier and faster way to build highly performing algorithms, due to the extensive collection of specialised libraries that come with it.

Artificial Intelligence (AI) in games (29%) and robot locomotion (27%) are the two areas where C/C++ is favoured the most, given the level of control, high performance and efficiency required. Here a lower level programming language such as C/C++ that comes with highly sophisticated AI libraries is a natural choice, while R, designed for statistical analysis and visualisations, is deemed mostly irrelevant. AI in games (3%) and robot locomotion(1%)  are the two areas where R is prioritised the least, followed by speech recognition where the case is similar.

Other than in sentiment analysis, R is also relatively highly prioritised – as compared to other application areas – in bioengineering and bioinformatics (11%), an area where both Java and JavaScript are not favoured. Given the long-standing use of R in biomedical statistics, both inside and outside academia, it’s no surprise that it’s one of the areas where it’s used the most. Finally, our data shows that developers new to data science and machine learning who are still exploring options prioritise JavaScript more than others (11%) and Java less than others (13%). These are in many cases developers who are experimenting with machine learning through the use of a 3rd-party machine learning API in a web application.

machine-learning-programming-languages

Professional background is pivotal in selecting a machine learning language.

Second to the application area, the professional background is also pivotal in selecting a machine learning language: the developers prioritising  the top-five languages more than others come from five different backgrounds. Python is prioritised the most by those for whom data science is the first profession or field of study (38%). This indicates that Python has by now become an integral part of data science – it has evolved into the native language of data scientists. The same can not be said for R, which is mostly prioritised by data analysts and statisticians (14%), as the language was initially created for them, replacing S.

Front-end web developers extend their use of JavaScript to machine learning, 16% prioritising it for that purpose, while staying clear of the cumbersome C/C++ (8%). At the exact opposite stand embedded computing hardware / electronics engineers who go for C/C++ more than others, while avoiding JavaScript, Java and R more than others. Given their investment in mastering C/C++ in their engineering life, it would make no sense to settle for a language that would compromise their level of control over their application. Embedded computing hardware engineers are also the most likely to be working on near-the-hardware machine learning projects, such as IoT edge analytics projects, where hardware may force their language selection. Our data confirms that their involvement is significantly above average in industrial maintenance, image classification and robot locomotion projects among others.

For Java, it’s the front-end desktop application developers who prioritise it more than others (21%), which is also inline with its use mostly in enterprise-focused applications as noted earlier. Enterprise developers tend to use Java in all projects, including machine learning. The company directive in this case is also evident from the third factor that is strongly correlated to language prioritisation – the reason to get into machine learning. Java is prioritised the most (27%) by developers who got into machine learning because their boss or company asked them to. It is the least preferred (14%) by those who got into the field just because they were curious to see what all the fuss was about – Java is not a language that you normally learn just for fun! It is Python that the curious prioritise more than others (38%), another indication that Python is recognised as the main language that one needs to experiment with to find out what machine learning is all about.

It seems that some universities teaching data science courses still need to catch up with this notion though. Developers who say that they got into machine learning because data science is/was part of their university degree are the least likely to prioritise Python (26%) and the most likely to prioritise R (7%) as compared to others. There is evidently still a favourable bias towards R within statistics circles in academia – where it was born – but as data science and machine learning gravitate more towards computing, the trend is fading away. Those with university training in data science may favour it more than others, but in absolute terms it’s still only a small fraction of that group too that will go for R first.

C/C++ is prioritised more by those who want to enhance their existing apps/projects with machine learning (20%) and less by those who hope to build new highly competitive apps based on machine learning (14%). This pattern points again to C/C++ being mostly used in engineering projects and IoT or AR/VR apps, most likely already written in C/C++, to which ML-supported functionality is being added. When building a new app from scratch – especially one using NLP for chatbots – there’s no particular reason to use C/C++, while there are plenty of reasons to opt for languages that offer highly-specialised libraries, such as Python. These languages can more quickly and easily yield highly-performing algorithms that may offer a competitive advantage in new ML-centric apps.

Finally, contractors who got into machine learning to increase their chances of securing highly-profitable projects prioritise JavaScript more than others (8%). These are probably JavaScript developers building web applications to which they are adding a machine learning API. An example would be visualising the results of a machine learning algorithm on a web-based dashboard.

There is no such thing as a ‘best language for machine learning’.

Our data shows that popularity is not a good yardstick to use when selecting a programming language for machine learning and data science. There is no such thing as a ‘best language for machine learning’ and it all depends on what you want to build, where you’re coming from and why you got involved in machine learning. In most cases developers port the language they were already using into machine learning, especially if they are to use it in projects adjacent to their previous work – such as engineering projects for C/C++ developers or web visualisations for JavaScript developers.

If your first ever contact with programming is through machine learning, then your peers in our survey point to Python as the best option, given its wealth of libraries and ease of use. If, on the other hand, you’re dreaming of a job in an enterprise environment, be prepared to use Java. Whatever the case, these are exciting times for machine learning and the journey is guaranteed to be a mind-blowing one, irrespective of the language you opt for. Enjoy the ride!