Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General questions
#1
Prologue::: 
Old guy here... been doing I.T. (Networking) for over 25 years now... and for the most part had a "scripter" on the team, so I never HAD to learn*.
written a few Bash scripts when needed, but nothing substantial. 

So here's a few questions, and simply looking for best practices or tricks of the trade etc...not expecting finite answers.

1) Context switching
So, I'm not writing code most of the day;  again, I'm neck deep in OSPF & BGP and VPNs, all day etc.  So when I work (code) on my little app, I'm finding I forget "where I'm at".  Did I leave the code in a working state? What section of code was I working on last...shoot -- what issue/problem (business/project-wise) was I working on?

Now it seems obvious I could jot down in a notepad these things, but often, as it's not my primary gig, I'll get distracted/interrupted/sleepy, pick one...and I'll simply hit save, and close the lid of the laptop.

It's possible that due to it being "new", the learning curve, etc...that this will get better simply by coding more...but I'm finding my tricks for networking context-switching don't seem to be as effective for coding.   And yes, I am commenting as I go (otherwise I'd be at a total loss).

2) Saves
How often do you pick up code from yesterday, write, edit, erase code, etc and save it to a new filename ?  Depends? (on amount of change)?  3 times a day, 30 times?  For networking, it's typically a "live" system.  I'm not constantly tweaking an OSPF configuration for the same network.    Again, not really looking for a singular answer, but what's common practice, or what's worked for you.

3) Rewrites
I've found myself coming back the next day, looking at my code and thinking -- yea it works, but I think there's a better way to code piece-X  -- and then spending the night on rewriting code that previously was working (maybe not elegantly) rather than moving on to the next piece of the puzzle.  Good thing or finish the damn project then look at improvements/efficiencies?

General questions but after a week of python, #1 & 3 I feel are possibly hindering progress, and #2 came about because I was sooooo happy that a function I wrote & saved in save-3, then nuked in edit-4 and needed in edit-19 was there in a file #3.

Thanks,
PappaBear
* actually learned basic & pascal on Commodore-64  :-) but that was in 83 and doesn't count.
Reply
#2
Also old dude here (been at it 50 years (next year))
Kilobaud Magazine Author during the 70's

1) Context switching
If you use PyCharm as an ide, you can add a todo comment where you
want to pick up. Then just check todo list
This is simple -- just add the following line to your code:
# todo - pick up here
Other IDE's probably have a similar option

Every morning I back up what I'm working on
And save before I quit

Rewrites - Keep your code in manageable pieces (functions or methods)
and keep different subjects in different modules (import where needed)

Now your rewrites will usually be at the method level.
Before you start, rename the original module and make a new copy with the original name
In addition, comment out the old method and keep until the new one is behaving properly.
Reply
#3
2) Answer might be never - if you have 19+ versions of single file saved with a different suffixes, then its high time to start using version control system (nowadays its often git). With version system saving new version of a file is "cheap", so you can (and should) save your file after every "major" change. You wont have directory full of dozens versions of same file and with meaningful commit messages and possibility to compare changes its much easier to track your changes or revert to some previous version.
Reply
#4
Also an oldie (65) but new to Python.  I use Pycharm, so as was pointed out, I use the TODO option to help me keep on track.  As was also mentioned, when improving code, I comment out the old code, then remove it once the new code proves itself worthy.  Another way I do it is to have a 'scratch' file that I use to test new code before moving to the real file.  I also keep a command terminal opened to my working directory in case there is something that won't work properly in Pycharm's terminal, but does in a regular command window.  So I usually have three things opened when coding: command window, scratch file and real file (note the last two are tabs in Pycharm).  I haven't really found a need to make backups of my files (except when I do my weekly system backup).
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
Many thanks everyone! I was using NotePad++ (as I use it for all my networking stuff) with the NppPython plugin...

D/L Pycharm now :-)
Reply
#6
Nothing wrong with Npp, I use it also, though usually for small edits or reading a file.  I just find Pycharm easier.  There are other IDE's as well, in fact I'm trying out "Geanie" on a Raspberry Pi, not to impressed do far though. :-)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#7
PyCharm scares me with those hundreds buttons  Cry
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#8
(Apr-11-2017, 05:40 PM)wavic Wrote: PyCharm scares me with those hundreds buttons  Cry

Me too, but I found that I really only need or want to change 3 things in Default Settings:
  1. Font (Input Mono for Windows, leave as default for Linux)
  2. File encoding (utf-8)
  3. Interpreter (for Windows it's 3.6.1, for Linux it's 3.4) (I don't use 2.x on either system, but it can be done using a combo of default settings and file settings)
Other than that, about all I use is the "Make New Project", "Make New File" and the "Run".  There are indeed many more things it can do and perhaps someday I'll take the time to learn some of them.  Angel (maybe)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#9
(Apr-11-2017, 07:59 PM)sparkz_alot Wrote: Other than that, about all I use is the "Make New Project", "Make New File" and the "Run".

i still after all these years just use Vim and the terminal to execute. I prefer to not have to touch my mouse at all between coding and running. Maybe if i used tiling window managers i could just throw my mouse out for good.  Think
Recommended Tutorials:
Reply
#10
Once you get use to PyCharm you'll love it.
Also Highly recommended is Atom: https://atom.io/
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020