Tuesday
Jun242008
Minor code readability
Tuesday, June 24, 2008 at 1:54 Tweet Here's minor thing that just made the code feel a little better:
using (var inputStream = _inputFile.PostedFile.InputStream)
using (var stream = _fileStore.Create(tempInfo))
{
inputStream.PumpTo(stream, <span style="color:green;">128.Kb()</span>);
}
128.Kb() is more friendly to the eye than 1024*128
Reader Comments (2)
That's neat :) You could also have the same for other measures like seconds/minutes. The only problem I see, is that it can be used nonsensically - for example Thread.Sleep(1.Kb()) or inputStream.PumpTo(stream, 128.Seconds()). But garbage in = garbage out, so I don't think I really have a problem with that.
Fredric,
Clear logics of the code could save us from some trouble here. So if we extend int.Seconds() to return TimeSpan, it would disallow us to use derived expressions in pumping code.
Thread.Sleep, on the other hand, accepts the TimeSpan (as any other methods that deal with the timing).
WBR,
Rinat