Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Author Posts - Languages

3 Articles
article-image-clean-coding-in-python-with-mariano-anaya
Expert Network
27 Jul 2021
7 min read
Save for later

Clean Coding in Python with Mariano Anaya

Expert Network
27 Jul 2021
7 min read
Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we want our project to successfully deliver features constantly at a steady and predictable pace, then having a good and maintainable code base is a must. The true nature of clean code rely on the fact that other practitioners should be able to read and maintain the code. Read the book Clean Code in Python, Second Edition, to know all about idiomatic Python, see the difference between good and bad code, and identify traits of good code and good architecture. There is no sole or strict definition of clean code. Moreover, there is probably no way of formally measuring clean code, so you cannot run a tool on a repository that will tell you how good, bad, or maintainable that code is. Sure, you can run tools such as checkers, linters, static analyzers, and so on, and those tools are of much help. They are necessary, but not sufficient. Clean code is not something a machine or script can recognize (so far) but rather something that professionals can decide. We interviewed Python expert, and bestselling author, Mariano Anaya on clean coding, importance of efficient code formatting and his recent book, Clean Code in Python, 2nd Edition. The interview in detail: To what extent can the inability to write efficient code harm/affect an organization/software?  In my experience, inefficient code can be so dangerous as to paralyze entire projects. I’ve seen services that needed to be re-written because of how unmaintainable they were. At some point, it became impossible to keep on making changes to that API, and the issues kept piling up, so it needed to be replaced by a brand-new system.  On another occasion, there was an application we knew had problems because of the way it was written, and its instability was causing frustration in customers, which permeated into the company. The buggy nature of the application wasn’t separate from the way it was written, rather it was the consequence. Customers were complaining about quality, and this shows up to which degree technical debt can harm an organization. I’ve seen this pattern several times, when the company must make the hard decision of stopping the release of new features to fix errors in the software.  I’d say that technical debt, if left untreated, can lead to very harmful results for a company.  2. What should developers keep in mind while starting out with legacy systems?  First to identify the degree of technical debt accrued. There are good software projects that have been designed correctly and their technical debt is relatively low (perhaps it’s just about updating some libraries to newer versions or moving parts of the code towards new features that weren’t available at the time it was originally written).  In the event of having a lot of technical debt, it’s important to understand what’s the most critical part that needs to be fixed. There’s certainly a part in the code, a module, or a functionality that’s responsible for most of the complaints from customers, and that’s what needs to be refactored more urgently.  It’s critical in this sense to do a proper analysis and have a plan about the improvements to make in the code, rather than jump straight to the code and start refactoring. This will help give a clearer idea of what needs to be changed, and the degree of the refactor needed. Meaning, if we’ll be fixing the code, or the situation requires a full rewrite. Generally, completely rewritten the application should be a last-resort kind of decision, although there are some obvious cases (for example, if the application was written with Python 2, then it’s clear that all the code will need to be changed).  3. What are the future advancements that you anticipate in Python?  It’s hard to know for sure what will happen with Python in years to come, but it’s interesting to see that in a similar way Python took inspiration and features from other languages, it’s now inspiring modern languages as well, but it also catches up with new features and programming models. Such was the case of all the improvements made for asynchronous programming, incorporated into the standard library.  I believe the asynchronous programming capabilities will continue to be enhanced in future releases.  I have also noticed some improvements towards trying to make Python more efficient, whether this means having a more lightweight interpreter by reducing the number of packages in the standard library, to try to solve the GIL problem. These are the kind of improvements I’m more hopeful to see.  4. What are some of the popular myths around writing clean code?   Perhaps the most common misconception is that clean code is about formatting code, or maybe even about PEP-8. In fact, relating technical debt only to code issues is another popular myth. Technical debt, is also about technology, being caught up with dependencies.  Being able to update your dependencies quickly in case there’s a security issue, it’s also a concern related to technical debt, and therefore to clean code. Things like the speed of iteration, how fast and frequently deployments can be made, the adaptability of the architecture, play an important role in the success of the project.  5. Tell us about your book, Clean Code in Python, Second Edition. What trajectory does your book follow to help its readers develop maintainable and efficient code?  The first chapter starts with an introduction to the importance of having a well-structured code base, presenting a framework for the chapters to come. This is supported by tools, and recommendations on how to setup a project for success, considering automated tools that will help us format the code, and setting up a pipeline to effectively deploy our code with good quality gates (controls, tests, different stages).  Then, the book introduces some Python-specific concepts, making strong emphasis on the particularities of Python’s syntax, and a more succinct way of writing code, taking advantage of the features the language has to offer.  There are some chapters that revisit general design ideas from software engineering, like object-oriented design and design patterns. From that point, the chapter will explore topics of software engineering in terms of how they can be implemented in Python, using the particularities of the language itself.  The idea of the book is to provide readers with the tools and concepts for them to understand what clean code means beyond any definitions given. It’s a pragmatic book; oriented towards a practitioner’s audience, so it makes special focus on how to get things done in an effective way, which often means accepting tradeoffs.  6. Does your book provide hands-on scenarios to practice the techniques it teaches? Absolutely! The book has a very pragmatic, hands-on approach. As each idea is introduced, it’s followed by examples that demonstrate how that implementation would work. Moreover, I’ve put special effort into making the examples as realistic as possible. Considering that the examples need to showcase an idea irrespective of superfluous details (that is, leaving out everything that’s not relevant to the explanation being made, and isolating the problem at hand), they’re still real-world scenarios, pieces of code any reader can relate to their daily job. There’re no made-up examples like Fibonacci-series or things anyone wouldn’t normally find on real code. Extrapolating from the examples, readers can use the code as reference to solve their problems.  To practice more, there’s a Github repository where all the code from the book lies, and it’s constantly updated. There’s also a Docker image for the entire setup of the book, with the environment already configured, that readers can use to test the code, and learn by modifying it.  About Mariano Anaya is a software engineer who spends most of his time creating software with Python and mentoring fellow programmers. Mariano's main areas of interests besides Python are software architecture, functional programming, distributed systems, and speaking at conferences. He was a speaker at Euro Python 2016 and 2017. To know more about him, you can refer to his GitHub account with the username rmariano. His speakerdeck username is rmariano.
Read more
  • 0
  • 0
  • 9377

article-image-listen-how-activestate-is-tackling-dependency-hell-by-providing-enterprise-level-support-for-open-source-programming-languages-podcast
Richard Gall
08 Oct 2019
2 min read
Save for later

Listen: How ActiveState is tackling "dependency hell" by providing enterprise-level support for open source programming languages [Podcast]

Richard Gall
08 Oct 2019
2 min read
"Open source back in the late nineties - and even throughout the 2000s - was really hard to use," ActiveState CEO Bart Copeland says. "Our job," he continues, "was to make it much easier for developers to use open source and much easier for enterprises to use open source." How does ActiveState work? But how does ActiveState actually do this? Copeland explains: "ActiveState is exactly like Red Hat. So what Red Hat did to Linux - providing enterprise-grade Linux distributions - ActiveState does for open source programming languages." Clearly ActiveState is an interesting product that's playing an important part in helping enterprises to better manage the widespread migration to open source technology. For the latest edition of the Packt Podcast we spoke to Copeland about ActiveState and the growth of open source over the last decade. We think you'll find what he has to say interesting... Listen: https://soundcloud.com/packt-podcasts/activestate-making-open-source-more-accessible-for-the-enterprise-interview-with-bart-copeland   Read next: Can a modified MIT ‘Hippocratic License’ to restrict misuse of open source software prompt a wave of ethical innovation in tech? Key quotes from Bart Copeland Copeland on the relationship between enterprise management and developers: "If you look at the enterprise… they want to make sure that it works and it doesn’t cause security threats and their in compliance with all the licenses. And the result is, due to the complexities of open source, management within the enterprise will often limit developers on what languages and what open source stacks they can use because the more stacks you have, the more complexity you have in an organization." Copeland on developer freedom: "A developer is a very technical and creative individual and they want to be able to use the right tools to build the right solution. And so if a developer is handcuffed to certain technology stacks, they may not be able to use the best technology to solve the problem." Learn more about ActiveState here.
Read more
  • 0
  • 0
  • 3150

article-image-python-experts-talk-python-twitter-qa-recap
Richard Gall
29 Mar 2018
3 min read
Save for later

Python experts talk Python on Twitter: Q&A Recap

Richard Gall
29 Mar 2018
3 min read
To celebrate the launch of Python Interviews, we ran a Q&A session on Twitter with some of the key contributors to the book. Author and interviewer Mike Driscoll (@driscollis), and experienced Python contributors Steve Holden (@holdenweb), and Alex Martelli (@aleaxit) got together to respond to your questions. Here's what happened... https://twitter.com/PacktPub/status/979055321959358465 https://twitter.com/aleaxit/status/979055993874104321 https://twitter.com/holdenweb/status/979056136199593984 https://twitter.com/driscollis/status/979056963987361793 The future of Python We then asked Mike, Steve and Alex what they thought the future of Python is going to look like. https://twitter.com/aleaxit/status/979057847660003328 https://twitter.com/holdenweb/status/979059669699309569 https://twitter.com/holdenweb/status/979059813459034112 https://twitter.com/driscollis/status/979059276017815554 How to get involved with the Python community We then asked what our experts think is the best way for someone new to the Python community to get involved. With the language growing at an immense rate, more people are (hopefully) going to want to contribute to the project. https://twitter.com/aleaxit/status/979059707389231105 https://twitter.com/holdenweb/status/979060708276137985 Advice for anyone new to programming Programmings popularity as a career choice is growing. That's not just true of new graduates but people looking to retrain and take on a new challenge in their career. But what should anyone new to programming know when starting out? https://twitter.com/aleaxit/status/979063034202107905 https://twitter.com/holdenweb/status/979061878554054658 https://twitter.com/driscollis/status/979061529575346177 Switching from Python 2.7 to Python 3 There's been considerable discussion within the community on the merits of shifting from Python 2.7 to Python 3. But whatever the obvious advantages are, there will always be resistance to change when it requires an investment of time and effort. And if you don't need to switch then why would you? Here's what Mike, Steve and Alex had to say... https://twitter.com/aleaxit/status/979063346665107457 https://twitter.com/holdenweb/status/979062974450192384 https://twitter.com/driscollis/status/979062547935571969 What gives Python an advantage over other programming languages? Why is Python so popular exactly? If it's growing at such a fantastic rate, why are developers and engineers turning to it? What does it have that other languages don't? https://twitter.com/aleaxit/status/979063792276471808 https://twitter.com/holdenweb/status/979064210608001025 https://twitter.com/driscollis/status/979063896173699072 Future Python releases If Python's going to remain popular, it's going to need to adapt and evolve with the needs of the developers of the future. So what capabilities and features would our experts like to see from Python in the future? https://twitter.com/driscollis/status/979064329864695813 https://twitter.com/aleaxit/status/979064880757063680 https://twitter.com/holdenweb/status/979064474496913408 What problems does Python face as a language? https://twitter.com/driscollis/status/979065953949552640 https://twitter.com/aleaxit/status/979065864539357184 https://twitter.com/holdenweb/status/979066065706725376 Why is Python so useful for AI and Machine learning? AI is a growing area that has expanded beyond the confines of data science into just about every corner of modern software engineering. Python has been a core part of this, and in part it explains part of the rise of Python's popularity - people want to build algorithms in a way that's relatively straightforward. https://twitter.com/driscollis/status/979066778771914752 https://twitter.com/holdenweb/status/979069094862389253 https://twitter.com/holdenweb/status/979069100831006721
Read more
  • 0
  • 0
  • 6048
Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime