SlideShare a Scribd company logo
Dr. Miguel Fierro
@miguelgfierro
Best practices in coding for
beginners
2
Pursuing Artificial Intelligence
Language
Speech
Search
Machine
Learning
Knowledge Vision
3
Agenda
The why, the what and the how of Python
Development
strategies
Software development principles
What’s next?
4
Agenda
The why, the what and the how of Python
Development
strategies
Software development principles
What’s next?
Why Python?
Most popular language
According to PYPL, Python
surpassed Java in 2018 as the most
popular programming language.
The language of AI
It has became the language of AI,
machine learning and deep learning.
Most of the top AI libraries use
python.
Easier
As Python typically involves less
code, it also takes less time to
complete a job. This also means
less money.
Dr. Miguel Fierro - @miguelgfierro
6
The final 2.x version 2.7 release came out in
mid-2010
Python 2.7 will only receive necessary security
updates until 2020
Python 3.5 was released in 2015 and Python
3.6 in 2016.
All recent standard library improvements are
available in Python 3.x by default
Python 2.x Python 3.x
Python 3.x is the present and future
of the language
Dr. Miguel Fierro - @miguelgfierro
7
$ source activate my_env
(my_env) $ pip install –r requirements.txt
bash
Python environments
# file: requirements.txt
Django==1.7.10
markdown2==2.3.0
Pillow==4.2.1
numpy>=1.13.3
opencv>=3.3.0
pyodbc>=4.0.21
requests>=2.18.4
beautifulsoup4>=4.6.0
pandas>=0.22.0
scikit-image>=0.13.1
scikit-learn>=0.19.1
scipy>=0.19.0
matplotlib>=1.5.3
file
Python environments encapsulate development
Dr. Miguel Fierro - @miguelgfierro
8
$ conda create –n my_env –f conda.yaml
$ source activate my_env
(my_env) $
bash
Conda environments
# file: conda.yaml
channels:
- conda-forge
- defaults
dependencies:
- python==3.6
- numpy==1.13.3
- flask==1.0.2
- cherrypy==12.0.1
- ipykernel==4.6.1
- pip:
- pandas==0.22.0
- scipy==1.1.0
- scikit-learn==0.19.1
- jupyter==1.0.0
file
Conda environments make development easier
Dr. Miguel Fierro - @miguelgfierro
Typical project structure
9
docs
robotics
tests
third_party
tools
.coveragerc
.gitignore
.travis.yml
LICENSE.md
README.md
setup.py
Example of library: robotics
10
Agenda
The why, the what and the how of Python
Development
strategies
Software development principles
What’s next?
11
Jupyter notebooks
Dr. Miguel Fierro - @miguelgfierro
Test Driven Development
Develop the tests first
1) Add a test
Write a test that defines a function or
improvements of a function.
It makes the developer focus on the
requirements before writing the code, a
subtle but important difference.
2) Run the test to check it fails
Execute all the tests and check whether
they pass or fail. The new test should fail
for the expected reason.
3) Write the code
Write some code that causes the test to
pass. The new code written at this stage is
not perfect and will be improved later.
At this point, the only purpose of the
written code is to pass the test.
5) Refactor code
Clean the code, remove duplication, avoid
magic numbers (constants without a
variable) and apply other software
development techniques.
4) Run the test to check it passes
The new test should pass.
Now the programmer can be confident
that the new code meets the test
requirements.
6) Repeat
For each new functionality of the code,
start by adding a new test
Dr. Miguel Fierro - @miguelgfierro
13
def test_predict_accuracy (self):
acc = predict()
self.assertGreaterEqual(acc, 0)
self.assertLessEqual(acc, 1)
Type of tests
Python def test_predict_accuracy (self):
acc = predict()
self.assertGreaterEqual(acc, 0.65)
def test_predict_accuracy (self):
acc = predict()
self.assertEqual(acc, 0.654345675)
Unit tests Integration tests Utility tests
It tests the correct behavior It tests that whether the result is acceptable It shows an example of the behavior
Dr. Miguel Fierro - @miguelgfierro
14
How to create a library
Dr. Miguel Fierro - @miguelgfierro
15
def sigmoid(x):
"""Sigmoid function. Output between 0-1
Args:
x (np.array): An array.
Returns:
result (np.array): Sigmoid of the array.
Examples:
>>> x = np.array([[1,1,-3],[0.5,-1,1]])
>>> sigmoid(x)
array([[0.73, 0.73, 0.04],
[0.62, 0.26, 0.73]])
"""
return 1. / (1 + np.exp(-x))
Documentation: Python docstrings
Python
Google style Numpy style
def sigmoid(x):
"""Sigmoid function. Output between 0-1
Parameters
-----------
x : np.array
An array.
Returns
-------
result : np.array
Sigmoid of the array.
Examples
--------
>>> x = np.array([[1,1,-3],[0.5,-1,1]])
>>> sigmoid(x)
array([[0.73, 0.73, 0.04],
[0.62, 0.26, 0.73]])
"""
return 1. / (1 + np.exp(-x))
Dr. Miguel Fierro - @miguelgfierro
16
Code style: PEP8
Python's official style guide, for formatting code
correctly to maximize its readability.
Created in 2001 by Guido van Rossum et. al.
!DILEMMA:
How to automatize the code style?
Use auto-format in your favorite IDE
PyCharm
Free and payed
version
Visual Studio
Heavy weight IDE with
many functionalities
VS Code
Ubuntu default
Atom
Results visualization
No matter which IDE you prefer,
it will save you time and make the
development easier.
Dr. Miguel Fierro - @miguelgfierro
18
Agenda
The why, the what and the how of Python
Development
strategies
Software development principles
What’s next?
Software development principles
Single responsibility DRY
(Don’t Repeat
Yourself)
MVP
(Minimum Viable
Product)
Plan for reuse
Key concepts for creating great software
Dr. Miguel Fierro - @miguelgfierro
Modularity
Single responsibility
Each class or module should be responsible for a
single part of the software, in other words: “A
class should have only one reason to change”.
Part of a broader set of principles called SOLID.
A class does only one thing, a function does only one thing
Dr. Miguel Fierro - @miguelgfierro
DRY
If a piece of code can be generalized and reuse, do it!
Extract a new function or a private method.
Reducing complexity
Don’t Repeat Yourself … please
Dr. Miguel Fierro - @miguelgfierro
Fail fast
MVP
The MVP is the minimum product that collects the
maximum amount of validated learning about
customers with the least effort.
Based on the Lean Startup methodology.
Minimum Viable Product
Dr. Miguel Fierro - @miguelgfierro
Generalize your code to be reusable
Generalization
Plan for reuse
Whenever you create a piece of software, design it
in a way so it can be reusable in other projects.
It will save you a lot of time.
Dr. Miguel Fierro - @miguelgfierro
24
Agenda
The why, the what and the how of Python
Development
strategies
Software development principles
What’s next?
25
Create your own codebase
Dr. Miguel Fierro - @miguelgfierro
26
Start contributing to opensource
Dr. Miguel Fierro - @miguelgfierro
Dr. Miguel Fierro
@miguelgfierro
Best practices in coding for
beginners

More Related Content

PDF
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
PDF
Can Python Overthrow Java? | Java vs Python | Edureka
PDF
Python Programming Tutorial | Edureka
PDF
How to become a Python Developer | Python Developer Skills | Python Career | ...
PPTX
Python Usefulness
PDF
Let linguistics guide software analysis
PPTX
Python basic
PDF
Software Analysis using Natural Language Queries
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Can Python Overthrow Java? | Java vs Python | Edureka
Python Programming Tutorial | Edureka
How to become a Python Developer | Python Developer Skills | Python Career | ...
Python Usefulness
Let linguistics guide software analysis
Python basic
Software Analysis using Natural Language Queries

What's hot (20)

PDF
How Netflix uses Python? Edureka
PDF
Robot Framework with Python | Edureka
PPTX
Introduction to Python Basics Programming
PDF
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
PPTX
Is your code ready for testing?
PDF
Comment soup with a pinch of types, served in a leaky bowl
PDF
5 Simple Steps To Install Python On Windows | Install Python 3.7 | Python Tra...
PPTX
Introduction to python updated
PPTX
Career in python
PPTX
Test Driven Development (TDD) Preso 360|Flex 2010
ODP
Tdd in php a brief example
PDF
Introduction to Python IDLE | IDLE Tutorial | Edureka
PPTX
Let's Explore C# 6
PDF
PYTHON PROGRAMMING FOR HACKERS. PART 1 – GETTING STARTED
PDF
IRJET- Python: Simple though an Important Programming Language
PPTX
The Python outside of your textbook
PDF
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
PPTX
PPTX
Python Programming Course
PPTX
The Medusa Project
How Netflix uses Python? Edureka
Robot Framework with Python | Edureka
Introduction to Python Basics Programming
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Is your code ready for testing?
Comment soup with a pinch of types, served in a leaky bowl
5 Simple Steps To Install Python On Windows | Install Python 3.7 | Python Tra...
Introduction to python updated
Career in python
Test Driven Development (TDD) Preso 360|Flex 2010
Tdd in php a brief example
Introduction to Python IDLE | IDLE Tutorial | Edureka
Let's Explore C# 6
PYTHON PROGRAMMING FOR HACKERS. PART 1 – GETTING STARTED
IRJET- Python: Simple though an Important Programming Language
The Python outside of your textbook
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Python Programming Course
The Medusa Project
Ad

Similar to Best practices in coding for beginners (20)

PPT
👉Python Programming Course – Complete Overview 3.ppt
DOCX
Malware Detection using ML Malware Detection using ml
DOCX
Android Malware Detection Using Genetic Algorithm.docx
PDF
What makes python 3.11 special
PDF
10 useful Python development setup tips to boost your productivity
PDF
DIY in 5 Minutes: Testing Django App with Pytest
PDF
Ways To Become A Good Python Developer
PPTX
Educator Guide_Coding Algorithms_V2.3.pptx
PDF
Econometrics for python, how to deal with data
DOCX
python training.docx
PPTX
python programming.pptx
PPTX
Introduction to Python and Basic Syntax.pptx
PDF
Best Python IDEs in 2024 Boosting Creativity and Learning for Young Programme...
PPTX
Future of Python Certified Professionals in Data Science and Artificial Intel...
PPTX
Python for Software Developers May-2025.pptx
PPT
Introduction to Agile Software Development & Python
DOCX
python Certification Training in marthahalli
PDF
Python
PDF
A Comprehensive Guide to App Development with Python - AppsDevPro
PPTX
Django strategy-test
👉Python Programming Course – Complete Overview 3.ppt
Malware Detection using ML Malware Detection using ml
Android Malware Detection Using Genetic Algorithm.docx
What makes python 3.11 special
10 useful Python development setup tips to boost your productivity
DIY in 5 Minutes: Testing Django App with Pytest
Ways To Become A Good Python Developer
Educator Guide_Coding Algorithms_V2.3.pptx
Econometrics for python, how to deal with data
python training.docx
python programming.pptx
Introduction to Python and Basic Syntax.pptx
Best Python IDEs in 2024 Boosting Creativity and Learning for Young Programme...
Future of Python Certified Professionals in Data Science and Artificial Intel...
Python for Software Developers May-2025.pptx
Introduction to Agile Software Development & Python
python Certification Training in marthahalli
Python
A Comprehensive Guide to App Development with Python - AppsDevPro
Django strategy-test
Ad

More from Miguel González-Fierro (12)

PPTX
Los retos de la inteligencia artificial en la sociedad actual
PDF
Knowledge Graph Recommendation Systems For COVID-19
PDF
Thesis dissertation: Humanoid Robot Control of Complex Postural Tasks based o...
PDF
Distributed training of Deep Learning Models
PPTX
Running Intelligent Applications inside a Database: Deep Learning with Python...
PPTX
Deep Learning for Sales Professionals
PPTX
Deep Learning for Lung Cancer Detection
PPTX
Mastering Computer Vision Problems with State-of-the-art Deep Learning
PPTX
Speeding up machine-learning applications with the LightGBM library
PDF
Leveraging Data Driven Research Through Microsoft Azure
PDF
Empowering every person on the planet to achieve more
PDF
Deep Learning for NLP
Los retos de la inteligencia artificial en la sociedad actual
Knowledge Graph Recommendation Systems For COVID-19
Thesis dissertation: Humanoid Robot Control of Complex Postural Tasks based o...
Distributed training of Deep Learning Models
Running Intelligent Applications inside a Database: Deep Learning with Python...
Deep Learning for Sales Professionals
Deep Learning for Lung Cancer Detection
Mastering Computer Vision Problems with State-of-the-art Deep Learning
Speeding up machine-learning applications with the LightGBM library
Leveraging Data Driven Research Through Microsoft Azure
Empowering every person on the planet to achieve more
Deep Learning for NLP

Recently uploaded (20)

PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PDF
ETO & MEO Certificate of Competency Questions and Answers
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
PPTX
Practice Questions on recent development part 1.pptx
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
composite construction of structures.pdf
PPTX
Sustainable Sites - Green Building Construction
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
web development for engineering and engineering
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
Internship_Presentation_Final engineering.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
DOCX
573137875-Attendance-Management-System-original
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
ETO & MEO Certificate of Competency Questions and Answers
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Practice Questions on recent development part 1.pptx
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Model Code of Practice - Construction Work - 21102022 .pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
composite construction of structures.pdf
Sustainable Sites - Green Building Construction
Lecture Notes Electrical Wiring System Components
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
web development for engineering and engineering
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
Internship_Presentation_Final engineering.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
573137875-Attendance-Management-System-original

Best practices in coding for beginners

  • 1. Dr. Miguel Fierro @miguelgfierro Best practices in coding for beginners
  • 3. 3 Agenda The why, the what and the how of Python Development strategies Software development principles What’s next?
  • 4. 4 Agenda The why, the what and the how of Python Development strategies Software development principles What’s next?
  • 5. Why Python? Most popular language According to PYPL, Python surpassed Java in 2018 as the most popular programming language. The language of AI It has became the language of AI, machine learning and deep learning. Most of the top AI libraries use python. Easier As Python typically involves less code, it also takes less time to complete a job. This also means less money. Dr. Miguel Fierro - @miguelgfierro
  • 6. 6 The final 2.x version 2.7 release came out in mid-2010 Python 2.7 will only receive necessary security updates until 2020 Python 3.5 was released in 2015 and Python 3.6 in 2016. All recent standard library improvements are available in Python 3.x by default Python 2.x Python 3.x Python 3.x is the present and future of the language Dr. Miguel Fierro - @miguelgfierro
  • 7. 7 $ source activate my_env (my_env) $ pip install –r requirements.txt bash Python environments # file: requirements.txt Django==1.7.10 markdown2==2.3.0 Pillow==4.2.1 numpy>=1.13.3 opencv>=3.3.0 pyodbc>=4.0.21 requests>=2.18.4 beautifulsoup4>=4.6.0 pandas>=0.22.0 scikit-image>=0.13.1 scikit-learn>=0.19.1 scipy>=0.19.0 matplotlib>=1.5.3 file Python environments encapsulate development Dr. Miguel Fierro - @miguelgfierro
  • 8. 8 $ conda create –n my_env –f conda.yaml $ source activate my_env (my_env) $ bash Conda environments # file: conda.yaml channels: - conda-forge - defaults dependencies: - python==3.6 - numpy==1.13.3 - flask==1.0.2 - cherrypy==12.0.1 - ipykernel==4.6.1 - pip: - pandas==0.22.0 - scipy==1.1.0 - scikit-learn==0.19.1 - jupyter==1.0.0 file Conda environments make development easier Dr. Miguel Fierro - @miguelgfierro
  • 10. 10 Agenda The why, the what and the how of Python Development strategies Software development principles What’s next?
  • 11. 11 Jupyter notebooks Dr. Miguel Fierro - @miguelgfierro
  • 12. Test Driven Development Develop the tests first 1) Add a test Write a test that defines a function or improvements of a function. It makes the developer focus on the requirements before writing the code, a subtle but important difference. 2) Run the test to check it fails Execute all the tests and check whether they pass or fail. The new test should fail for the expected reason. 3) Write the code Write some code that causes the test to pass. The new code written at this stage is not perfect and will be improved later. At this point, the only purpose of the written code is to pass the test. 5) Refactor code Clean the code, remove duplication, avoid magic numbers (constants without a variable) and apply other software development techniques. 4) Run the test to check it passes The new test should pass. Now the programmer can be confident that the new code meets the test requirements. 6) Repeat For each new functionality of the code, start by adding a new test Dr. Miguel Fierro - @miguelgfierro
  • 13. 13 def test_predict_accuracy (self): acc = predict() self.assertGreaterEqual(acc, 0) self.assertLessEqual(acc, 1) Type of tests Python def test_predict_accuracy (self): acc = predict() self.assertGreaterEqual(acc, 0.65) def test_predict_accuracy (self): acc = predict() self.assertEqual(acc, 0.654345675) Unit tests Integration tests Utility tests It tests the correct behavior It tests that whether the result is acceptable It shows an example of the behavior Dr. Miguel Fierro - @miguelgfierro
  • 14. 14 How to create a library Dr. Miguel Fierro - @miguelgfierro
  • 15. 15 def sigmoid(x): """Sigmoid function. Output between 0-1 Args: x (np.array): An array. Returns: result (np.array): Sigmoid of the array. Examples: >>> x = np.array([[1,1,-3],[0.5,-1,1]]) >>> sigmoid(x) array([[0.73, 0.73, 0.04], [0.62, 0.26, 0.73]]) """ return 1. / (1 + np.exp(-x)) Documentation: Python docstrings Python Google style Numpy style def sigmoid(x): """Sigmoid function. Output between 0-1 Parameters ----------- x : np.array An array. Returns ------- result : np.array Sigmoid of the array. Examples -------- >>> x = np.array([[1,1,-3],[0.5,-1,1]]) >>> sigmoid(x) array([[0.73, 0.73, 0.04], [0.62, 0.26, 0.73]]) """ return 1. / (1 + np.exp(-x)) Dr. Miguel Fierro - @miguelgfierro
  • 16. 16 Code style: PEP8 Python's official style guide, for formatting code correctly to maximize its readability. Created in 2001 by Guido van Rossum et. al. !DILEMMA: How to automatize the code style? Use auto-format in your favorite IDE
  • 17. PyCharm Free and payed version Visual Studio Heavy weight IDE with many functionalities VS Code Ubuntu default Atom Results visualization No matter which IDE you prefer, it will save you time and make the development easier. Dr. Miguel Fierro - @miguelgfierro
  • 18. 18 Agenda The why, the what and the how of Python Development strategies Software development principles What’s next?
  • 19. Software development principles Single responsibility DRY (Don’t Repeat Yourself) MVP (Minimum Viable Product) Plan for reuse Key concepts for creating great software Dr. Miguel Fierro - @miguelgfierro
  • 20. Modularity Single responsibility Each class or module should be responsible for a single part of the software, in other words: “A class should have only one reason to change”. Part of a broader set of principles called SOLID. A class does only one thing, a function does only one thing Dr. Miguel Fierro - @miguelgfierro
  • 21. DRY If a piece of code can be generalized and reuse, do it! Extract a new function or a private method. Reducing complexity Don’t Repeat Yourself … please Dr. Miguel Fierro - @miguelgfierro
  • 22. Fail fast MVP The MVP is the minimum product that collects the maximum amount of validated learning about customers with the least effort. Based on the Lean Startup methodology. Minimum Viable Product Dr. Miguel Fierro - @miguelgfierro
  • 23. Generalize your code to be reusable Generalization Plan for reuse Whenever you create a piece of software, design it in a way so it can be reusable in other projects. It will save you a lot of time. Dr. Miguel Fierro - @miguelgfierro
  • 24. 24 Agenda The why, the what and the how of Python Development strategies Software development principles What’s next?
  • 25. 25 Create your own codebase Dr. Miguel Fierro - @miguelgfierro
  • 26. 26 Start contributing to opensource Dr. Miguel Fierro - @miguelgfierro
  • 27. Dr. Miguel Fierro @miguelgfierro Best practices in coding for beginners