Developer Week 047
Courses
Boot.Dev Back-end Developer Career Path (~53.04%) (š +1.36%)
10. Build a Maze Solver DONE
10.4.0 Drawing Some Lines
Learned the difference between self.variable
and self.__variable
GPT
The choice between
self.__variable
andself.variable
in Python class design reflects intentions around visibility, encapsulation, and internal use.
self.variable
ā Public attributeself._variable
ā Protected (by convention only)self.__variable
ā Private (name-mangled)
I think I was supposed to know this already, but clearly forgot.
11. Learn Memory Management (26/101 modules)
11.2.3
In C, splitting code into files likeĀ coord.c
,Ā coord.h
, andĀ main.c
Ā is a practice calledĀ modular programming. Hereās how each file serves a distinct purpose:
coord.h
Ā (Header file):
This file declares the structures and function prototypes (signatures) of your coordinate utilities. By including it in other files, the compiler knows about your types and functionsāeven if their actual implementation is somewhere else.
For example, it tells the compiler āthereās a function calledĀ scale_coordinate
Ā that returns aĀ struct Coordinate
."
coord.c
Ā (Implementation file):
This implements (defines) the functions declared inĀ coord.h
. All the logicāthe instructions for struct manipulation and coordinate mathālives here.
By separating this from the header, you can change how functions work without breaking code that calls them, as long as you keep the interface the same.
main.c
Ā (Driver/test file):**
This is the entry point: it contains theĀ main()
Ā function and any code to run your program or tests. It relies on the declarations inĀ coord.h
Ā and the real code inĀ coord.c
.
Why does C do this?
- It keeps code organized and easier to maintain.
- It allows teams to work on different parts independently.
- It helps prevent “duplicate symbols” and other compilation errors.
In summary:
- Header files declareĀ whatĀ exists,
- Implementation files defineĀ howĀ things work,
- Main (or other) files use these pieces to create the program’s behavior.