6 Replies - 1196 Views - Last Post: 24 February 2016 - 07:25 AM

#1 leibniz76   User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 89
  • Joined: 02-May 14

How often do you come across a small code that takes hours to write?

Posted 23 January 2016 - 01:05 PM

In the early days I would come across a set of just 50 lines that would take 6 hours to write rather frequently. Maybe once or twice a month. I thought those days were behind me. It happened again. Part of the problem was that I was using one of the codes that I wrote 6 months ago back in the days when I was not very experienced and I had forgotten how it worked. Still it should not have happened. How often does this happen to you guys?
Is This A Good Question/Topic? 0
  • +

Replies To: How often do you come across a small code that takes hours to write?

#2 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11736
  • View blog
  • Posts: 19,931
  • Joined: 19-March 11

Re: How often do you come across a small code that takes hours to write?

Posted 23 January 2016 - 01:14 PM

"A code"? You mean like a cipher? Or do you mean "a program"?
(sorry, pet peeve: "code" in the programming sense is a mass noun, and doesn't take plural or singular marking. Kind of like "slime", as in "he was covered in slime", not "he was covered in a slime")

Yeah, sometimes a small thing can be difficult to write. This usually indicates that you haven't thought it through enough before writing, which means there are probably other problems lurking in your design.
Was This Post Helpful? 1
  • +
  • -

#3 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3038
  • View blog
  • Posts: 11,678
  • Joined: 03-December 12

Re: How often do you come across a small code that takes hours to write?

Posted 23 January 2016 - 03:06 PM

I believe in the premises of self documenting code. Which means, a procedure should easily identify what it is doing. However, sometimes I have seen where it is not possible (usually due to a hack) and in those cases you should write what the procedure should be attempting to do, not how it is doing it, but what.


Also, your goal should not be writing the smallest code possible, but to be efficient and cleanly written. You should also be concerned with performance, but readability can be gained even when writing high performance scalable code.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7187
  • View blog
  • Posts: 24,357
  • Joined: 05-May 12

Re: How often do you come across a small code that takes hours to write?

Posted 30 January 2016 - 03:08 PM

A couple of times I have been forced to write less elegant code to reach the performance goals that I needed: denormalized data structures, unrolled loops, etc. In these cases, I put the well written code in #ifdef SLOW blocks and the optimized code in the #else section. I would also have a unit test that implements the slower more readable version and compares results of the faster implementation. Yes, it means duplicated code, but I like to have a reference of my more legible version of the code readily available.
Was This Post Helpful? 0
  • +
  • -

#5 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2392
  • View blog
  • Posts: 5,025
  • Joined: 11-December 07

Re: How often do you come across a small code that takes hours to write?

Posted 31 January 2016 - 06:00 AM

I've experienced similar. Optimising often creates more corner cases than simple, clean. I'll try and catch them in my unit tests but I often use the previous version as a test oracle too. Java doesn't have #ifdef SLOW so I use the strategy pattern instead.
Was This Post Helpful? 1
  • +
  • -

#6 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 172
  • View blog
  • Posts: 1,114
  • Joined: 03-April 12

Re: How often do you come across a small code that takes hours to write?

Posted 23 February 2016 - 06:09 AM

One such piece (or rather several pieces) of code was a double vectoring exception handler for Raspberry Pi 2B gdb stub/agent.
At exception handling, every mode had to be considered in both entry and exit, and both primary and secondary vectoring had to be considered, and rather fast enough to allow higher speed peripherals to be used.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7187
  • View blog
  • Posts: 24,357
  • Joined: 05-May 12

Re: How often do you come across a small code that takes hours to write?

Posted 24 February 2016 - 07:25 AM

I would have expected a lookup table would make this performant. Granted, putting together the lookup table would take some time: get expected inputs/outputs, make a big table, and the use K-maps to come up with the minimum lookup table.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1