Author Topic: Teach yourself, teach others... with comments  (Read 3595 times)

0 Members and 1 Guest are viewing this topic.

nivuahc

  • Guest
Teach yourself, teach others... with comments
« on: April 24, 2005, 09:19:38 AM »
A dear friend and I were having a discussion just the other day about teaching. And we both agreed that, the thing about teaching that was so appealling was that, as a teacher, you often learn more than the students.

You can easily see how this is so by doing a little teaching yourself. And you can do that teaching by way of commenting your code.

First, let me give you a little background. I worked for a few years at a major oil company as their lead AutoCAD developer. I inherited a bunch of routines and code that had very little, if any, commenting at all. I had no idea what was being attempted most of the time and I spent the majority of my time isolating bits and pieces of code and figuring out the big picture one puzzle piece at a time. It was a wonderful learning experience but it was also a nightmare. And, to make matters worse, the guy who had the position before I did had a habit of naming his variables and his functions like this
Code: [Select]
(defun doit ( / a b c d)
There is no way I could have done my job without commenting his code. As I would figure out one piece of the puzzle, I would comment it, and move on to the next. That changed the way I looked at writing comments altogether.

The approach I take when I write comments in code (which, admittedly, isn't often enough) is this: Someone might be looking at that code a year from now trying to figure out what on earth I was trying to accomplish. And that person might not have the same skill level as I did (although that's not very likely) or that person may be new to LISP and my approach may confuse them... so I do my best to explain, in my comments, exactly what I was thinking and why. The approach that I took and why I took it. And, more often than not, my comments make up more than 50% of the text on the page.

That's good for a couple of reasons... first, and foremost, it gives a step-by-step road map of my thinking process when I wrote the code. Later, usually many months or years later, when I look at a bit of code I wrote, I can easily get right back on that train of thought. It also makes it fairly simple for someone else who might be reading it, to understand what is going on and why. If they don't fully grasp a concept, it's usually laid out pretty well in my comments. They can learn from my code and my mistakes. It can get them thinking on a similar track and, possibly, shed light on a problem that they may be having.

The biggest benefit to writing descriptive comments is that it helps you, the person writing them, to understand your code better. It usually ends up encouraging me to improve my already working code, because I'll realise that I could have done something better. It also points out mistakes in my code because, when I'm explaining it in the comments, it isn't until then that I'll realise that a particular piece of what I wrote wasn't necessary.

I've learned more from commenting my own code (and that of others) than you might believe. It's a valuable tool for you and everyone else.

When you take the time to comment your code in a thorough manner you are helping to teach others and you are helping to teach yourself.

I encourage you to make it a practice of yours, the benefits are well worth it.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Teach yourself, teach others... with comments
« Reply #1 on: April 24, 2005, 09:30:37 AM »
Indeed, good stuff Chuck.

Disable "Shrink large images to fit in browser", then lookie here:

http://www.theswamp.org/screens/mp/code.png

PS : You might get a kick out of the StringReverse function near the bottom.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

nivuahc

  • Guest
Teach yourself, teach others... with comments
« Reply #2 on: April 24, 2005, 11:21:56 AM »
That's sweet lookin' code Bro. :)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Teach yourself, teach others... with comments
« Reply #3 on: April 24, 2005, 07:12:17 PM »
Quote from: MP
... Disable "Shrink large images to fit in browser", ...


IE6: Options->Advanced->Multimedia->"Enable Automatic Image Resizing"
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Teach yourself, teach others... with comments
« Reply #4 on: April 24, 2005, 07:30:28 PM »
Firefox 1.x:

Options -> Advanced -> Resize large images to fit in the browser window.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

nivuahc

  • Guest
Teach yourself, teach others... with comments
« Reply #5 on: May 04, 2005, 01:00:56 PM »
I just read/heard this and thought that it was actually quite fitting to this thread. I thought I'd share

Quote from: Douglas Adams
"What I mean is that if you really want to understand something, the best way is to try and explain it to someone else. That forces you to sort it out in your own mind. And the more slow and dim-witted your pupil, the more you have to break things down into more and more simple ideas. And that's really the essence of programming. By the time you've sorted out a complicated idea into little steps that even a stupid machine can deal with, you've certainly learned something about it yourself. The teacher usually learns more than the pupil. Isn't that true?" -- Richard MacDuff (Dirk Gently's Holistic Detective Agency)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Teach yourself, teach others... with comments
« Reply #6 on: May 04, 2005, 01:03:05 PM »
=> Brilliant <=
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Teach yourself, teach others... with comments
« Reply #7 on: May 04, 2005, 01:13:06 PM »
Quote from: MP
Disable "Shrink large images to fit in browser", then lookie here:

Mind if I ask how you got all that into a .png file? I know it wasn't a screen shot.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Teach yourself, teach others... with comments
« Reply #8 on: May 04, 2005, 01:21:56 PM »
I wish I could find the comment by V. Nesterovsky over at adesk about commenting your code, if memory serves it said something like "Well written code needs little commenting".

Great post Chuck!!
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Teach yourself, teach others... with comments
« Reply #9 on: May 04, 2005, 01:26:01 PM »
Quote from: Mark Thomas
Quote from: MP
Disable "Shrink large images to fit in browser", then lookie here:

Mind if I ask how you got all that into a .png file? I know it wasn't a screen shot.

Multiple screen shots dovetailed.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Teach yourself, teach others... with comments
« Reply #10 on: May 04, 2005, 01:32:35 PM »
Quote from: MP
Multiple screen shots dovetailed.

Thank ya sir ... :)
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Teach yourself, teach others... with comments
« Reply #11 on: May 04, 2005, 01:36:31 PM »
PS: Easy in PSP.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Teach yourself, teach others... with comments
« Reply #12 on: May 04, 2005, 01:41:21 PM »
I was wondering the same thing ....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie