Jonathan Starr's Blog
Thoughts on C#, Ajax, WCF, LINQ, Agile et al.
Site Sections
Home
Contact
Syndication
Login
Posts
74
Comments
70
Trackbacks
0
Saturday, June 21, 2008
Code Redundancy Is NOT Necessarily Bad
improve
my
=>
'code'
I was just reading Jeff Atwood's recent blog article
Department of Declaration Redundancy Department
He makes the case that writing code without static typing is easier to read, and "Anything that
removes redundancy from our code
should be aggressively pursued -- up to and including switching languages."
My take is "maybe".
Say I have a class named Example that implements two interfaces, IFoo and IBar. When I instantiate I have several options when dong so statically.
Example example1 = new Example();
IFoo example2 = new Example();
IBar example3 = new Example();
In the second case I am ensuring that example2 implements a certain interface, and I can swap this out with an instantiation of a different object that implements IFoo. This strategy pattern is fundamental to object oriented programming, and 'getting in the habit of writing code using var' can provide inflexible suboptimal design. Additionally, if you are coding using
TDD
(Test Driven Development) you won't be able to write unit tests that remove all dependencies for your class unless you write your dependencies as interfaces.
The way the compiler in
C#
3.5 automatically converts
LINQ
queries to IEnumerable objects is nice. But the following statement
var reader = new StreamReader(fileName);
is cast to the child static type, not to the its abstract parent (as I think it should be).
Interested in your thoughts.
Jonathan
posted @
Saturday, June 21, 2008 5:43 PM
|
Feedback (9)
Archives
August, 2008 (2)
July, 2008 (2)
June, 2008 (3)
May, 2008 (2)
April, 2008 (3)
March, 2008 (4)
February, 2008 (1)
January, 2008 (13)
December, 2007 (19)
November, 2007 (12)
October, 2007 (10)
September, 2007 (3)
Post Categories
C#
Philosophy
Critique
JavaScript
Links
Software Design
Personal
Religion
Music
Language
Microsoft Live
Politics
Geopolitics
Humor
Physics
Thought Experiments
Businesses using ASP.NET
Friends
Finance
Microsoft Events
Sharepoint
CRM
Caffeine
Africa
Charity
Sports
Statistics
Privacy
Management
Software Development
WCF
Instructional Video
1CCN.COM
Mobile Phone Applications
Windows Movie Maker
Management
Financial Engineering
ASP.NET
SQL Server
Anthropology
Agile Development
Scrum
TDD
Spike
Image Galleries
Fishing Trip
About the Author
Blogs
Scott Guthrie
Timothy Ferriss
GeeksWithBlogs
Bill Evjen
Kevin Grossnicklaus
Meridium Visual Studio Macros
Geometry
Flatland!
Good topology problem
Moebius Transformations
Music
Amish Paradise
Chiron Beta Prime Christmas
Code Monkey
Don't Download this Song
I Feel Fantastic!
re: Your Brains
The Future Soon
What's the matter with parents today
White & Nerdy
Programming
Good Script # Intro
jQuery
LOL Code Compiler
Meridium Visual Studio .NET Macros
MyGeneration
MyGeneration
Refactor Code
SkyDrive
Storage
Skydrive
Videos
Trunk Monkey
News
Jonathan Starr is a developer in Saint Louis, MO. He holds an MBA in Finance from Columbia Business School and earned his MCSD from Microsoft.
All statements in this blog are personal opinions and do not reflect the opinions of his employer.
Related Sites
Tag Cloud
Default.aspx
LINQ
SqlServer
TDD
UnitTests
Windows Live Writer
XP
more tags...
Copyright © 2005 Jonathan Starr
This work is licensed under a
Creative Commons License