Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tips for making code last [closed]

Sometimes I really wonder if my code is "lastable". I do everything to make it "last" and avoid depending on things while writing or solving problems. Things like "programming tricks" and assumptions which may change in the future if I rewrite or add to the code. Sometimes it's easy, other times it's hard, but it's all a part of being a programmer and making stuff work better, faster and easier.

Having said this, can you recommend some tips from your personal experience for writing better long lasting code in HLL? What should be avoided, what embraced?

Thank you!

like image 428
Secko Avatar asked Dec 01 '22 07:12

Secko


2 Answers

Avoid anything you recently read about and thought,

Well that is an interesting language feature, design pattern etc. , I think this can help me reduce my code complexity.

For some reason this always comes to bite me later on. Better to have this in side projects and then use it in production code once it proved a good idea, versus merely looking like one.

like image 60
nasmorn Avatar answered Dec 05 '22 04:12

nasmorn


Bit rot...

The problems I have most often come up against when compiling an old project are

  • Missing dependencies - It is a good idea to list any libraries that you depend on, including the URL you got it from. Your include path may not be the same as it was 5 years ago!
  • Compiler changes - These are usually not much of a bother, and can often be fixed with a #define in C/C++
  • Data size changes - This was a nasty one when moving from 16-bit to 32-bit. Try not to make assumptions about the size of variables.
  • Mysterious build process - For some projects, there may be obscure build steps for building resources, libraries, etc. Make sure they're well documented.
  • Overly clever code - I've seen code that assumes the machine has less than X megabytes of memory, and so uses the top bits of pointers to hold data. Don't do things like that!
  • Error checking - When things DO break, good error checking will help you figure out why a lot faster.
like image 30
MrZebra Avatar answered Dec 05 '22 05:12

MrZebra