online store
top of page

Good vs. Great Python Developers: What Sets Them Apart

  • Writer: Alex
    Alex
  • Aug 26
  • 3 min read

A key difference between an amateur and a professional is "production readiness". Many amateur artists and developers create incredible art and technology, but their work is often unusable for real productions because they care less about optimization and usability. While an unoptimized asset or code may look impressive, the production will suffer over time due to slow renderings, constant fixes, and modifications.



The first goal when learning Python is always a working application that delivers on its promise. In the beginning our main focus is on creating working code that fulfills its intended function. The second goal is optimized code that is short, to the point, and easy to understand. At the same time, it’s important to develop good coding habits and practices so that we’re ready to use our applications in a production.


Once we have achieved our first goal, it is wise to review the results and consider how we can improve. For example,


  • Can we reduce two loops into one?

  • Do we need this many if statements or functions to get the job done?

  • Is there a better way to solve the problem?


This doesn't mean we should cram as much code as possible into one line, as that doesn't help readability. Rather, we should write code that is both easy to read and effective. This takes time, but the earlier we start, the faster our code will work professionally and help us and our production.


A famous proverb is:

“Detours expand your knowledge of the surroundings.”

The more we try and explore, the more mistakes we make, and the more we understand Python. This will help us make better decisions in the future. Therefore, spending time on it after completing it is an investment in our future selves.


3 different students solve the same Python assignment differently
3 different students solve the same assignment differently

Another way to learn about better solutions is to learn from others. How did your cohort buddy or colleague solve this task? Looking at others' solutions can help us expand our perspective and find new solutions. So, don't hesitate to look up how others solved the same issue - just wait until you’ve a proper solution yourself. Finally, let's review one of last week's assignments and see how we can improve it. The assignment was:


Write a function that waits for one argument and removes the last part after the last underscore. Find a good name for the function and argument. The name can have zero or multiple underscores. Rename the variable and print it outside the function.


As an example, we use the variable "asset = 'sulley_001'"



Draft

First, let's look at how our initial solution could be implemented. Remember, our primary goal is to complete the task, so this is a valid initial draft.


# 9 lines. Draft
def remove_end_part(asset):
    split_name = asset.split('_')

    if len(split_name) > 1:
        split_name.pop(-1)
        new_name = '_'.join(split_name)
        return new_name
    else:
        return asset
    

asset = 'sulley_001'
result = remove_end_part(asset)
print(result)


Optimized

The difference between the draft and the optimized version might seem minimal (only saving 33% of code) but over time it will add up to a significant number and difference.


  1. better naming ("remove postfix")

  2. clearer English expressions ("if underscore in asset")

  3. remove redundants (one return)

  4. slight performance (later split)

  5. combine steps (join & splice list)

# 6 lines. Optimized
def remove_postfix(asset):
    if "_" in asset:
        asset_split = asset.split('_')
        asset = '_'.join(asset_split[:-1])
    
    return asset
    

asset = 'sulley_001'
result = remove_postfix(asset)
print(result)

Although there are multiple ways to solve a problem, the key in Python is to write the best delivering, fastest, and most readable solution, which takes time. So, start practicing, draw inspiration from others, and don't be afraid of failure.



See you at our next Python cohort,

Alex

Comments


Commenting on this post isn't available anymore. Contact the site owner for more info.
bottom of page