avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] [avr-libc-commit] [2358] Reverted month_length() back


From: Michael Rice
Subject: Re: [avr-libc-dev] [avr-libc-commit] [2358] Reverted month_length() back to using the 'knuckles' algorithm.
Date: Wed, 24 Apr 2013 18:09:23 -0400

The 'elegant' solution, while it looks pretty, is sometimes the Sirens song. Take the often used example for testing Leap years...

int is_leap_year(int year){
        return (year%4==0)?( (year%100==0)? ( (year%400==0)? 1 : 0) : 1) : 0;
}

An elegant 1 liner, which compiles to ~44 bytes. But the brutishly ugly, multi line method I used in the library compiles to 38, and most people find it easier to understand.

In general, I have found that breaking up those one liners into multiple lines, will often result in smaller and faster code. Not always, but usually.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]