More on this book
Community
Kindle Notes & Highlights
by
Cory Althoff
Read between
May 19 - May 26, 2023
You are not reading this book because a teacher assigned it to you, you are reading it because you have a desire to learn, and wanting to learn is the biggest advantage you can have.
think of an object as a data value in Python with three properties: identity, data type, and value.
Python allows you to use code from one module in another module.
if __name__ == "__main__":
To program professionally, you need to learn either the object-oriented or functional programming paradigms.
State is the value of a program's variables while it is running.
As your program grows in complexity, the number of global variables in it increases.
Classes are a mechanism for the programmer to classify and group together similar objects.
Every object is an instance of a class.
A suite in a class can be a simple statement or a compound statement called a method.
Any method surrounded by double underscores, like __init__, is called a magic method: a method Python uses for special purposes like creating an object.
class Orange: def __init__(self, w, c): self.weight = w self.color = c print("Created!") or1 = Orange(10, "dark orange") print(or1)
class Rectangle(): def __init__(self, w, l): self.width = w self.len = l def area(self): return self.width * self.len def change_size(self, w, l): self.width = w self.len = l
A disadvantage of object-oriented programming is that creating programs takes extra effort because a great deal of planning is often involved in designing them.
Instance: Every object is an instance of a class. Every instance of a class has the same type as all the other instances of that class. Instance variables: Variables that belong to an object.
"Good design adds value faster than it adds cost." —Thomas C. Gale
There are four main concepts in object-oriented programming: encapsulation, abstraction, polymorphism, and inheritance. Together, they form the four pillars of object-oriented programming.
Private variables and methods are useful when you have a method or variable that your class uses internally, but you plan to change the implementation of your code later (or you want to preserve the flexibility of that option),
In Python, if you have a variable or method the caller should not access, you precede its name with an underscore.
Polymorphism: Polymorphism is "the ability (in programming) to present the same interface for differing underlying forms (data types)."
Composition: Composition models the "has a" relationship by storing an object as a variable in another object.
"Treat your code like poetry and take it to the edge of the bare minimum." —Ilya Dorman
In Python, classes are objects.
Class variables belong to the object Python creates for each class definition and the objects they create.
Simple is better than complex. Complex is better than complicated.
Easter egg: A message hidden in code.
"Every programmer is an author." —Sercan Leylek
"The magic of myth and legend has come true in our time. One types the correct incantation on a keyboard, and a display screen comes to life, showing things that never were nor could be..." —Frederick Brooks
A stack is a data structure. Like a list, you can add and remove items from a stack, except unlike a list, you can only add and remove the last item.
Unlike a stack, where the first item put in is the last out, a queue is a first-in-first-out data structure (FIFO):
The built-in time module has a function called time. It returns a float that represents the number of seconds it has been since the epoch, a point in time (January 1st, 1970) used as a reference.
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." —John Woods
The Pragmatic Programmer by Andy Hunt and Dave Thomas,
Two or more things are orthogonal if changes in one do not affect any of the others. In a well-designed system, the database code will be orthogonal to the user interface: you can change the interface without affecting the database, and swap databases without changing the interface."
Limiting functions to accomplishing one task offers several advantages. Your code will be easier to read because the name of your function will describe exactly what it does.
Logging is the practice of recording data when your software runs.
"Untested code is broken code."
There are a few programming books that are considered must-reads. The Pragmatic Programmer by Andy Hunt and Dave Thomas; Design Patterns by Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm (design patterns are an important subject I didn't get a chance to cover); Code Complete by Steve McConnell; Compilers: Principles, Techniques, and Tools, by Alfred Aho, Jeffrey Ullman, Monica S. Lam, and Ravi Sethi; and Introduction to Algorithms by the MIT Press. I also highly recommend Problem Solving with Data Structures and Algorithms,
Get on LeetCode and practice those algorithms.
Don't stop at just one answer, read all the explanations on a topic you can find. Ask questions and read differing opinions online.
Reading other people's code is going to be difficult at first, but it is important because you can learn so much from other programmers.