I don't like annotations
Call me crazy, but I really don't like annotations. Those weird things used in Java and .NET..
Let me show you some examples why I don't like them: (And yes, there are probably some examples why they are good.. or at least why they seem to be good..)
From the RhinoMocks documentation:
What does [SetUp] tell us about "Setup"? :) And the same thing happens for the TearDown method, of course.. And really, why is this
better than
Alright, there are reasons why the annotated version is better. You may not be able to 'reflect' on a class to get all the methods for which the name starts with "test", and there may be ambiguities.. But are annotations solving these problems 'better enough' to accept the penality of this added language complexity? And it is added complexity, isn't it?
What is even more interesting is the fact that in the same example code from the RhinoMocks site you find lines like this:
Look at some recent posts like Sacred Code Cows and Talking Dynamic Languages which basically say that an I for an interface is at least a bit strange. Probably much worse than strange..
There's more! :)
So I implemented this Syntax Highlighther plugin for IDEA during the last evenings. Look at some of the signatures of methods I had to implement:
For me it just feels like the wrong approach.. It's much like being a codified part of the contract between caller and callee. That's ok. But does it look nice? Does it look 'right' in a stylish way? For me it has one of these bad smells..
If you'd really like to make the code speak the truth - as much as possible - why not use something like this:
Use what the language core offers you! And don't give me the performance BS.. What's your main priority? Performance or correctness? Or..? Decide that first, then be disciplined about it and follow through with it..
Anyway, just a thought.. And don't ask me about C++ template (meta) programming.. In your on frikin interest.. :)
tfdj
Let me show you some examples why I don't like them: (And yes, there are probably some examples why they are good.. or at least why they seem to be good..)
From the RhinoMocks documentation:
[SetUp]
public void Setup()
{
mocks = new MockRepository();
}
What does [SetUp] tell us about "Setup"? :) And the same thing happens for the TearDown method, of course.. And really, why is this
[Test]
public void CallMethodOnObject()
better than
public void testCallMethodOnObject()
Alright, there are reasons why the annotated version is better. You may not be able to 'reflect' on a class to get all the methods for which the name starts with "test", and there may be ambiguities.. But are annotations solving these problems 'better enough' to accept the penality of this added language complexity? And it is added complexity, isn't it?
What is even more interesting is the fact that in the same example code from the RhinoMocks site you find lines like this:
IDemo demo = (IDemo)mocks.CreateMock(typeof(IDemo));
Look at some recent posts like Sacred Code Cows and Talking Dynamic Languages which basically say that an I for an interface is at least a bit strange. Probably much worse than strange..
There's more! :)
So I implemented this Syntax Highlighther plugin for IDEA during the last evenings. Look at some of the signatures of methods I had to implement:
@NotNull
public final String getDemoText()
@Nullable
public final StructureViewBuilder getStructureViewBuilder( final @NotNull VirtualFile file, final @NotNull Project project )
@NotNull
@NonNls
public final String getDefaultExtension()
For me it just feels like the wrong approach.. It's much like being a codified part of the contract between caller and callee. That's ok. But does it look nice? Does it look 'right' in a stylish way? For me it has one of these bad smells..
If you'd really like to make the code speak the truth - as much as possible - why not use something like this:
public interface Something
{
public final ExtensionString getDefaultExtension();
}
public final class ExtensionString
{
public static final ExtensionString newInstance( final String aExtension )
{
if ( isValidAndCorrect( aExtension ) == false )
{
throw new YouSuckException( aExtension );
}
return new ExtensionString( aExtension )
}
(...)
// From Object
public final String toString()
{
return myExtension;
}
// Implementation Details
private ExtensionString( final String aExtension )
{
myExtension = aExtension;
}
private static final void isValidAndCorrect( final String aExtension )
{
(...)
}
private final String myExtension;
}
Use what the language core offers you! And don't give me the performance BS.. What's your main priority? Performance or correctness? Or..? Decide that first, then be disciplined about it and follow through with it..
Anyway, just a thought.. And don't ask me about C++ template (meta) programming.. In your on frikin interest.. :)
tfdj


0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home