Settings

Theme

Writing better code: it’s imperative that you are declarative

togaroga.com

1 points by andrewhare 16 years ago · 1 comment · 1 min read

Reader

Most C# developers are very familiar with writing imperative code (even though they may not know it by that name). In this article, I will introduce you to an alternative style of programming called declarative programming. Proper declarative code is easier to read, understand, and maintain.

makecheck 16 years ago

These aren't really good examples in my opinion. The "condensed" version is not better, because it makes one thing much worse: it is now hard to change the contents of the loop.

Especially when working with larger data sets, you need to be able to do whatever is necessary within a single loop over the data, to avoid lousy runtime. In the article's example, by automatically filtering out even numbers to do ONE operation, it is now very hard to modify that loop to perform other operations on numbers that may not be even.

In my practical experience, a "real" for-loop is almost always more flexible and valuable, and is just as clear.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection