01 - Introduction To Computation and Programming
01 - Introduction To Computation and Programming
Python
Python 101 for Economists
José Moreno
[email protected]
Data Lead
1
1. Introduction to Computation and Python
2
1. Introduction to
Computation and
Python
What is programming?
3
Programing definition
● Cambridge Dictionary:
○ The activity or job of writing computer programs.
○ The process or skill of writing programs for computers.
○ The instructions that tell a computer what to do.
● LLMs:
○ Creating instructions for a computer to perform tasks.
○ Programming is the process of writing instructions in a specific language to enable a computer to
perform tasks and solve problems.
○ Programming is the process of creating instructions for computers to follow.
4
Programming process
(4) (5)
🕹 📲
Testing and debugging Deployment
5
Problem identification
● Repetitive tasks: If a task is performed frequently and follows a consistent
pattern, it's often a good candidate for automation through programming
● Data processing: Problems involving large amounts of data that need to be
sorted, analyzed, or transformed are well-suited for programming solutions
● Complex calculations: When a problem requires numerous or intricate
mathematical operations, programming can provide accurate and quick results
● Decision-making based on conditions: If a process involves many if-then
scenarios, programming can efficiently handle these logical structures
● Information management: Storing, retrieving, and organizing large amounts of
information can be effectively managed through databases and programming
6
Problem identification
● Information management: Storing, retrieving, and organizing large amounts of
information can be effectively managed through databases and programming
● User interaction: If there's a need for users to interact with data or systems in a
specific way, programming can create user interfaces and manage these interactions
● Real-time monitoring and responses: Problems requiring constant monitoring and
quick responses to changing conditions are often solved through programming
● Simulation and modeling: Complex systems or scenarios that need to be simulated
can be addressed through programming
● Integration of different systems: When there's a need to connect or communicate
between different software or hardware systems, programming is often the solution
● Customization of existing software: If off-the-shelf software doesn't quite meet
specific needs, programming can be used to create custom solutions or extensions
7
Solution design (architecture or algorithm)
● Break down the problem:
○ Divide the main problem into smaller, manageable sub-problems
○ Identify core functionalities needed
● Research existing solutions:
○ Look for established algorithms or design patterns that might apply
○ Consider best practices in the relevant domain
● Outline the algorithm or system architecture:
○ Sketch a high-level flow of the solution
○ Define main components and their interactions
○ Select data structures that efficiently represent and manipulate the required information
● Consider efficiency and scalability:
○ Analyze time and space complexity
○ Plan for potential future expansions or modifications
8
Solution design (architecture or algorithm)
● Plan for error handling and edge cases:
○ Identify potential failure points
○ Design robust error handling mechanisms
● Document the design:
○ Create flowcharts, pseudocode, or UML diagrams
○ Write clear explanations of key components and their functions
● Review and refine:
○ Critically evaluate the design
○ Seek feedback from peers or stakeholders
● Consider testing strategies:
○ Plan how to verify the correctness of the solution
○ Design test cases covering various scenarios
9
Implementation (writing code)
● Development environment: Appropriate Integrated Development
Environment (IDE) or text editor and necessary compilers or interpreters for
your chosen language
● Programming language: Select a language suitable for your project (e.g.,
Python, R, Java, C++, JavaScript, Matlab, …)
● Version control system: Tools like Git for tracking changes and collaborating
● Libraries and frameworks: Relevant pre-built tools to aid development
● Coding standards: Established conventions for naming, formatting, and
structuring code
● Documentation practices: Methods for inline comments and external
documentation
10
Implementation (writing code)
● Testing tools: Unit testing frameworks, Integration and system testing tools
● Debugging tools: Debuggers integrated with your IDE or standalone tools
● Performance profiling tools: For identifying bottlenecks and optimizing code
● Knowledge of algorithms and data structures: Understanding of how to
implement efficient solutions
● API documentation: If interfacing with external services or libraries
● Error handling strategies: Techniques for graceful error management and
logging
● Security considerations: Understanding of common vulnerabilities and how to
mitigate them
11
🕹Testing and debugging
Why in programing?
12
🕹Testing
● Purpose:
○ Verify that code works as intended
○ Identify bugs and errors
○ Ensure software meets requirements
● Types of testing:
○ Unit testing: Testing individual components or functions
○ Integration testing: Testing how components work together
○ System testing: Testing the entire application
○ Acceptance testing: Verifying the software meets user requirements
● Test-Driven Development (TDD):
○ Writing tests before writing code
○ Helps clarify requirements and design
● Automation:
○ Using scripts to run tests automatically
○ Enables frequent testing and continuous integration
● Coverage:
○ Measuring how much of the code is exercised by tests
○ Identifying untested parts of the code
13
🕹Debugging
● Purpose:
○ Identify the cause of errors or unexpected behavior
○ Fix issues in the code
● Techniques:
○ Using debuggers to step through code execution
○ Adding print statements to track program flow
○ Analyzing log files
● Types of bugs:
○ Syntax errors: Incorrect language usage
○ Logic errors: Flawed algorithms or decision-making
○ Runtime errors: Issues that occur during program execution
● Debugging tools:
○ Integrated debuggers in IDEs
○ Memory profilers
○ Stack trace analyzer
● Strategies:
○ Reproducing the error consistently
○ Isolating the problem area
○ Using binary search to narrow down the issue
14
📲Deployment
● Purpose: Process of making software available for use.
● Key Components
○ Code packaging and dependency management
○ Environment configuration
○ Database migrations
○ Infrastructure setup
● Deployment Strategies
○ Manual deployment
○ Automated deployment (CI/CD)
○ Blue-green deployment
○ Canary releases
● Essential Tools
○ Version control (e.g., Git)
○ Containerization (e.g., Docker)
○ Orchestration (e.g., Kubernetes)
○ Cloud platforms (e.g., AWS, Azure)
● Why It Matters
○ Bridges development and production
○ Ensures real-world functionality
○ Enables rapid updates
○ Maintains application reliability
15
Apply the programming process to solve a problem you
want to solve... right now!
16