Nov 18, 2014

.NET is Open Source

Well, the trend of the latest years resulted in .NET going open source. That is pretty amazing, now it is possible to see what is there under the hood, without searching info in blogs and Q&A.
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.
What's interesting is that it is now easier to go and look at what the class does inside in case of any doubts. From the other hand, that is an abstraction leak - you are not supposed to take into account actual implementation. However, according to a law of leaking abstractions, sometimes that’s inevitable.

Jul 8, 2014

Brackets for the web

While diving into web development I needed a lightweight editor for JS, CSS and HTML files. So I decided to check how it is going for Brackets – open sourced code editor for the web.
After launching
cinst brackets
I 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:


  1. Before writing your own feature, check if somebody already did that
  2. 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 Smile

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

One of the things that smells for me in code is the comparison with boolean literals in C#.
All those things like
image
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:
image

Jan 12, 2014

Git Extensions credentials issue

Second time I faced the issue while working with fresh-installed Git and GitExtensions. While pushing changes to github, GitExtensions said

geissue

I quickly realized that I already fought with that and here is the link to solution, so I could easily find it.

In short, the issue is in the global gitconfig file, [credential] option get some unnecessary backslashes.

Jan 5, 2014

Knockout in short

Knockout is a MVVM-style binding JavaScript framework. Home: http://knockoutjs.com/ – there are docs, tutorials (interactive also) and other. Could be extended by custom bindings.

View Model – pure JavaScript object.

To activate knockout on page: ko.applyBindings(viewModelObjectInstance); Can take second param (DOM object) to activate certain object only.

Observables

ko.observable() - functions that can update the UI when data changes, when setting multiple observables you could chain calls.

Computed

ko.computed() – computed observable. 1st par\am – computing func, second (optional) – ‘this’ for that func. With passing object like {read:func, write:func, owner: obj} you could create writeable computed observable. Computed recomputes dependencies when created and on each run. Circular are avoided (doesn’t enters reevaluating itself).

ko.isComputed(obj) – for all computed

ko.isObservable(obj) – for observables, observableArrays, all computed

ko.isWriteableObservable(obj) – for observables, observableArrays, writeable computed

Observable Arrays

Collections.

Methods like native: indexOf, slice, pop, push, shift, unshift, reverse, sort, splice. unshift\shift  = push\pop but for array start. splice = slice with removing from source array.

Own methods: remove, removeAll. destroy, destroyAll – set _destroy property to objects.

Bindings

Are done via HTML attribute data-bind, like <input data-bind=”text: myName”/>.

visible – applies to .style.display – sets to none or resets back to prev value.

text – sets the element content (innerText or textContent). Escapes the HTML. Could be used in containerless syntax (when no container is allowed in place where you need text) <!——ko text: name——> <!——/ko——>.

html – works with innerHTML.

css – add/remove classes. Static syntax - takes JavaScript object= “css {className: bool_JS_Expr }”. Dynamic syntax= “css: propertyName”.

style – takes JavaScript object. Use fontWeight instead off font-weight (see more in doc)

attr – any attribute. Takes JavaScript object.

Control flow

foreach – iterates by array copying the underlying HTML template. Could take a JS object, param data means array, as is an alias to be used in underlying HTML, there are also several callbacks. Also could use containerless binding syntax.

if, ifnot – adds or removes DOM and maintains bindings. Could be in containerless syntax.

with – creates binding context. Supports containerless.

Form bindings

click – binds a function. First param DOM object, second – event. clickBubble binding allows to sop bubbling. Return true from func to allow default action.

event – bind func to any event. Uses JS object syntax. Params and default action are as in click binding, bubbling is also similer (youreventBubble: false)

submit – like click.

enable, disable, hasFocus – intuitive.

value – for input, select, textarea (use checked for checkboxes).

checked – for checkboxes ad radiobuttons.

options, selectedOptions – for select. Main param is an array.

Templates

Use template binding. Can take either id of template or JS object with params. Manages the DOM to be generated inside and data to be used for binding.

Binding context

$parent, $parents (all parents chain), $root, $data (current context), $index(foreach only), $parentContext (for nested loops), $rawData (usually the same as $data), $context (current binding context),  $element (DOM element for current binding).