Build it, Break it, Remake it

After all the work and sweat put into making my Python output look good, the time has come to tear it apart and rebuild.

Why?

Because the code is a disorganized mess. Functions and variables were created on the fly without any future-looking structure. There is no sustainable way of going forward with it. Much as it hurts, it's time to throw away the original baby with its dirty bath water and begin again.

I owe part of my courage to this guy, Pete the Web Developer. He encourages us to build before we're ready and to learn from our mistakes.


What was my number one mistake?
(1) I didn't organize my code into logical modules.
Mainly because I was afraid of making my own modules.
Turns out my fears were misplaced. "Module" is merely a fancy alias for a (dot) Py file. You put some variables and/or functions into a separate Py file and suddenly it's a "module".  Afzal teaches how to store global variables and retrieve them where needed here: (global vars). Pgmming_4_Devs teaches in slow detail how to do modules here: (math.pi) And after that about "packages" here (a bunch of module files).

(2) I didn't realize that I need to structure the names of my variables. What does that even mean? My project aims to present a bunch of demonstration frames to the user that demonstrate various Python methods. More specifically in one case, Learning_List_Methods. Each demonstration frame starts with a Title Box that has a middle message line braced above and below with a string of asterisks ("************").

    (2a) Then under the Title Box is a list of statements, each being a printout of an f-string. In order to organize these statements, I plan to form a program-defined message_name having the format of message_type + frame_id + line_id, where the latter three are program defined strings that are concatenated to create a message_name as a string, say intro_messg_f02_l03 where f02 is the frame idntification, l03 is the line number and intro_messg is the message type.

    (2b) Next, at least for now, I plan to use the Python exec(method) [See here] to create a string that says "print(message_name)" as the argument inside the exec() function. A for loop can iterate through a list of line numbers (e.g. Lij) so as to automatically generate a listing of printed out statements.

    (2c) Finally, I plan to have separate modules named messages.py, funcs.py and vars.py where the first module stores my structurally-named message strings, the second stores my functions and the third store color escape codes and other such variables used in the main or other modules.


(3) Planning is one thing. Doing is another.
Right now I have a long road ahead of me to start jogging down.

MORE TO EXPLORE
Pete the Web Developer -- 12 Learn to Code Tricks That Would’ve Saved [you] MONTHS -- (here)

Tech w Tim -- What does '__init__.py' do in Python? (here)
Tech w Tim -- Top 18 Most Useful Python Modules (here)
Data Engineer -- Unlocking Python: Functions & Modules Explained -- (here)

 

Comments

Popular posts from this blog

Links for Python Noobs

Everything From Everywhere All At Once -- Doesn't Fly

I Lied