SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
Keep your repo clean
Héctor Canto
@hectorcanto_dev
● Software Developer ++
● Barcelona & Vigo
● @ Blueliv
○ CyberSecurity
○ Threat Intelligence
● Interested in
○ Best practices
○ Great documentation
○ Teach and Learn
About me
● Maintenance
● Best practices
● Standards
● Auxiliary tools
○ Security
● Documentation
● Collaboration
Topics
Keep your repo clean
Main ideas
1. Code, config, deploy and documentation matched together
○ joined through CI/CD and versioning
2. Code not only for yourself, but for others
3. Holistic view of documentation
“Code is read much more often than written.”
- paraphrasing Clean Code, Robert C.Martin (2008)
Keep your repo clean
Why maintaining a project
● “Future you”
● Collaboration
○ team-mates
○ non-tech colleagues (product, sales)
○ external workers
○ partners
● Holiday, medical leaves, bus factor & rotation
● Do to others what you hope they do to you
“Always code as if the guy who ends up
maintaining your code will be a violent
psychopath who knows where you live.
Code for readability.”
- John F. Woods (1991)
Keep your repo clean
I- Code, config and deploy
Keep your repo clean
They have some common folder and files
> Let's build a template
References
- https://medium.com/worldsensing-techblog/project-templates-an
d-cookiecutter-6d8f99a06374
- https://realpython.com/python-application-layouts/
- http://cookiecutter-templates.sebastianruml.name/
- PyConEs 2018 https://www.youtube.com/watch?v=Ttco5BTJI7I
- PyBCN 2019 https://www.youtube.com/watch?v=TkrTM2Byj34
How a repo should look like
Cookiecutter, Yeoman
PEP-8, keepachangelog.com
├── $source/
├── config/
├── deploy/
├── docs/
├── requirements/
├── scripts/
├── README.md
├── CHANGELOG.md
├── setup.cfg
├── Makefile
├── docker-compose.yml
└── sonar-project.properties
Keep your repo clean
Versioning
● Versioning is very useful
○ rollbacks, debugging, regressions
● It should span to:
○ Tags, Releases, Documentation
○ Artifact repositories (pkg manager, Docker registry)
● Major.minor.patch-prerelease.x+build#commit
○ 1.0.0-alpha.2+201303131abde44700
○ 0.7.2-rc.5
bumpversion, Nexus (artifacts), CI/CD tools
SemVer.org 1.0+, PEP-404
# setup.cfg
[bumpversion]
current_version = 1.2.3
commit = False
tag = True
tag_name = {new_version}
[bumpversion:file:source/__nit__.py]
[bumpversion:file:sonar-project.prop
erties]
# bash
bumpversion patch --new-version
2.1.3
Keep your repo clean
● Should work out-of-the-box
● Templates
○ With comments and loops!
○ same template, multiple environments
● Infrastructure as Code
● Passwords out of repo
# db.env
POSTGRES_USER=dbuser
POSTGRES_DB=dbname
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_PASSWORD=notadmin
# db.env.j2
name: {{ db.schema_name|default('dbname') }}
user: {{ db.user | default('dbuse') }}
{# do not use same dbname and username #}
host: {{ db.host | default('postgres') }}
port: {{ db.port | default(5432) }}
{%- if 'password' in db %}
password: '{{ db.password }}'
{%- endif %}
Maintain a workable config
Jinja2, direnv, docker, ConfigLoad
IaC, YAML, .env
Keep your repo clean
Utils configuration: setup.cfg
● Keep your utils configurations together
● And the root of your folder lighter
setup.cfg
# setup.cfg
[flake8]
...
[pylint]
...
[pep8]
...
[coverage:run]
...
[coverage:report]
...
[coverage:xml]
...
[coverage:html]
...
[tool:pytest]
...
Keep your repo clean
Connect it all: Code, config and deploy
● A repository should have the means to be deployed
○ instructions in documentation
○ simple commands in Makefile, manage.py, scripts ...
● Code, config and deploy should match together in a point-in-time
● Strategy 1: all in one repo Strategy II: multi-repo
● CI/CD and config management tools join all together
Python-Fabric, Chef, Puppet, Ansible, Salt, Terraform …
IaC, DevOps, SRE
Keep your repo clean
Connect it all: branching and ticketing
● Ticket numbering
○ type-of-branch/functional-name-#PROJ-123
■ feature, bugfix, release, docs …
■ what are you implementing here, don't repeat the ticket title
■ what ticket are you solving
● Versioning reference:
○ git - changelog - docker - docs - ticketing …
○ links on the wiki to the "latest", prevents obsolescence
Any CI-CD tool, Git GUI Clients
git-flow
Keep your repo clean
II - Code for others
Keep your repo clean
To be a good programmer you need to be a bit of a writer
● Be coherent and consistent
○ try: …. except SpecificException as exc:
● Answer some of the 6 'W' of journalism:
○ Who, What, Where, Why, When and hoW
● An image is worth more than 1000 words
○ Diagrams!
Code style I
class WhoService
def what_i_do(p1, p2, p3)
"""
why I do this, and a bit
how
p1: where to
p2: who
p3: when or how often
"""
how_i_do_this()
and_that()
return what_you_need
Keep your repo clean
PlantUML, Draw.io, InkScape
UML, SVG
Code Style II
1. Avoid generic vocabulary, use specifics:
a. Frontend app, API REST, auth service, TwitterAPIClient
2. Use collective nouns and adjectives:
a. for choice in choice_options
b. for element in selected_items
c. for item in raw_params
3. Avoid custom abbreviations,
use conventions.
4. Add a glossary to your project docs
or to your wiki.
https://hackernoon.com/software-complexity-naming-6e02e7e6c8cb
“Vocabulary is not just a way of communication,
it is a toolset.
It evokes ideas, it enables abstraction and specification.
But it also introduces implicit meaning, irony,
sarcasm, hidden assumptions.”
Keep your repo clean
Sphinx-docs
● Main on top, detail out or below
● Don't put all code together, modules!
○ my rule of thumb 500 lines (200 even better)
○ 30 lines per method or function
● Follow a style guide
○ extend it with your own rules
Code style III
Writing Idiomatic Python (Jeff Knup), Google's pyguide
black, flake8, pylint, Sonarqube, IDE plugins
PEP-8, PEP-20
Keep your repo clean
- Put the main function first, leave
fine details to other methods
- Use submodules and classes to
order things and encapsulate logic
together (in classes f.i.)
- Use _ and __ to tip scope
- import namespaces, not classes and
funcitons, to give context
Code style IV
● Know your Design Patterns
○ client-server, singleton, adapter, pub/sub, factory ...
● Follow well-known principles and practices:
○ Object Calisthenics
■ if-else inversion
○ SOLID, KISS, DRY, YAGNI…
○ Learn about DDD
https://sourcemaking.com/
https://williamdurand.fr/2013/06/03/object-calisthenics/
# SOLID
S: validate_filter_transform_and_upload
O: BaseClass, CoolMixin, HigherOrderComponent
LD: func1(data, param1, param2)
func2(data, param2, param1)
I: def func3(injection1, injection2):
that = injection1.search(this)
injection2.save(that)
Keep your repo clean
Comments and docstrings
● Do not comment everything
● Use triple-quote comments
● Save comments and docstrings
with good naming
● Type hinting! Python 3.5+
● Follow a docstring standard:
○ reST, numpy, Google, Epytext
"""
This is a multiline
comment
"""
"""
This is a Google docstring
Args:
param1 (int): The 1st parameter.
param2 (str): The 2nd parameter.
Returns:
bool: The return value. True for
success, False otherwise.
Raise:
TypeError: parameters are wrong
"""
http://daouzli.com/blog/docstring.html
PEP-257
Keep your repo clean
Security Tools
● Safety (pyup.io)
● Docker Image scans: Clair, Trivy
● Docker secrets (Swarm, K8S)
● Ansible Vault
● SonarQube
● git-crypt
● KeePassXC
● Training, training and training
Keep your repo clean
III - Documentation purposes
Keep your repo clean
Documentation goals
▪ Explain implementation
▪ extension of the code
▪ Explain purpose
▪ Give context
▪ Evolution traceback
▪ Explain how to work together
▪ the framework
▪ Explain decisions
Keep your repo clean
Extended documentation
In order of scope
- Code itself
- Comments
- Docstrings
- Tests
- Commit log
- Dev docs
- +ADRs (next slide...)
- API specification
- GUI helpers (tooltips, inline help)
- Tickets or Stories
- Project wiki
- User docs
- FAQ
Who reads the documentation:
- You
- Future you
- Your team
- Other devs
- Other colleagues
- Marketing, customer support ...
- Managers
- Partners
- Customers
- Users
Keep your repo clean
Architecture Decision Records (ADR)
● Higher scope: architecture and software design
● Explain expectations
● State pros, cons, expected benefits and risk
● Write down agreements and compromises
● Re-evaluation and self-evaluation:
○ why we use such language, framework or design
ADR Template
# Intro
## Author, Approvers, links
# Context and problem statement
# Decision
## Drivers, Considered options
## Outcome
# Pros and expected benefits
# Cons and potential risks
# Possible improvements
# Links to other ADRs
Keep your repo clean
thoughtworks.com/radar/techniques/lightweight-architecture
-decision-records
ADR templates: https://adr.github.io
Extended documentation caveats
Caveats:
- Maintenance
- obsolescence and inconsistency
- Redundancy
- Different scopes
- departments, docs audience
- Out of one own responsibility
- Beware of Agile principles:
- “Working SW first”
- Not good for small projects
Solutions and mitigations:
- Documentation owner and/or
docs committee
- Automation
- Documentation as Code
- One source of truth
- Bug-bashing for docs
- Spread Domain language across
teams and projects (DDD)
Keep your repo clean
● Keep code, config and deploy synced with Versioning
● Think on the "future you"
● Write code for others
● Use tools, standards and automatization to your benefit
● Code explains implementation, documentation explain purpose
○ and gives context
● Consider the "extended" documentation
Summary
Keep your repo clean
Thanks for your attention!
Questions?
Héctor Canto
@hectorcanto_dev
hectorcanto
WE'RE HIRING
Specifics
● Repo structure and maintenance
● Versioning
● Config
● Deploy artifacts
● Test
● Security
● Code style
● Extended Documentation
Each of the following topics may be
extended to a full talk.
We will keep things high level.
All icons, images and graphs are made by
me, opensource or free-to-use:
https://icons8.com
https://unsplash.com/
InkScape & GIMP
Disclaimers
Deploy
A repository must have the means to run the software it represents
● Commands to simplify the process
○ Makefile, manage.py, Ansible
● Means to deploy: Docker, python-fabric, Ansible, Terraform…
● Consider several environments
make, Ansible, fabric, Terraform, Docker ...
IaC
● Spend time testing
○ a lot initially, it is worth it
● Understand the different aspects of test
○ Cost
○ Unicity
○ Intention
○ Box-style
● A test can have several aspect at once
○ Unitary tests usually are cheap, white-box, non-integrative ...
○ Sometimes they may have some “integration” side
● Understand the test pyramid analogy
unittest, pytest, mock, hypothesis, Postman ...
TDD, BDD
Tests
More ‘doc’ tools
- Swagger (OAI)
- Django Rest Framework browsable API
- Any Wiki
- Ticketing System
- Bug Tracking System
- Support forum and FAQs
Reference one to each other
To be a good programmer you need to be a
bit of a writer
● Be coherent and consistent
○ try: … except SpecificException as exc:
● Answer some of the 6 'W' of journalism:
○ what, how, why, when, where, who
● An image is worth more than 1000 words
○ Diagrams!
● Don't put all code together, modules!
○ my rule of thumb 500 lines (200 even better)
Code style
Keep your repo clean

Contenu connexe

Tendances

Traquer les fuites mémoires avec Python
Traquer les fuites mémoires avec PythonTraquer les fuites mémoires avec Python
Traquer les fuites mémoires avec PythonVictor Stinner
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytestHector Canto
 
Jenkins multi configuration (matrix)
Jenkins multi configuration (matrix)Jenkins multi configuration (matrix)
Jenkins multi configuration (matrix)Muhammad Zbeedat
 
Python Debugging Fundamentals
Python Debugging FundamentalsPython Debugging Fundamentals
Python Debugging Fundamentalscbcunc
 
Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 27: FileSystems in Linux (Part 2)Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 27: FileSystems in Linux (Part 2)Ahmed El-Arabawy
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced pythonCharles-Axel Dein
 
Héberger son site web
Héberger son site webHéberger son site web
Héberger son site webStrasWeb
 
Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Edureka!
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python TutorialSimplilearn
 
File Handling Python
File Handling PythonFile Handling Python
File Handling PythonAkhil Kaushik
 
I got 99 problems, but ReST ain't one
I got 99 problems, but ReST ain't oneI got 99 problems, but ReST ain't one
I got 99 problems, but ReST ain't oneAdrian Cole
 
Document Object Model ( DOM)
Document Object Model ( DOM)Document Object Model ( DOM)
Document Object Model ( DOM)Abdelouahed Abdou
 
Python Deserialization Attacks
Python Deserialization AttacksPython Deserialization Attacks
Python Deserialization AttacksNSConclave
 
Helpful logging with python
Helpful logging with pythonHelpful logging with python
Helpful logging with pythonroskakori
 
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzingGareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzingYury Chemerkin
 

Tendances (20)

Traquer les fuites mémoires avec Python
Traquer les fuites mémoires avec PythonTraquer les fuites mémoires avec Python
Traquer les fuites mémoires avec Python
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytest
 
Jenkins multi configuration (matrix)
Jenkins multi configuration (matrix)Jenkins multi configuration (matrix)
Jenkins multi configuration (matrix)
 
Python Debugging Fundamentals
Python Debugging FundamentalsPython Debugging Fundamentals
Python Debugging Fundamentals
 
Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 27: FileSystems in Linux (Part 2)Course 102: Lecture 27: FileSystems in Linux (Part 2)
Course 102: Lecture 27: FileSystems in Linux (Part 2)
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
 
Python operator precedence and comments
Python   operator precedence and commentsPython   operator precedence and comments
Python operator precedence and comments
 
Héberger son site web
Héberger son site webHéberger son site web
Héberger son site web
 
Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...
 
Lesson 4 constant
Lesson 4  constantLesson 4  constant
Lesson 4 constant
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
I got 99 problems, but ReST ain't one
I got 99 problems, but ReST ain't oneI got 99 problems, but ReST ain't one
I got 99 problems, but ReST ain't one
 
Files in Python.pptx
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
 
Document Object Model ( DOM)
Document Object Model ( DOM)Document Object Model ( DOM)
Document Object Model ( DOM)
 
Python Deserialization Attacks
Python Deserialization AttacksPython Deserialization Attacks
Python Deserialization Attacks
 
Polymorphisme (cours, résumé)
Polymorphisme (cours, résumé)Polymorphisme (cours, résumé)
Polymorphisme (cours, résumé)
 
Helpful logging with python
Helpful logging with pythonHelpful logging with python
Helpful logging with python
 
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzingGareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
 

Similaire à Keep your repo clean

AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017Ortus Solutions, Corp
 
Javascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxJavascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxMukundSonaiya1
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016maiktoepfer
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with pythonroskakori
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unitKotresh Munavallimatt
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowKathy Brown
 
Pentester++
Pentester++Pentester++
Pentester++CTruncer
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdfManaging Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdfAndrew Lamb
 
OpenERP Technical Memento
OpenERP Technical MementoOpenERP Technical Memento
OpenERP Technical MementoOdoo
 
C++14 - Modern Programming for Demanding Times
C++14 - Modern Programming for Demanding TimesC++14 - Modern Programming for Demanding Times
C++14 - Modern Programming for Demanding TimesCarlos Miguel Ferreira
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
Ln monitoring repositories
Ln monitoring repositoriesLn monitoring repositories
Ln monitoring repositoriessnyff
 

Similaire à Keep your repo clean (20)

AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
 
Javascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxJavascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptx
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unit
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To Know
 
Pentester++
Pentester++Pentester++
Pentester++
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdfManaging Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
 
OpenERP Technical Memento
OpenERP Technical MementoOpenERP Technical Memento
OpenERP Technical Memento
 
C++14 - Modern Programming for Demanding Times
C++14 - Modern Programming for Demanding TimesC++14 - Modern Programming for Demanding Times
C++14 - Modern Programming for Demanding Times
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Ln monitoring repositories
Ln monitoring repositoriesLn monitoring repositories
Ln monitoring repositories
 
Object Oriented Programming using C++ - Part 1
Object Oriented Programming using C++ - Part 1Object Oriented Programming using C++ - Part 1
Object Oriented Programming using C++ - Part 1
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
C++primer
C++primerC++primer
C++primer
 

Dernier

SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxRTS corp
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxAS Design & AST.
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 

Dernier (20)

SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptx
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptx
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 

Keep your repo clean

  • 1. Keep your repo clean Héctor Canto @hectorcanto_dev
  • 2. ● Software Developer ++ ● Barcelona & Vigo ● @ Blueliv ○ CyberSecurity ○ Threat Intelligence ● Interested in ○ Best practices ○ Great documentation ○ Teach and Learn About me
  • 3. ● Maintenance ● Best practices ● Standards ● Auxiliary tools ○ Security ● Documentation ● Collaboration Topics Keep your repo clean
  • 4. Main ideas 1. Code, config, deploy and documentation matched together ○ joined through CI/CD and versioning 2. Code not only for yourself, but for others 3. Holistic view of documentation “Code is read much more often than written.” - paraphrasing Clean Code, Robert C.Martin (2008) Keep your repo clean
  • 5. Why maintaining a project ● “Future you” ● Collaboration ○ team-mates ○ non-tech colleagues (product, sales) ○ external workers ○ partners ● Holiday, medical leaves, bus factor & rotation ● Do to others what you hope they do to you “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Code for readability.” - John F. Woods (1991) Keep your repo clean
  • 6. I- Code, config and deploy Keep your repo clean
  • 7. They have some common folder and files > Let's build a template References - https://medium.com/worldsensing-techblog/project-templates-an d-cookiecutter-6d8f99a06374 - https://realpython.com/python-application-layouts/ - http://cookiecutter-templates.sebastianruml.name/ - PyConEs 2018 https://www.youtube.com/watch?v=Ttco5BTJI7I - PyBCN 2019 https://www.youtube.com/watch?v=TkrTM2Byj34 How a repo should look like Cookiecutter, Yeoman PEP-8, keepachangelog.com ├── $source/ ├── config/ ├── deploy/ ├── docs/ ├── requirements/ ├── scripts/ ├── README.md ├── CHANGELOG.md ├── setup.cfg ├── Makefile ├── docker-compose.yml └── sonar-project.properties Keep your repo clean
  • 8. Versioning ● Versioning is very useful ○ rollbacks, debugging, regressions ● It should span to: ○ Tags, Releases, Documentation ○ Artifact repositories (pkg manager, Docker registry) ● Major.minor.patch-prerelease.x+build#commit ○ 1.0.0-alpha.2+201303131abde44700 ○ 0.7.2-rc.5 bumpversion, Nexus (artifacts), CI/CD tools SemVer.org 1.0+, PEP-404 # setup.cfg [bumpversion] current_version = 1.2.3 commit = False tag = True tag_name = {new_version} [bumpversion:file:source/__nit__.py] [bumpversion:file:sonar-project.prop erties] # bash bumpversion patch --new-version 2.1.3 Keep your repo clean
  • 9. ● Should work out-of-the-box ● Templates ○ With comments and loops! ○ same template, multiple environments ● Infrastructure as Code ● Passwords out of repo # db.env POSTGRES_USER=dbuser POSTGRES_DB=dbname POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_PASSWORD=notadmin # db.env.j2 name: {{ db.schema_name|default('dbname') }} user: {{ db.user | default('dbuse') }} {# do not use same dbname and username #} host: {{ db.host | default('postgres') }} port: {{ db.port | default(5432) }} {%- if 'password' in db %} password: '{{ db.password }}' {%- endif %} Maintain a workable config Jinja2, direnv, docker, ConfigLoad IaC, YAML, .env Keep your repo clean
  • 10. Utils configuration: setup.cfg ● Keep your utils configurations together ● And the root of your folder lighter setup.cfg # setup.cfg [flake8] ... [pylint] ... [pep8] ... [coverage:run] ... [coverage:report] ... [coverage:xml] ... [coverage:html] ... [tool:pytest] ... Keep your repo clean
  • 11. Connect it all: Code, config and deploy ● A repository should have the means to be deployed ○ instructions in documentation ○ simple commands in Makefile, manage.py, scripts ... ● Code, config and deploy should match together in a point-in-time ● Strategy 1: all in one repo Strategy II: multi-repo ● CI/CD and config management tools join all together Python-Fabric, Chef, Puppet, Ansible, Salt, Terraform … IaC, DevOps, SRE Keep your repo clean
  • 12. Connect it all: branching and ticketing ● Ticket numbering ○ type-of-branch/functional-name-#PROJ-123 ■ feature, bugfix, release, docs … ■ what are you implementing here, don't repeat the ticket title ■ what ticket are you solving ● Versioning reference: ○ git - changelog - docker - docs - ticketing … ○ links on the wiki to the "latest", prevents obsolescence Any CI-CD tool, Git GUI Clients git-flow Keep your repo clean
  • 13. II - Code for others Keep your repo clean
  • 14. To be a good programmer you need to be a bit of a writer ● Be coherent and consistent ○ try: …. except SpecificException as exc: ● Answer some of the 6 'W' of journalism: ○ Who, What, Where, Why, When and hoW ● An image is worth more than 1000 words ○ Diagrams! Code style I class WhoService def what_i_do(p1, p2, p3) """ why I do this, and a bit how p1: where to p2: who p3: when or how often """ how_i_do_this() and_that() return what_you_need Keep your repo clean PlantUML, Draw.io, InkScape UML, SVG
  • 15. Code Style II 1. Avoid generic vocabulary, use specifics: a. Frontend app, API REST, auth service, TwitterAPIClient 2. Use collective nouns and adjectives: a. for choice in choice_options b. for element in selected_items c. for item in raw_params 3. Avoid custom abbreviations, use conventions. 4. Add a glossary to your project docs or to your wiki. https://hackernoon.com/software-complexity-naming-6e02e7e6c8cb “Vocabulary is not just a way of communication, it is a toolset. It evokes ideas, it enables abstraction and specification. But it also introduces implicit meaning, irony, sarcasm, hidden assumptions.” Keep your repo clean Sphinx-docs
  • 16. ● Main on top, detail out or below ● Don't put all code together, modules! ○ my rule of thumb 500 lines (200 even better) ○ 30 lines per method or function ● Follow a style guide ○ extend it with your own rules Code style III Writing Idiomatic Python (Jeff Knup), Google's pyguide black, flake8, pylint, Sonarqube, IDE plugins PEP-8, PEP-20 Keep your repo clean - Put the main function first, leave fine details to other methods - Use submodules and classes to order things and encapsulate logic together (in classes f.i.) - Use _ and __ to tip scope - import namespaces, not classes and funcitons, to give context
  • 17. Code style IV ● Know your Design Patterns ○ client-server, singleton, adapter, pub/sub, factory ... ● Follow well-known principles and practices: ○ Object Calisthenics ■ if-else inversion ○ SOLID, KISS, DRY, YAGNI… ○ Learn about DDD https://sourcemaking.com/ https://williamdurand.fr/2013/06/03/object-calisthenics/ # SOLID S: validate_filter_transform_and_upload O: BaseClass, CoolMixin, HigherOrderComponent LD: func1(data, param1, param2) func2(data, param2, param1) I: def func3(injection1, injection2): that = injection1.search(this) injection2.save(that) Keep your repo clean
  • 18. Comments and docstrings ● Do not comment everything ● Use triple-quote comments ● Save comments and docstrings with good naming ● Type hinting! Python 3.5+ ● Follow a docstring standard: ○ reST, numpy, Google, Epytext """ This is a multiline comment """ """ This is a Google docstring Args: param1 (int): The 1st parameter. param2 (str): The 2nd parameter. Returns: bool: The return value. True for success, False otherwise. Raise: TypeError: parameters are wrong """ http://daouzli.com/blog/docstring.html PEP-257 Keep your repo clean
  • 19. Security Tools ● Safety (pyup.io) ● Docker Image scans: Clair, Trivy ● Docker secrets (Swarm, K8S) ● Ansible Vault ● SonarQube ● git-crypt ● KeePassXC ● Training, training and training Keep your repo clean
  • 20. III - Documentation purposes Keep your repo clean
  • 21. Documentation goals ▪ Explain implementation ▪ extension of the code ▪ Explain purpose ▪ Give context ▪ Evolution traceback ▪ Explain how to work together ▪ the framework ▪ Explain decisions Keep your repo clean
  • 22. Extended documentation In order of scope - Code itself - Comments - Docstrings - Tests - Commit log - Dev docs - +ADRs (next slide...) - API specification - GUI helpers (tooltips, inline help) - Tickets or Stories - Project wiki - User docs - FAQ Who reads the documentation: - You - Future you - Your team - Other devs - Other colleagues - Marketing, customer support ... - Managers - Partners - Customers - Users Keep your repo clean
  • 23. Architecture Decision Records (ADR) ● Higher scope: architecture and software design ● Explain expectations ● State pros, cons, expected benefits and risk ● Write down agreements and compromises ● Re-evaluation and self-evaluation: ○ why we use such language, framework or design ADR Template # Intro ## Author, Approvers, links # Context and problem statement # Decision ## Drivers, Considered options ## Outcome # Pros and expected benefits # Cons and potential risks # Possible improvements # Links to other ADRs Keep your repo clean thoughtworks.com/radar/techniques/lightweight-architecture -decision-records ADR templates: https://adr.github.io
  • 24. Extended documentation caveats Caveats: - Maintenance - obsolescence and inconsistency - Redundancy - Different scopes - departments, docs audience - Out of one own responsibility - Beware of Agile principles: - “Working SW first” - Not good for small projects Solutions and mitigations: - Documentation owner and/or docs committee - Automation - Documentation as Code - One source of truth - Bug-bashing for docs - Spread Domain language across teams and projects (DDD) Keep your repo clean
  • 25. ● Keep code, config and deploy synced with Versioning ● Think on the "future you" ● Write code for others ● Use tools, standards and automatization to your benefit ● Code explains implementation, documentation explain purpose ○ and gives context ● Consider the "extended" documentation Summary Keep your repo clean
  • 26. Thanks for your attention! Questions? Héctor Canto @hectorcanto_dev hectorcanto WE'RE HIRING
  • 27. Specifics ● Repo structure and maintenance ● Versioning ● Config ● Deploy artifacts ● Test ● Security ● Code style ● Extended Documentation
  • 28. Each of the following topics may be extended to a full talk. We will keep things high level. All icons, images and graphs are made by me, opensource or free-to-use: https://icons8.com https://unsplash.com/ InkScape & GIMP Disclaimers
  • 29. Deploy A repository must have the means to run the software it represents ● Commands to simplify the process ○ Makefile, manage.py, Ansible ● Means to deploy: Docker, python-fabric, Ansible, Terraform… ● Consider several environments make, Ansible, fabric, Terraform, Docker ... IaC
  • 30. ● Spend time testing ○ a lot initially, it is worth it ● Understand the different aspects of test ○ Cost ○ Unicity ○ Intention ○ Box-style ● A test can have several aspect at once ○ Unitary tests usually are cheap, white-box, non-integrative ... ○ Sometimes they may have some “integration” side ● Understand the test pyramid analogy unittest, pytest, mock, hypothesis, Postman ... TDD, BDD Tests
  • 31. More ‘doc’ tools - Swagger (OAI) - Django Rest Framework browsable API - Any Wiki - Ticketing System - Bug Tracking System - Support forum and FAQs Reference one to each other
  • 32. To be a good programmer you need to be a bit of a writer ● Be coherent and consistent ○ try: … except SpecificException as exc: ● Answer some of the 6 'W' of journalism: ○ what, how, why, when, where, who ● An image is worth more than 1000 words ○ Diagrams! ● Don't put all code together, modules! ○ my rule of thumb 500 lines (200 even better) Code style Keep your repo clean