jump to navigation

You might be an engineer if… April 30, 2015

Posted by mareserinitatis in computers, engineering, research, science.
Tags: , , , , ,
add a comment

I know engineers have quirky personalities.  There are these things that most people take for granted that drives other people nuts…and vice versa.  The engineer will spend hours fixing something so it works just perfectly while others don’t care as long as it’s functional.

I realized lately that one of my big pet peeves has been programming languages.  Okay…that’s not just lately.  But still.  It really amazes me how you can do something so simply in one language but it’ll take you days to figure it out in another language.  I’ve been beating my head against this a lot lately.  While I learned programming a long time ago, as I went through my education, I learned other languages that had been optimized for working with certain types of problems.

So what am I dealing with now?  Languages that were among some of the first that I learned, and their offspring.

I have decided that I will be switching to do some of my work in another language, maybe even learning a new one that supposedly has a low learning curve.  On the other hand, I have to admit that my frustration certainly helps me to recognize the brilliance of the people who did all of their work in these languages.  The engineer in me can’t help but think the languages are clunky and inefficient.  I can’t be completely wrong, though: if they weren’t no one would’ve bothered to come up with new ones.

Does this make me multilingual? July 16, 2013

Posted by mareserinitatis in computers, electromagnetics, engineering, grad school, math, physics, research.
Tags: , , , ,
3 comments

I began my programming education quite young and have maintained my skills over the years.  I have recently been thinking of documenting some of the various languages and software programs I’ve learned to use, so here is as good a place as any.

  • 4th grade – TI Basic
  • 8th grade – Logo
  • 10th grade – BasicA and Apple Basic (pretty close to the same thing)
  • 12th grade – Fortran and QBasic (these were at the college)

In college:

  • took a class on C and had to learn unix, too
  • learned Maple in a calc course
  • learned matlab for a research project and used it extensively in a numerical analysis course
  • learned mathcad for a physics lab course
  • learned mathematica for intro to differential equations and used that for many other classes

During my MS, I was exposed to half a dozen software packages for computational electromagnetics modeling (half of which are trademarked, so I’m not going to bother listing them).

In the past couple years at work, I’ve gotten pretty handy with Scilab.

After all of this, you would think that I have a pretty complete toolkit.  I should be able to do pretty much whatever I need with what I’ve already learned.  I find it ironic, therefore, that I am back to using Fortran (one of the first things I learned).  I also have been spending the past month trying to learn IDL (which, if you don’t mind me saying, seems like a less friendly version of matlab), so there is something new, again.  Also, I have people pestering me to learn python.

Looking at this list, I’m starting to think I’m learning things so that I can simply forget them again later.  I’m pretty sure I’ve forgotten more than I remember.

Doesn’t anyone ever comment any more? June 26, 2013

Posted by mareserinitatis in computers, research.
Tags: , , ,
3 comments

While the title above may seem like a complaint about the blog, I am fairly certain that the lack of commentary is probably due to the lack of posting.

Instead, however, I feel like complaining about another issue (one I’ve likely addressed before): lack of comments in code.  One thing that frustrates me about teaching students to program is that they are generally unaware of how important it is to comment your code, particularly when that code is for a research project and may need to be picked up by someone else.

I guess I’m getting old enough that I’ve had several instances of attempting to pick up an old piece of my own code and realizing what a horrible job I did in commenting.  I’m now incredibly thorough when commenting my code so that I’ll be able to go back to it later and understand.

The real issue is, however, that no one ever taught me how to comment code.  It’s something I had to figure out for myself.  The only thing I ever saw was one brief section in Darnell and Margolis’ book.  While I agree with the Do’s they listed, I strongly disagree with a couple of the Don’ts:

  • Do not describe how a piece of code achieves its purpose.  This should be obvious from the code itself.
  • Do not repeat the code.  Comments should contain additional information that cannot be construed from the code itself.
  • Try not to use comments to explain the purpose of variables.  Instead, use meaningful variable names.

While I agree with the second bullet, I’ve learned over time that the first and third are bunk.  Specifically, there is this notion that well-written code should make it obvious as to what is being done.  Maybe if you’re the only person looking at your code, but that’s usually not the case.  As much as we would like to think that meaningful variable names will substitute for explanation in the comments, I’ve found that one person’s meaningful variables may not be that to another person and will probably require significant elaboration.  Further, truly meaningful variable names often need to be rather long, and few people want to take the time to type out names that would be exceptionally clear.  (And then there’s the programmer I knew who used exotic dancer’s names for his variables.  His code was a nightmare to debug.)

The first bullet is the one that really irritates me, however.  I have pulled up code I wrote from a class to use in another class and been completely confused because it had been years since I looked at it.  During the second go-around, I realized there was a chance I may end up using it again, so I started adding things in.  Specifically, I put in the comments that it was algorithm to do linear interpolation.  I even put a reference to the book I got the algorithm from, including page numbers, and what the inputs would need to be (including format requirements) as well as the outputs.  I mentioned what needed to be changed to use the code for other programs.  Finally, I went through and explained what was happening in each step or loop and what the variables meant (e.g., k is a counter, c is the coefficient array).  Without *all* this information, it was impossible to take the code I’d written and modify it for another use without putting in some significant effort.

The reason I went into such elaborate detail (and continue to do so) is that a lot of code, particularly when dealing with algorithms, is almost never intuitive.  If that were intuitive, references like the numerical recipes books would be useless.  (Well, they kind of are, but you know what I mean.)  Therefore, contrary to the advice given above, comment everything, how it works, what your variables mean, etc.  You and anyone else who uses your code later will be very appreciative.

Lost in translation March 18, 2013

Posted by mareserinitatis in computers, research.
Tags: , ,
add a comment

I took my first class in Fortran in the fall semester of 1992, while I was still in high school.  I was taking some classes at the university as an early entry student, and the teacher of the course was a grad student.  He was trying to explain something and kept getting the syntax wrong.  I was getting horribly frustrated, as were the rest of us.  He probably noticed as his response was to say, “I know three operating systems, which means I’ve become completely useless in all of them.”

I didn’t understand how he could confuse things like that as I was taking German and Spanish simultaneously and never seemed to have a problem with mixing things.  I had no idea how different it was to learn spoken language versus coding language.  That was before I’d learned to use a handful of programming languages and started using matlab commands in my fortran code.  Debugging is even more of a pain because it looks right…and it is, but for another language.

The calm before the storm November 25, 2012

Posted by mareserinitatis in computers, engineering, teaching.
Tags: , , ,
add a comment

I teach on Tuesdays and Thursdays.  This past week was Thanksgiving, so I obviously had a bit of a dilemma.  I don’t like getting the classes out of synch because that means I have two different preps to complete.  The obvious solution, therefore, is to just cancel class during the week of Thanksgiving, and that is exactly what I did.

However, I’ve changed one of the assignments in the class from optional to required.  You may remember that last year, I talked about Engineers Who Don’t Like to Program.  I discovered that the majority of my students would rather do a presentation than learn how to program.  I decided this year to change that.  Instead of having two optional programming assignments, I moved some things around so that there is one assignment, very scaled back from what I had expected last year, and it was required to pass the class.

I had a lot of intimidated students, but I think cutting the length back significantly made them less afraid.  I chose to have two weeks in the computer lab to work on the assignment.  They ended up being the week before Thanksgiving and the week after.  In the meantime, I decided to add an extra office hour during one of the cancelled classes so that students could come and ask me questions.

Not surprisingly, no one showed up.  I’ll have to remind them of this when I have an flurry of requests from students needing extra help right before the assignment is due.

thinking work June 10, 2012

Posted by mareserinitatis in grad school, research, solar physics.
Tags: , , ,
add a comment

I have to give a presentation next week and older son took off for the summer, so between getting slides together and getting stuff and people shuttled to the airport, it was a rather busy weekend.  There was some code I wanted to work on but didn’t have the chance.

It’s funny, though, because I was still thinking about it, and I actually think I made good progress on a plan of action.  I realized I had three options: fix it, rewrite it, or throw my hands up in despair and give up. (Okay…last one is very low on the list of possibilities, but I can’t say it’s non-existent…there have been days.)  I’m not sure I can fix it, but I have an idea of how to go about doing it.  It’s a piece of code without commenting, but I know what it’s supposed to do, and I have an awesome ‘cookbook’ of numerical algorithms that explains it.  (Need a spline written in a jiffy….I’m your woman!)  I also suspect that in the process of trying to fix it, I’ll figure out a way to rewrite it a bit more efficiently, likely with less effort than fixing it will take.  And I planned out how I can verify everything, as well.

While I didn’t have much time to work on it directly, I got my resources together and know what I’m going to do so I can hit it first thing after work tomorrow.  I wonder if I made more progress by spending my ‘off’ time thinking about it than if I’d just dived in.  I guess I should know in a couple days.  But it’s funny how stepping away from something and letting your mind idle on it can result in something worthwhile.

I have converted January 9, 2012

Posted by mareserinitatis in computers, research, science, solar physics.
Tags: , , ,
7 comments

Because of the vagaries of my status at UMN (that is, I am an enrolled student, but I don’t pay tuition and therefore do not get some of the perks), I found out that I could no longer get access to Matlab.  This is a bummer because, well, I need it for my thesis.

I’m trying to prove out some code and it’s easier to see what’s going on in Matlab because of the plotting functions.  The idea is that I would like to write it up in there, see what’s going on, and then translate it to the dreaded Fortran.

Alas, I guess I’m having to break up with Matlab.  Instead, I’m learning Scilab.  I find this somewhat funny given how I was explaining to my engineering students last semester that once you know a computer language, it’s often easier to learn another.  (Sadly, most chose not to learn a first one.)  This is doubly so moving from Matlab to Scilab (or, I imagine, the reverse order) because they are so similar.

I like Scilab because it seems to me like a cleaned up version of Matlab.  I don’t consider myself a master in the art of Matlab Kung Fu, but I’m passable.  I have written a small program to solve the Boltzmann equation in the presence of an electromagnetic field and later solved the intractable igloo problem.  However, there are some of the subtleties of matrix operations in Matlab which have always proved problematic for me, mostly dealing with conditional statements to indicate matrix indices, leaving me to fall back on loops.  Not efficient, but it works.  So far, it appears that these operations are more straightforward in Scilab.  I also like the use of the % to indicate prenamed variables.  I am all too guilty of using i as a counter and then being frustrated because it wouldn’t work as an imaginary value later in the program.  And of course, I really like the price tag.

I haven’t yet gotten to some of the plotting I need, however, and as I understand it, that is where Matlab excels.  We shall see.

Have you used both programs?  If so, how do you think they compare?

Forgetting how to be inexperienced November 8, 2011

Posted by mareserinitatis in computers, engineering, teaching.
Tags: , ,
4 comments

I learned to program when I was 9.  My grandmother gave us an old TI-35 console that hooked up to a TV and a tape deck to record the programs.  (Yes, as in cassette tapes…)  She failed to get any games or other programs to run, so in order to get anything useful out of it, I had to learn to program.

It was a huge disappointment for me: I’d really wanted an Apple IIc so I could play Oregon trail on the phosphorescent green screen like I did at school.  On the other than, with 25+ years of knowledge and experience, I think it was the best gift I could’ve ever gotten.  I can make a living programming…but I can’t playing Oregon Trail.

My goal this week was to pass on some of that appreciation of programming to my students.  (I guess I can almost say next generation since my own son is just a couple years behind my students.  That’s sad.)  My informal polling in class has made me realize that only about a quarter of my students have ever programmed in any language ever.

I could have understood this when I was in college…not everyone had access to computers.  It seems like the ubiquity of computers doesn’t necessarily mean one will necessarily have experience using them other than at an apps level.

So I decided they should probably get at least a cursory knowledge of a useful programming language.  Matlab seemed like a good choice because I know several of the upper-level classes use it.  And let’s face it…once you learn to program in one language, it’s easier to go to another.

I found an excellent tutorial.  I liked it because it went through things in a fairly basic manor, which I was sure my students could understand.  It also had exercises.

Unfortunately, my mistake was thinking my students would be able to read, do the examples, and get a decent understanding of how matlab worked.  That’s more or less how I learned it.

Of course…I had already learned other languages when I decided I should learn Matlab.  (It wasn’t around when I was 9, you see…)

I was very surprised to find that the most difficult concept for the students to get was how to write an m-file.  That is, they didn’t understand that you could write a series of commands in the file and then execute the whole file simply by typing the m-file name in the command window.  They wanted to print out the command window or copy and paste their results into the m-file from the command window.

I have to admit that I was impressed with their creativity…but confounded by all the strange things they were attempting.

Finally, I went through a five-minute explanation of the differences between the command window and an m-file, and how the two work.  That seemed to clarify what needed to be done for many of the students.  When I took this approach with my second class, they seemed very calm and significantly less frustrated than the first class.

I really hoped this would be a positive introduction to programming for the students, but I can tell I’ve managed to make it frustrating for one group.  I guess it’s really hard to put myself in their place and figure out where they’re going to have problems.  It’s only when I throw some of them in and see how they react that I can change my approach to fit their needs.

Teaching any class for the first time is a frustrating experience.

Bad encounters with programming guides May 5, 2011

Posted by mareserinitatis in computers, engineering, research, science.
Tags: ,
2 comments

Like almost everyone who has experience writing code, I’ve been guilty of doing a crappy commenting job.  I write a piece of code and go back months or years later to realize that I have NO idea what I did and nor does anyone else.  Thus, I am now at the opposite end of the spectrum.  There’s a loop of some sort, there’s a comment explaining what it does.  If there’s an equation I’m solving, the equation is in my comments.  If I pulled material, such as an algorithm from a book, information on the book, including the page numbers involved, are added to my code.

Seriously.

As you may guess, I now hold everyone to those standards…and their code almost never holds up.  However, there are different levels of crappy code.  Specifically, there are three of them.

The least offensive level of crappy code is that which is reasonably well-commented but has stupid variable names like Fred, Wilma, Betty, and Barney, i.e. names that have no bearing on what the variable actually does.  I almost never see this.

The second level omits these useless variable names, choosing instead to use names that actually relate to their functions.  However, comments are sparse, at best.  If you have good familiarity with the algorithm, there’s a chance you might understand it…maybe.  This is actually most of what I see.

The third and most egregiously awful level combines both of the worst aspects of the coding errors mentioned above: no commenting and nonsensical variable names.  When you ask the person how other people are supposed to keep track of their code, you’re told you simply need to know how it works.  I’m not normally a violent person, but it is infuriorating enough to make me want to throw my favorite software engineering text at them.

So please – if you’re writing code, please do an adequate job of coding AND use appropriate variable names.  I’m too short on books to lose too many.

%d bloggers like this: