Categories
CS462

Later = Never

– LeBlanc’s Law

This statement couldn’t be more true. How many times in life has this been the case?

“It looks okay right now, I think ill come back later to make it look nicer” – Me

“I need to go finish this assignment, but ill do it later” – also Me

I am going to go to the gym later! – again… Me

Now there truly are times when things need to get done “later” and they in fact do. So yes, it’s not like I never get anything done, but my point is that I can get caught up in this exact thing. I can put stuff off because I am either doing something else (hopefully it’s important) or I am making this age-old excuse “I’ll do it later”.

Now, when it comes to my code, I don’t want this to be the case. Why not do the heavy lifting now, before the code gets too “tangled” or “messy”? Deadlines for projects are excuses to just get something just up and running, they are an opportunity to present your best work.

” Most managers want the truth, even when they don’t act like it. Most managers want good code, even when they are obsessing about the schedule. They may defend the schedule and requirements with passion; but that’s their job. It’s your job to defend the code with equal passion

– Robert Martin, Clean Code: A Handbook of Agile Software Craftsmanship

I want to take the time, early and often, to write code that is both “elegant” and “efficient” as Bjarne Stroustrup, the inventor of C++, would say. This is done by being disciplined, using little techniques that help with both cleanliness and code-sense. It takes practice to take this:

def calc(x,y,o):
 if o =='+':
  return x+y
 elif o=='-':
  return x-y
 elif o=='*':return x*y
 elif o=='/': 
  if y!=0:
   return x/y
  else:
   return 'error'
 else:
  return 'Invalid'

a=10
b=5
op='*'
print('Result:',calc(a,b,op))

vs.

def calculate(x, y, operator):
    if operator == '+':
        return x + y
    elif operator == '-':
        return x - y
    elif operator == '*':
        return x * y
    elif operator == '/':
        if y != 0:
            return x / y
        else:
            return 'Error: Division by zero'
    else:
        return 'Error: Invalid operator'

# Example usage
x = 10
y = 5
operator = '*'
result = calculate(x, y, operator)
print(f'Result: {result}')

We see better variables names, error messages, and even simply more spaces between characters. The little things go a long way. Sometimes “simple” doesn’t mean “shorter”.

Leave a Reply

Your email address will not be published. Required fields are marked *