How to define the programming language --- Python --- we've been using all through the course? l looked it up on Wikipedia and it said:"Python is a widely used general-purpose, high-level programming language. It supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles." Though python supports many kinds of programming paradigms, what we've always been using until now is object-oriented programming style.
Object-oriented programming is a specific programming style mainly based on "objects". Basically all the types in python: "int", "str", "list"..., all of these are objects. The functions that can be called on a certain type of object are called methods. Sometimes we create types with certain characteristics to make our programs more efficient. These types are called classes.
By using classes we can maintain our program and test the functions far more convenient than simply using help functions. As professor Danny said in the lecture, if we want to design a program (a game in the lecture), first we write a class with some generic attributes (certain kind of attributes shared by all instances) and we only need to write a subclass for all the different attributes under different considerations. In this way we can avoid maintaining many codes at the same time and achieve a high level of efficiency. If we want to test for different cases, it's also better to use unittest than doctest, especially when it's hard to write down examples in docstring.
No comments:
Post a Comment