Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Efficiency
#1
To go kinda in tandem with Pete's post about coding styles, I wanted to take a second to get everyone's thoughts on Coding Efficiency.  What do you guys usually shoot for -- the most efficient code for you, or the most efficient code for your programs to run?

Everyone know bubble sorts are crap.  They're slow.  They're inefficient as heck.   And, if all we're doing is sorting a small set of items such as the order of a shopping list, or deck of cards, they're all we need!  Why bother with the time and effort to come up with something faster, when your biggest use case is sorting 100 things in 0.2 slow seconds?  My personal time as a programmer is worth more than the 0.1 second you'd save as an user of my "Shopping App Pro" program.  

Most programmers should for an adage of "Less is more".  bplus is terrible about this, with his constant need to count lines of code and use them as a marker for success.  (Not picking on bplus at all -- just using him as an example we see here on the forums, because he posts and shares these short programs a ton.)

The thing is, a lot of times, "MORE IS LESS" when it comes to coding.   For example, let's say I have a variable x that can do 100 different things..  Usually it's written in code as something like:

SELECT CASE x
   CASE 1
   CASE 2
   CASE 3
   CASE 4
   CASE 5
   ... so on.
END SELECT

Simple for the programmer to write, understand, and work with.   But wouldn't it be a lot more efficient with:

SELECT CASE x
    CASE 0 TO 50
       SELECT CASE x
          CASE 1
          CASE 2
          ...on
      END SELECT
    CASE 51 TO 100
...

We've now doubled the code for decision making, but halved the total possible number of IF checks required to process the code.  If we break it down further, binary-tree style, we can reduce it to a long arse batch of code that has to make a maximum of 8 decisions, instead of 100!

It's a lot more code on the programmer, but a lot more efficient for the program itself.



The question is, where do most of you guys try and draw the line?  How hard do you work for code efficiency, very programmer efficiency?  

Curious My-Minds Want To Know!!
Reply


Messages In This Thread
Coding Efficiency - by SMcNeill - 08-11-2024, 12:16 AM
RE: Coding Efficiency - by TerryRitchie - 08-11-2024, 01:21 AM
RE: Coding Efficiency - by SMcNeill - 08-11-2024, 03:25 AM
RE: Coding Efficiency - by CharlieJV - 08-11-2024, 01:29 AM
RE: Coding Efficiency - by Pete - 08-11-2024, 07:22 PM
RE: Coding Efficiency - by Dimster - 08-12-2024, 06:34 PM
RE: Coding Efficiency - by Pete - 08-13-2024, 09:46 PM
RE: Coding Efficiency - by SMcNeill - 08-13-2024, 11:11 PM
RE: Coding Efficiency - by Pete - 08-13-2024, 11:23 PM
RE: Coding Efficiency - by SMcNeill - 08-13-2024, 11:28 PM
RE: Coding Efficiency - by TerryRitchie - 08-14-2024, 01:21 AM
RE: Coding Efficiency - by Pete - 08-13-2024, 11:53 PM
RE: Coding Efficiency - by Pete - 08-14-2024, 03:38 PM
RE: Coding Efficiency - by SMcNeill - 08-14-2024, 04:26 PM
RE: Coding Efficiency - by mdijkens - 08-15-2024, 11:29 AM
RE: Coding Efficiency - by Pete - 08-15-2024, 03:20 PM
RE: Coding Efficiency - by Kernelpanic - 08-15-2024, 05:57 PM
RE: Coding Efficiency - by justsomeguy - 08-15-2024, 06:06 PM
RE: Coding Efficiency - by TerryRitchie - 08-16-2024, 03:21 AM
RE: Coding Efficiency - by justsomeguy - 08-16-2024, 07:09 AM
RE: Coding Efficiency - by Pete - 08-15-2024, 11:14 PM
RE: Coding Efficiency - by dano - 08-16-2024, 12:33 AM
RE: Coding Efficiency - by Pete - 08-16-2024, 12:35 AM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 01:55 AM
RE: Coding Efficiency - by Pete - 09-11-2024, 06:45 AM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 07:59 AM
RE: Coding Efficiency - by bplus - 09-11-2024, 01:51 PM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 02:01 PM
RE: Coding Efficiency - by bplus - 09-11-2024, 02:39 PM
RE: Coding Efficiency - by Pete - 09-11-2024, 02:48 PM
RE: Coding Efficiency - by dano - 09-12-2024, 01:41 PM
RE: Coding Efficiency - by Jack - 09-12-2024, 04:01 PM
RE: Coding Efficiency - by Kernelpanic - 09-12-2024, 08:13 PM
RE: Coding Efficiency - by Pete - 09-13-2024, 06:56 PM



Users browsing this thread: 7 Guest(s)