Jun 15, 2016
Running .NET Core in Docker container
The idea: run the .NET Core simple application (hello world) in a Linux container provisioned by Docker ecosystem.
May 10, 2015
SourceTree
I decided to try SourceTree DVCS client (I saw an advertisement made by someone, I don’t really remember who that was). And it made me like console.
It looks pretty, has nice UI, but somehow it make me feel pain when using it. At first, its slow - and I'm not talking about huge repos, remote repos, digging deep in history or something like that. Switching focus between latest revisions in history view is done with noticeable lag (all other operations are not faster). Sometimes I'm able to see 2 loading icons when switching focus to next revision. This makes exploring history a little bit painful.
At second, it is not convenient for me to see which branch is my current. [pic here]. Its name is bold in branches list, but branches list does not give much without history. It is also marked bold in history (and a tiny icon overlay), but that does not make much difference, since the history has a lot of bright colors - just having a bold name is not enough (let alone the icon overlay - on my 24" monitor I almost never notice it).
At third, when working with Mercurial, it does not allow to see active branches only - the ones that were not merged into the default branch. I could see either all branches or current branch only, which requires me to change filtering dropdown at the top.
Next, how would you know which branches are local and which are remote? There is no signs for that.
After all, I end up with TortoiseHG (it has its own issues, but at least it is fast).
By the way, here is what Google suggests

Feb 27, 2015
C#6, sugar
All those features does not require new CLR, they are just syntactic sugar (by the way, the whole C# is just a syntactic sugar for IL), so I decided to take a look what they compile to.
I used Jon Skeet’s post as a reference.
Read-only properties initialization
At the first glance they should compile into field initialization – and they are. There are two options, init property in place or in constructor:public class AutoProps { public string InitInPlace { get; } = "HasThisVal"; public string InitInCtor { get; } public AutoProps() { InitInCtor = "from ctor"; } }
The major difference there is that init in place looks like field initialization, which does not allow you to use instance members) and behaves that way too. Well, I asked dotPeek to tell me what does he think about that, and here is how the code looks like after decompilation:
public class AutoProps { [CompilerGenerated] [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly string \u003CInitInPlace\u003Ek__BackingField; [CompilerGenerated] [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly string \u003CInitInCtor\u003Ek__BackingField; public string InitInPlace { get { return this.\u003CInitInPlace\u003Ek__BackingField; } } public string InitInCtor { get { return this.\u003CInitInCtor\u003Ek__BackingField; } } public AutoProps() { this.\u003CInitInPlace\u003Ek__BackingField = "HasThisVal"; base.\u002Ector(); this.\u003CInitInCtor\u003Ek__BackingField = "from ctor"; } }
And, they both are actually initialized in constructor, the difference is only in the order.
Automatically-implemented properties initialization
The same as in place initialization for read-only properties.Expression-bodied members
That is a shorthand for read-only properties, operators and methods – which consist from a single statement. That’s basically is shorter way to write method body – and there is no surprises in compilation results.nameof
Finally, no need to maintain string literals while logging, throwing e.t.c. Compiles into string literal (concatenating with surrounding strings if necessary).Dictionaries initialization
The new dictionaries initialization syntax does not look very different:public Dictionary<string, int> CreateDictionaryOldWay() { return new Dictionary<string, int>() { {"a", 1}, {"b", 2}, {"b", 4}, {"c", 3} }; } public Dictionary<string, int> CreateDictionaryNewWay() { return new Dictionary<string, int>() { ["a"] = 1, ["b"] = 2, ["b"] = 4, ["c"] = 3 }; }
The major difference is in the code it compiles to, while the old way initialization compiles to Add method calls -
Dictionary<string, int> dictionary = new Dictionary<string, int>(); dictionary.Add("a", 1);
the new way uses indexers instead -
Dictionary<string, int> dictionary = new Dictionary<string, int>(); dictionary["a"] = 1;
Using for static classes
Now it is possible to reference static classes in using directive – and this will bring fields, methods and properties of that class into scope without necessity of referencing them with class name. Compiles into fully qualified names (local members have higher precedence when resolving the member). You are free to include two classes with same member names in usings, but you will not be able to use those members – compiler would not be able to detect which one you want to use.String interpolation
That is quite complicated feature, from the point of implementation. Compiles to a string.Format call with a bit of auxilliary code.From
public string GetSentence(string p1, int p2) { return "here I am \{p1}, \{p2}"; }to
public string GetSentence(string p1, int p2) { string format = "here I am {0}, {1}"; object[] objArray = new object[2]; int index1 = 0; string str = p1; objArray[index1] = (object) str; int index2 = 1; // ISSUE: variable of a boxed type __Boxed<int> local = (ValueType) p2; objArray[index2] = (object) local; return string.Format(format, objArray); }
Null propagation
Simple and effective way to hide null check, however I’m not sure that having a lot of null checks is a good sign.As the name implies, that is a shortcut for an expression that could result in null value and thus applicable for reference types (nut also supports Nullable struct).
Compiles to a series of null checks, from
class Node { public Node Child { get; set; } public int Data { get; } } class NullPropagation { public int? GetInfo(Node n) { return n?.Child?.Data; } }to
internal class NullPropagation { public int? GetInfo(Node n) { int? nullable; if (n == null) { nullable = new int?(); } else { Node child = n.Child; nullable = child != null ? new int?(child.Data) : new int?(); } return nullable; } }
Nov 18, 2014
.NET is Open Source
We've got reference source repository, which is intended to serve as a reference, located at https://github.com/Microsoft/referencesource
The new development will be in https://github.com/dotnet/corefx, it already has some libraries uploaded and the rest will come soon.
I decided to take a look into reference source, and the first place I went to was mscorlib assembly. Some notes on internals:
- Extensive use of Code Contracts there
- Some of the classes` internals do not match coding standards (or I comprehended the rules incorrectly)
- There is non-generic static class Nullable :) that is a container for static methods operating on nullables. I’m just curious what is the reason having it? There is no such thing for DateTime, for example.
- mscorlib, System.Web, System.ServiceModel are the monsters, taking more than 17 Mb of code each.
- largest file with code is System.Web.Services\System\Web\Services\Description\ServiceDescriptionSerializer.cs which seems to be obfuscated. It takes about 668KB.
- Task class is more than 6600 LOC
- Not only XML verbose, but its handling routines also – XLinq.cs from System.Xml.Linq\System\Xml\Linq has over 9k LOC and 390 KB size. It’s actually 3rd biggest file that contains code.

Jul 8, 2014
Brackets for the web
After launching
cinst bracketsI got an editor, it appeared that current version is 0.41. First impression was – “too lightweight”, and it is after Visual Studio. The first feature I missed was formatting of selected code – there is no such command to invoke (at least I was not successful finding it). After lurking back and forth, cloning the repo, looking through the code, adding new command to launch some existing APIs – I got what I want, but then I thought – there already should be someone who needed the same functionality. And that’s it, there were several attempts to provide such functionality, starting with the extension that does almost exactly what I did and ending with several cards in projects cardboard, describing different formatting desires.
I end up installing the Beautify extension for formatting and also Code folding for folding regions of code. Both does not look abandoned (Brackets itself as well) and they do the work so far.
There are several conclusions from that story:
- Before writing your own feature, check if somebody already did that
- You could pack Brackets with whatever you want - there are a lot of extensions for almost any needs
Why Brackets? I like its Live Preview feature, when you can edit page and see a result on the fly in browser. I like it for its weight – that’s exactly what I need for prototyping ideas. I like it’s pace of evolution – it’s moving forward quite fast, growing to a mature product. I like the fact that I can add the feature I am missing
Go and check if you haven’t seen it yet.
Jul 3, 2014
My list of tools
Well, tools in a tool belt. Any skilled worker has some preferences, what to use, both for tools and ways to use them. Here are mine:
Visual studio – IDE that I use on everyday basis. Surely it depends on your profile as a developer, what languages do you use; now I use C#, so that’s my IDE of choice. I’m using it starting from VS2005, now it is VS13.
Resharper – VS extension to refactor everything, static code analysis and so on. I appreciate its capabilities for the C# and JavaScript support.
DisplayFusion – multiple monitor taskbar support for Windows 7 (at least I need only taskbar support from that tool, I do not use other bells and whistles). Taskbar for secondary display is what I’m missing most in multi-monitor workstation setup. For me, second display without taskbar loses almost half of its usability. Windows 8 has multiple taskbars support built in, but while I’m on Windows 7 at my work desktop, I have to select among third-party tools. I used ActualTools Window Manager before, but its slowness on my new desktop (I even switched off literally everything in its options except 2nd taskbar) forced me to search for alternative and here it is. So far it is stable and gives me what I want – toolbar with pinnable applications and Aero previews. Now I’m on trial period, will consider buying.
OneNote – collecting my notes and info on both Windows and Android. Synchronization and offline notes. I moved from Evernote because I like interface more – will see if the transition worth time spent on it.
Notepad++ – lightweight editor for everything, supports plenty of formats, but has slightly obsolete interface.
Paint.NET – replacement for standard Windows’ Paint. Editing images – free and powerful – however sometimes not enough powerful. In example, cropping images is not very convenient.
7Zip – compressing and decompressing everything, no comments.
Truecrypt – has been replaced by BitLocker – Windows integrated encryption support.
f.lux – I already posted and article (sorry, that’s on Russian) on that app. I do not have requirements to colors on monitor to look natural, I just want more comfort for my eyes.
Dropbox – synchronization of choice for my files. Considering OneDrive also – so far I do not see killer features that could force me to do the change.
Fiddler – web debugging proxy, allows to look under the hood of web development world.
Teamviewer – remote access to mine home PC + collaboration when needed. Paid for commercial use.
Keepass – keeping your sensitive info at safe; passwords management solution. I also use unofficial port on Android, not very user-friendly though.
Daemon Tools Lite– images management, paid for commercial use.
GitExtensions – UI for git. I still cannot get used to git console when I need to check repository tree.
Skype – messenger of choice. But not mine choice. Personally I do not like its interface, contact groups are not convenient for me, Android version UI is awful.
Windows Liver Writer – the editor which has been used to write this article.
Chocolatey – machine package manager, I use it for installing everything from the above, starting from Notepad++. Basically, that’s one of the first application I’m installing on fresh Windows.
I did not include MS Office there + I might be missing some tools I use occasionally – let it be, I could post about them later.
Feb 22, 2014
comparison with boolean
All those things like
Recently, I was trying to find out, what makes people write such code and came to the conclusion that this is either lack of knowledge of statically typed language or mistake or just a fear of legacy code.
Let me explain the latter. There is a code that is stated it is working (possibly for decades). And there is a need to add a feature/fix a bug in that code. After the work is done, there could be changes that result in such code, and the person who does that changes is afraid of moving forward and lefts the comparison as it is.
Note, that this situation is just my imagination, I do not know exactly why such code exists. The situation is based on client’s legacy code, I have to work on. However, that’s not only clients with 10-years old code. Here is the same in Microsoft documentation:
http://msdn.microsoft.com/en-us/library/bb546150.aspx
The example text: