﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>alwin commented on Sometimes I have code blinders on</title><description>@Tommy Carlier,
  
  
Well of course it's all just a matter of personal taste. For me a string has a value if it has something in it, and yes, spaces are a value too.
  
  
I have this:
  
public static bool IsNullOrEmpty(this string self)
  
{
  
	return string.IsNullOrEmpty(self);
  
}
  
public static bool HasValue(this string self)
  
{
  
	return !IsNullOrEmpty(self);
  
}
  
With HasValue I have one less negation wrt Is*Not*Empty, or *!*IsNullOrEmpty. 
  
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment31</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment31</guid><pubDate>Sat, 06 Mar 2010 14:33:37 GMT</pubDate></item><item><title>Tommy Carlier commented on Sometimes I have code blinders on</title><description>@alwin I think that "empty" and "not empty" is clearly defined in relation to strings, while "value" is not as clearly defined: what is considered a value?
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment30</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment30</guid><pubDate>Sat, 06 Mar 2010 13:42:57 GMT</pubDate></item><item><title>firefly commented on Sometimes I have code blinders on</title><description>I think Oren just need another vacation :)
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment29</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment29</guid><pubDate>Sat, 06 Mar 2010 05:01:37 GMT</pubDate></item><item><title>Try It commented on Sometimes I have code blinders on</title><description>@Paul Batum
  
  
I need to man up Paul.  
  
  
I owe you a great big apology, once I wipe the egg from my face.  You're quite right.  I was thinking how assigning with constants on the left upsets the compiler.
  
  
I'll crawl back under my rock now with your permission.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment28</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment28</guid><pubDate>Sat, 06 Mar 2010 01:39:46 GMT</pubDate></item><item><title>Try It commented on Sometimes I have code blinders on</title><description>@Paul Batum
  
  
Do it, then come back and let us know what your experience is.  I think you'll find it errors out quite nicely thank you.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment27</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment27</guid><pubDate>Sat, 06 Mar 2010 00:50:03 GMT</pubDate></item><item><title>Paul Batum commented on Sometimes I have code blinders on</title><description>@Mr_Simple
  
  
Sure, its better if you're using a language like C, because if you accidentally  use '=' instead of '==' then you'll get a compile error. But C# doesn't have this problem, so I'm not sure what "stupid bugs" you're thinking it prevents.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment26</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment26</guid><pubDate>Sat, 06 Mar 2010 00:40:24 GMT</pubDate></item><item><title>alwin commented on Sometimes I have code blinders on</title><description>@Tommy Carlier,
  
  
Why not string.HasValue() ? instead of IsNotEmpty()
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment25</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment25</guid><pubDate>Fri, 05 Mar 2010 18:29:07 GMT</pubDate></item><item><title>Mr_Simple commented on Sometimes I have code blinders on</title><description>@Grimace
  
  
false == is even better.  Saves time running after stupid bugs.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment24</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment24</guid><pubDate>Fri, 05 Mar 2010 15:15:14 GMT</pubDate></item><item><title>Jason Meckley commented on Sometimes I have code blinders on</title><description>It's not that apparent to me either. I think it's that index will be null if TryGetValue returns false. in which case you either need to return after logging or put value.IndexDocuments in an else block.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment23</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment23</guid><pubDate>Fri, 05 Mar 2010 14:34:37 GMT</pubDate></item><item><title>Tommy Carlier commented on Sometimes I have code blinders on</title><description>Actually, now that I think about it: I sometimes create 2 versions of a method: the regular one and the "not"-one. Some extension methods I wrote:
  
- ICollection
&lt;t.HasItems(): same as Count &gt; 0
  
- ICollection
&lt;t.IsEmpty(): same as Count == 0
  
- string.IsEmpty(): same as string.IsNullOrEmpty(s)
  
- string.IsNotEmpty(): same as !string.IsNullOrEmpty(s)
  
  
Especially the HasItems/IsEmpty on the collection show the intention of the code.
&gt;</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment22</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment22</guid><pubDate>Fri, 05 Mar 2010 14:31:33 GMT</pubDate></item><item><title>Tommy Carlier commented on Sometimes I have code blinders on</title><description>@Patrick I also use the exclamation mark, but I also think it's not always very obvious (only 1 character that looks like a letter). I'd actually prefer a "not"-keyword here, like in VB.
  
Maybe the "condition == false" wouldn't be as easy to overlook if you turned it around (like they do in C++ for a different reason):
  
if (false == condition) { ... }
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment21</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment21</guid><pubDate>Fri, 05 Mar 2010 14:27:04 GMT</pubDate></item><item><title>Patrik H&amp;#228;gne commented on Sometimes I have code blinders on</title><description>I'm totally with Matt on this one, the (condition == false) is BAD practice. It's SOOOO much easier to overlook than the exclamation mark. The exclamation mark adds the negation beforehand so that you know that you are negating the statement when you read it.
  
  
I feel you on the bug though, been there, done that and in the end it's always like DUH!
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment20</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment20</guid><pubDate>Fri, 05 Mar 2010 13:57:30 GMT</pubDate></item><item><title>Dmitry commented on Sometimes I have code blinders on</title><description>There should be a "return" statement after log.Debug().
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment19</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment19</guid><pubDate>Fri, 05 Mar 2010 13:45:22 GMT</pubDate></item><item><title>Demis Bellot commented on Sometimes I have code blinders on</title><description>Yeah we've all been there, usually a good time for a break.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment18</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment18</guid><pubDate>Fri, 05 Mar 2010 13:42:50 GMT</pubDate></item><item><title>Grimace commented on Sometimes I have code blinders on</title><description>@Matt
  
  
I actually picked up that code style from Ayende. Shorter does not always mean more readable and an exclamation mark is easily overlooked.
  
  
I used to apply the exclamation mark, but after trying the "== false" for a while, I'm sold.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment17</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment17</guid><pubDate>Fri, 05 Mar 2010 13:35:11 GMT</pubDate></item><item><title>Markus Zywitza commented on Sometimes I have code blinders on</title><description>This is serious. It means that even you cannot code 20 hours a day for more than four weeks... ;-)
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment16</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment16</guid><pubDate>Fri, 05 Mar 2010 13:11:48 GMT</pubDate></item><item><title>Matt commented on Sometimes I have code blinders on</title><description>I'd be more ashamed of the if (condition == false) bit.. 
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment15</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment15</guid><pubDate>Fri, 05 Mar 2010 13:10:12 GMT</pubDate></item><item><title>efdee commented on Sometimes I have code blinders on</title><description>What Tommy Carlier said. You forgot 'return' when the TryGetValue fails :-)
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment14</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment14</guid><pubDate>Fri, 05 Mar 2010 12:28:07 GMT</pubDate></item><item><title>daniel commented on Sometimes I have code blinders on</title><description>nothing like another pair of eyes at times like that. 
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment13</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment13</guid><pubDate>Fri, 05 Mar 2010 11:59:17 GMT</pubDate></item><item><title>Brad commented on Sometimes I have code blinders on</title><description>log is null?
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment12</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment12</guid><pubDate>Fri, 05 Mar 2010 11:08:39 GMT</pubDate></item><item><title>Dirk commented on Sometimes I have code blinders on</title><description>I think this post was not about "find the bug"! It's about "We all are humans..." ;-)
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment11</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment11</guid><pubDate>Fri, 05 Mar 2010 10:57:35 GMT</pubDate></item><item><title>Lodewijk commented on Sometimes I have code blinders on</title><description>String.Format fails because 'index' is null.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment10</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment10</guid><pubDate>Fri, 05 Mar 2010 10:32:57 GMT</pubDate></item><item><title>Tommy Carlier commented on Sometimes I have code blinders on</title><description>Even if TryGetValue fails (and value is null), the last statement is still executed. Missing an else.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment9</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment9</guid><pubDate>Fri, 05 Mar 2010 10:22:39 GMT</pubDate></item><item><title>anon commented on Sometimes I have code blinders on</title><description>index can be null.
  
indexes can be null.
  
value can be null.
  
Simple.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment8</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment8</guid><pubDate>Fri, 05 Mar 2010 10:16:40 GMT</pubDate></item><item><title>James McKay commented on Sometimes I have code blinders on</title><description>Um...so, the intention is that when you try to index on a non-existent index it should fail silently? That being the case I'd call the method TryIndex rather than Index and have it return a Boolean to indicate failure.
  
  
If a method can't do what its name says it does, it should always throw.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment7</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment7</guid><pubDate>Fri, 05 Mar 2010 10:13:51 GMT</pubDate></item><item><title>Ian Nelson commented on Sometimes I have code blinders on</title><description>OK, try again Ian:
  
  
index parameter is null in rare cases, TryGetValue returns false in this case, and log.DebugFormat throws NullReferenceException ?
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment6</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment6</guid><pubDate>Fri, 05 Mar 2010 10:12:12 GMT</pubDate></item><item><title>FallenGameR commented on Sometimes I have code blinders on</title><description>Ayende, why have you stoped using HTML highlighting?
  
Not it's only images for code.
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment5</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment5</guid><pubDate>Fri, 05 Mar 2010 10:12:11 GMT</pubDate></item><item><title>Benny Thomas commented on Sometimes I have code blinders on</title><description>Been there, done that! :-)
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment4</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment4</guid><pubDate>Fri, 05 Mar 2010 10:11:43 GMT</pubDate></item><item><title>neonp commented on Sometimes I have code blinders on</title><description>value maybe null if trygetvalue fails. So you have a NullReferenceException when call value.IndexDocuments(...)
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment3</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment3</guid><pubDate>Fri, 05 Mar 2010 10:11:09 GMT</pubDate></item><item><title>Ian Nelson commented on Sometimes I have code blinders on</title><description>Oops, I'm blind too, just realised that "value" is the out parameter :-$
</description><link>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment2</link><guid>http://ayende.com/4424/sometimes-i-have-code-blinders-on#comment2</guid><pubDate>Fri, 05 Mar 2010 10:10:14 GMT</pubDate></item></channel></rss>