Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, February 6, 2014

TN consumer tax form fail

Anyone tried to fill out a Tennessee consumer use tax return lately? Probably not, since it’s entirely voluntary. That might explain why it’s so horribly designed.

First, it has to be done online; there’s no paper version. That’s OK, but only if you do online stuff right. Second, there’s no way to save your work; you type in a huge amount of information, lose your browser session and have to start over. Third, all the data has to be formatted to an absurd degree. Cents have to be in a separate field from dollars, entered as a two-digit amount. Years have to be two-two-four digits. Miss one, and it won't accept your form, but also won't point out your mistake! Fourth, you have to enter a separate line item for every purchase. If you want to add a number of purchases all at one time, too bad; you have to do that one by one.

Oh, and they don’t take Visa, of all things. Say what you want about whether this kind of tax should or should not exist. But speaking as an engineer, if you’re going to do something, it should be done well.

Thursday, December 12, 2013

Structuring code: setting vs. evaluating

A while back I was explaining my code to a coworker, so as to reduce our bus factor. We got into a discussion about the way I structured my code. My code tends to be more like this:

while(1){
     //read the inputs
     input1 = pin4
     input2 = pin5

     //define the mode
     if (input1) mode = CHARGE;
     else if (input2) mode = BOOST;
     else mode = STANDBY;

     //define outputs
     if (mode == CHARGE) output1 = 1;
     else output1 = 0;

     if (mode == BOOST) output2 = 1;
     else output2 = 0;
}

His code tends to be more like this:


//handle first mode
if (input 1){
     mode = CHARGE;

     output1 = 1;
     output2 = 0;
}
//handle second mode
else if (input 2){
     mode = BOOST;
     output1 = 0;
     output2 = 1;
}

The two are semantically identical, but the way you get from A to B is totally different.

In essence, mine is structured around making sure that any given variable is only set in exactly one place in the code wherever possible. Obviously there are some cases where that can't be, like the results of long strings of sequential calculations. But in general, I find that this makes my code much easier to debug. If something is wrong with the value of one particular variable, that problem can only exist in exactly one place. And if I need to insert intermediate flags between one variable and another, it's much easier if there's only one place to do that.

I'm not sure how I got to this point. I didn't used to program this way. I think I learned it from lots of VHDL pain, back in the day. I wonder if there are names for these two approaches to structuring one's program. I'd be interested in reading more about the subject.

Thursday, September 15, 2011

PSV considered harmful

"My motor control ISR's use lookup tables in PSV, most of my PID or FIR control interrupts use coefficients in PSV for the DSP to save RAM..."

https://www.microchip.com/forums/m241389.aspx

Aside from the acronymorrhea, it's really an interesting discussion. One poster insists certain practices are "not safe", while others say they're perfectly fine. Both have valid points.

Many things are not safe if you do not take appropriate precautions. Nested interrupts really can cause problems on non-atomic operations. But that doesn't mean you don't use nested interrupts, it just means you disable them for the duration of any non-atomic operations.

Simon Tatham, speaking of the hoops he went through to implement coroutines in C, said "Any coding standard which insists on syntactic clarity at the expense of algorithmic clarity should be rewritten." Obviously that's not 100% realistic. But neither is assuming you can meet an arbitrary syntactic coding standard 100% of the time. The balance lies in knowing when to break what rules.

Tuesday, August 23, 2011

Student feedback

In 2006 I finished my BS in computer science and computer engineering at Lipscomb University. Last fall I taught a class on web server technologies there . While teaching that class, I decided to try to correct what I saw as a significant oversight in the CS curriculum: I taught the students the basics of using source control, particularly Git.

I just got an e-mail from one of my students saying that Git helped him get a job after he graduated.

I have made the world a slightly better place.

Let's see what I can do teaching Operating Systems this fall!

Thursday, August 18, 2011

Once more unto the blog

I find myself wanting to say random things with no particular direction. The things I want to say can't typically be compressed into 140 characters. Thus, blog.

I've done this a few times before, but not with any serious regularity. We'll see how I do now.

Work's been interesting of late. I've been working on what's basically a grid-tied inverter for regenerative braking. I wrote a Python script to autogenerate my sine wave lookup table. The output and switching frequencies can be controlled by two constants in the script, and you can immediately recompile. It's quite excellent. The unit seems to work under all tested circumstances. Next, abuse.

I've also been training a new engineer. He's learning well how we do things, having had to drop two projects already for higher-priority ones. And now he's trying to modify and update my code from three years ago. (Poor sod.) See, I built this tester unit. It met spec, but I was never happy with the overall architecture. Now, three years later, someone wants several of them, somewhat modified, and they want them now. Since I never went back and redid it in what I now (in my since-acquired infallible wisdom) know to be the One True Way, and since we're in a rush, we have to carry over the bad old architecture to Yet Another Product.

Be sure your sins will find you out.