Hi. I'm Jason Meridth. I'm a continuously learning senior software developer/team lead/development manager trying to not let best be the enemy of better. I reserve the right to change my mind after obtaining more information. PGP Key
Afer you log into an ubuntu instance you’ll usually see something like this:
I have logged into many ubuntu servers in my time and today I finally looked up how the information that displays gets generated and displayed. I’ve used /etc/motd aka message of the day many times before but I noticed tha file doesn’t exist in a vanilla Ubuntu install. There are two main commands that are populating the information shown at login.
TL;DR We are all continually improving. Don’t forget that.
Recently I’ve been hearing more and more developers say stuff like “Wow, what was this person thinking when they wrote this?” or “Really? Sigh…..”. Don’t get me wrong. I’ve been guilty of this also. I am writing this post to remind myself and other developers that if you could, you would say those things to yourself of six months ago or even yesterday. We are all continually improving and we started writing bad, inexperienced code just like some of the code your reading now. I also saw someone say “Bad code doesn’t immediately become bad; it happens over time, gradually.” (thanks Sharon) That is true.
I like the quote:
Write code as if the person who will maintain
it is a psychopath and he/she knows where you live
I’ve also told developers recently that I read more code than I write. Yeah, maybe some of you just churn it out like you exhale but that isn’t me. That doesn’t mean I don’t produce, but I actually read code for fun. I am always reviewing code for work and side jobs, but I’m also reading open source library code for projects that I use or plan to use so that I can understand how they work and also to learn. Some people read books or newspaper articles. I read source code.
I am absolutely not passing judgment on anyone. There is a fine line between ignorance and lack of intelligence. Ignorance means the person is unaware/hasn’t been taught/etc. Lack of intelligence means that no matter how many times that person is taught they will never grasp the subject. This includes multiple ways of teaching the same subject matter. When you read those developer’s code, you will sigh. But…you should still add comments to their code and end it with something like “wdyt?” (wdyt == what do you think?). You present them with your perspective but aren’t forcing it on them. Maybe someday it will click. Maybe not. That’s not up to you. If they are destructive to the code, then that is a subject for another post. :)
I have been using the Python Debugger aka pdb docs for 2.7/docs for 3.5 a lot recently and wanted to share a cheat sheet I found and also the common commands I use.
The easiest thing to do is put the following in your code somewhere:
import pdb; pdb.set_trace()
Then when you run it, it will stop there and you can step through the code a line at a time. The l(ist) command will show you 11 lines of code around the current line is the one I use the most. s(tep), n(ext), r(eturn) are some other I use regularly.
Once the debugger is up, you can check the stacktrace w(where), variable values a(rgs) or [variable_name] or many other things. Please check the documentation or the cheatsheet image above.
A much more in-depth usage of pdb can be found here