r/linux • • Dec 28 '21

Tips and Tricks Rules of Programming

/r/computerscience/comments/rq60d4/rules_of_programming/

[removed] — view removed post

0 Upvotes

9 comments sorted by

2

u/Columbus43219 Dec 28 '21

Rule 3.

Fancy algorithms are slow when n is small, and n is

usually small. Fancy algorithms have big constants. Until you know

that n isn't frequently going to be big, don't get fancy. (Even if n

does get big, use Rule 2 first.)

Is that a typo?

1

u/AegorBlake Dec 28 '21

no that is not a typo. Fancy algorithms work best when n is big (when compared in speed to simpler ones)

1

u/whosdr Dec 28 '21

Until you know

that n isn't frequently going to be big, don't get fancy.

This says that you should only rework the algorithm if you know n is mostly small. Which yeah, that's definitely backwards.

1

u/lostparis Dec 28 '21

This rule is just crapply written - what even counts as fancy in this context?

A better rule is that easily understood algorithms are usually the best, but that sometimes a fast one is important. Also make your algorithms pluggable.

2

u/[deleted] Dec 28 '21

For example don't implement comb sort when built in algorithm for sorting is good enough for sufficiently small number of items. If you have fewer than 100 or 1000 items, sorting them will be fast regardless of algorithm used.

Implementing something else means adding bugs to the code and increasing complexity for not much benefit.

That said, I can't say rules are well written.

1

u/lostparis Dec 28 '21

For example don't implement comb sort

I think don't reinvent the wheel is more the issue here :)

1

u/[deleted] Dec 28 '21

That's the "can't say rules are well written" part of my answer. :) It's essentially trying to reinvent KISS principle but going around it.

2

u/lostparis Dec 28 '21

*You can't tell where a program is going to spend its time.

Actually you usually do know. But the details might not be as simple as you think.

These rules are all a bit of a mess. The ideas behind them are good but they are very badly expressed IMHO

1

u/AutoModerator Dec 28 '21

This submission has been removed due to receiving too many reports from users. The mods have been notified and will re-approve if this removal was inappropriate, or leave it removed.

This is most likely because:

  • Your post belongs in r/linuxquestions or r/linux4noobs

  • Your post belongs in r/linuxmemes

  • Your post is considered "fluff" - things like a Tux plushie or old Linux CDs are an example and, while they may be popular vote wise, they are not considered on topic

  • Your post is otherwise deemed not appropriate for the subreddit

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.