Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
yippee cahier
Mar 28, 2005

A consultant sent his source code to me recently, and I had the pleasure of rewriting it. I don't think this guy knows about the standard library.

code:
void convertUnsigned16BitToChars( unsigned short value16Bit, char * returnString ){
    char worker;

    worker = (char)((value16Bit & 0xF000) >> 12);
    if(worker >= 0 && worker < 10){
        worker = worker + 48;
    }else{
        worker = worker + 55;
    }
    returnString[0] = worker;
    
    worker = (char)((value16Bit & 0x0F00) >> 8);
    if(worker >= 0 && worker < 10){
        worker = worker + 48;
    }else{
        worker = worker + 55;
    }
    returnString[1] = worker;    

    worker = (char)((value16Bit & 0x00F0) >> 4);
    if(worker >= 0 && worker < 10){
        worker = worker + 48;
    }else{
        worker = worker + 55;
    }
    returnString[2] = worker;
    
    
    worker = (char)(value16Bit & 0x000F);
    if(worker >= 0 && worker < 10){
        worker = worker + 48;
    }else{
        worker = worker + 55;
    }
    returnString[3] = worker;

    return;
}
replaced with a call to sprintf().

code:
double power(double number, int toThe){
	double ret=1;
	int i;
	if(toThe==0)return 1;
	else if(toThe<0){
		toThe=-toThe;
		for(i=1;i<=toThe;i++)ret*=number;
		return 1/ret;
	}else{
		for(i=1;i<=toThe;i++)ret*=number;
		return ret;
	}
}
replaced with a call to pow().

code:
double degreesToRadians(double degrees){
	return degrees/180*PI;
}

double radiansToDegrees(double radians){
	return 180/PI*radians;
}
poo poo yeah, abstract away this insane complexity. He rewrote all the trigonometric functions too.

code:
char getLargestCHAR(char in1, char in2){
	return ( in1 >= in2 ) ? in1 : in2;
}
oh my god

I'd caution you against using any of this code in your own programs, as it's under copyright.

Adbot
ADBOT LOVES YOU

yippee cahier
Mar 28, 2005

Vanadium posted:

:psyduck:

!coherent

yippee cahier
Mar 28, 2005

just use a code reformatter and then who cares, it always looks good.

yippee cahier
Mar 28, 2005

I'm always getting asked in emails why I made a change to a certain file in SVN. I think I'm the only one who uses comments.

yippee cahier
Mar 28, 2005

Quick one:
code:
/* Clock settings at 64MHz */
MASTER_CLK_FREQ = 59000000;

yippee cahier
Mar 28, 2005


needs more orange

yippee cahier
Mar 28, 2005

Is the error that this took more than a single, non-branching line of code?

yippee cahier
Mar 28, 2005

Tell me there's more to that patch and this was some incidental thing where they had to insert a case for the new enum value to pass code review.

edit: lol code review on that

yippee cahier
Mar 28, 2005

Ugh, I'm in a similar situation. No one believes me when I say a component is browning out or otherwise resetting itself, so I have been tasked with days of driver rewrites to eliminate good interrupt driven design and move back to a polling loop "like we used to do back when we launched first_product". Why doesn't anyone believe me? Because first_product works fine on a completely different hardware platform, with a different model of component and years of bug fixes.

Often I have to bring people up to speed on how we're actually doing things in code so they can revise their far-fetched ideas why it doesn't work. It was suggested that I was overwhelming the resetting component with commands, despite using hardware flow control and only issuing the next command after getting and validating the response to the previous one. Result? Now I have work issue to test the interface with a dummy command before every real command. I'm about to double the number of commands hitting this supposedly overloaded command interface!

yippee cahier
Mar 28, 2005

Jumpingmanjim posted:

We also have a burn down chart that seems to keep burning up and stand up meetings that go on for too long. I wonder if there's enough material for a bad Agile thread.

Hey Geoff, didn't know you were on the forums.

yippee cahier
Mar 28, 2005

GCC (as of 5.x https://gcc.gnu.org/gcc-5/changes.html) and clang (http://clang.llvm.org/docs/LanguageExtensions.html#checked-arithmetic-builtins) both have checked overflow builtin functions. I assume that any inefficient code generated from these on your platform would be a bug that should eventually get optimized.

yippee cahier
Mar 28, 2005

Munkeymon posted:

Definitely not Google
:lol:
:golfclap:

yippee cahier
Mar 28, 2005

redleader posted:

I'd be interested to hear your problems with Python 3, compared to those of Zed "I learned Python to write a book on it" Shaw.

Yes, please elaborate. It was annoying to have to have to remember to encode and decode strings until I got used to it, but it's not like they jettisoned half the standard library. I've heard the "python is a garbage plang" argument as well as the "not worth breaking compatibility" argument, but this is new to me. What makes Python 2 so superior to Python 3?

yippee cahier
Mar 28, 2005

"programmers" means "libertarian men"

yippee cahier
Mar 28, 2005

Jabor posted:

Personally, I don't give a poo poo about when solar noon is, but I'd rather not walk to work in the dark.

Tell your boss you'll be in when it's light out and work 8 hours from whenever that is.

yippee cahier
Mar 28, 2005

Only delay needs to be volatile to implement a timeout, right?

yippee cahier
Mar 28, 2005

New Yorp New Yorp posted:

This is what happens when you don't do mandatory code review and let people work on their own.

I found an identical chunk of code repeated 34 times in this (relatively small) project I just inherited. It's not the only chunk of code like that. As far as I can tell, the project's LoC count primarily consists of copy/paste. There are no methods anywhere.

It also has a lot of patterns like:

code:
if (condition) {
 // do stuff
}
else {
  throw some error
}
Instead of
code:
if (!condition) {
  throw some error
}
// do stuff
leading to excessive indentation, since there are no methods:

code:
if (condition) {
  // do stuff
  if (anotherCondition) {
    // you get the idea
    if (yetAnotherCondition) {
      // god have mercy on my soul
    }
    else {
      throw some error
    }
  }
  else {
    throw some error
  }
}
else {
  throw some error
}

I sounded the "technical debt" alarm so we can go back and fix all this poo poo, since it is drat near impossible to read or change without breaking something in the huge nest of conditionals and copy/pasted code.

I've seen a NMEA sentence parser that did that for every field, separator, etc. The one line else clauses were hundreds of lines away. Thank god we don't have multiple return statements though!

yippee cahier
Mar 28, 2005

Embedded isn’t dead and C is by far the most popular language. Multiple kilobytes would be a very generous stack allocation for some systems I’ve worked on.

Do compilers have tuning options for when to turn off this optimization that substitutes heap for stack?

Adbot
ADBOT LOVES YOU

yippee cahier
Mar 28, 2005

Hammerite posted:

love to see a library in which every property accessor has a documentation string that says either "gets the value of the Foo property" or "sets the value of the Foo property" as though that were helpful to anyone, clearly solely because there is some policy saying that every method and property accessor is required to have a documentation string so they can claim they reach some documentation target

sometimes it’s easier to tell your IDE to autogenerate a doc block instead of arguing in a pull request about how confusing a member function called “encodeToBuffer” that takes one parameter called “buffer” really is.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply