Day 1: Git and Object Oriented Programming

Day 1: Git and Object Oriented Programming#

Note

Do not use AI tools to complete the exercises. The goal is to learn how to write code yourself, not to rely on AI tools.

Learning Goals#

  1. Name the best practices in scientific programming and list methods to achieve them.

  2. Write a class in Python using object oriented programming.

  3. Name the components that a well-structured Python project should have.

  4. Explain the concept of branches in Git.

  5. Create a merge request in Gitlab.

Repetition#

  • Fundamentals of Git

  • What is object-oriented programming?

Coding Goals#

We will write a simple class in Python that represents a line in a 2D space. We will then extend this class with methods to calculate the length of the line, move it, and store additional information. Finally, we will create multiple random lines and visualize them.

Preparation#

  1. Clone the Gitlab repo https://courses.gistools.geog.uni-heidelberg.de/advancedgeoscripting/advanced-geoscripting and setup the Python environment following the setup instructions in the README.

  2. Create a branch named with your name.

Line class#

You don’t have to finish all tasks, just see how far your get. If you need help, here is a short overview on object oriented programming with a simple example: Object-oriented programming

  1. Write a simple class called “line”. The class should have an x and a y value for both the start point and the end point.

  2. Create a line object.

  3. Add a method returning the length of the line. Apply it to your line object.

  4. Add a method returning the x and y coordinates of the start point and end point as a list. Apply it to your line object.

  5. Add a method to move the line by a given delta x and delta y. Apply it to your line object.

  6. Add an attribute to store a name or ID for the line.

  7. Create 10 different random lines on a 50 by 50 grid and plot them.

Push your changes#

  1. Push your changes to Gitlab and create a merge request.