teranex weblog - workhttps://budts.be/2010-12-18T12:31:00+01:00VIM: working with "light-projects"2010-09-29T23:32:00+02:002010-12-18T12:31:00+01:00Jeroen Budtstag:budts.be,2010-09-29:/weblog/2010/09/vim-working-with-light-projects<p>While VIM certainly isn't an IDE, there are a lot of plugins in existence to make it more IDE-like. Although I have been working a lot inside IDE's the past few years, I don't really need all those fancy IDE features (and the bloat that comes with it). That's one of the many things I like so much about Vim, I can just add the features I need to the editor. So while there are certainly at least a few plugins to work with projects inside Vim, I came up with my own system for working with "projects" (call them "light-projects" if you wish). One small note: For the moment this method suits my needs, but since I'm only using Vim for about two months as my main editor, this might change obviously.</p>
<p></p>
<p>Basically, my solutions is based on an autocommand for every 'project' and the <a href="http://www.vim.org/scripts/script.php?script_id=3025">command-t plugin</a>. Oh, and sessions as well. The autocommand detects when a file is read (or created) inside the project-directory. In this case, it …</p><p>While VIM certainly isn't an IDE, there are a lot of plugins in existence to make it more IDE-like. Although I have been working a lot inside IDE's the past few years, I don't really need all those fancy IDE features (and the bloat that comes with it). That's one of the many things I like so much about Vim, I can just add the features I need to the editor. So while there are certainly at least a few plugins to work with projects inside Vim, I came up with my own system for working with "projects" (call them "light-projects" if you wish). One small note: For the moment this method suits my needs, but since I'm only using Vim for about two months as my main editor, this might change obviously.</p>
<p></p>
<p>Basically, my solutions is based on an autocommand for every 'project' and the <a href="http://www.vim.org/scripts/script.php?script_id=3025">command-t plugin</a>. Oh, and sessions as well. The autocommand detects when a file is read (or created) inside the project-directory. In this case, it will source the correct 'vimrc-project-file' and setup everything specific for the project. So as an example, suppose we have a project in <code>~/Projects/foobar/</code>. In my <code>.vimrc</code> I add the following line (to be more correct, for most of the projects I would add the line in my <a href="http://budts.be/weblog/2010/09/using-your-bash-and-vim-config-on-multiple-computers/">host-specific vimrc-file</a>, as I mostly use one specific computer to work on a specific project):</p>
<div class="highlight"><pre><span></span>autocmd <span class="nb">BufRead</span><span class="p">,</span><span class="nb">BufNewFile</span> <span class="p">~</span><span class="sr">/Projects/</span>foobar<span class="sr">/* source ~/</span>.<span class="k">vim</span><span class="sr">/projects/</span>foobar.<span class="k">vim</span>
</pre></div>
<p>This autocommand simply sources the foobar.vim file everytime a file in the foobar directory is read, or created. Since the foobar.vim project-file is just a regular vim-script file, you can do anything you want in it. I mostly use it to set some editor properties and add some additional mappings, such as:</p>
<div class="highlight"><pre><span></span><span class="c">" I use autochdir by default, but for this project I prefer</span>
<span class="c">" to always be in the project-root. So we first disable the</span>
<span class="c">" autochdir option</span>
<span class="k">setlocal</span> <span class="nb">noautochdir</span>
<span class="c">" and then we cd to the project-root</span>
<span class="k">cd</span> <span class="p">~</span><span class="sr">/Projects/</span>foobar/
<span class="c">" in this project i like to use ant, so set it up as the make program inside vim</span>
<span class="k">setlocal</span> <span class="nb">makeprg</span><span class="p">=</span>ant\ <span class="p">-</span>find\ build.xml
</pre></div>
<p>I have some other options in my project-vimrc file which are more specific to exploring and navigating code, but I will explain these in a later post I plan to write.</p>
<p>So that's it for automatically configuring vim with settings specific to your project when editing one of the files of that project. One other important aspect of working with projects is to be able to easily open any file of your project. Most IDE's have fancy file-explorers, and a lot of vim-users seem to love the <a href="http://www.vim.org/scripts/script.php?script_id=1658">NERDtree plugin</a>. But a few years ago, when I found the <a href="http://plugins.jedit.org/plugins/?OpenIt">OpenIt plugin</a> for jEdit, I discovered that I can type faster than search my way through a tree-structure of directories and files. <a href="http://www.jetbrains.com/resharper/">Resharper</a> adds a similar feature to VS.NET (did I already mention that Visual Studio is just crap without Resharper?). Just press a shortcut, start typing what you need, and let the program do the searching.</p>
<p>For vim I found the <a href="https://wincent.com/products/command-t">command-t plugin</a>. After installing the plugin you can launch command-t with <code><leader>t</code> (unless you have changed your leader key it will be a backslash, so the correct mapping will be \t). Command-T will index your current directory and it's children. The fact that it indexes the current working directory is one of the reasons why I `cd` to the root of a project in my project-vimrc, so while working on a project Command-T will always index my entire project. The first time you launch it, command-t might take a few seconds before the indexing finishes (depending on the amount of files in the directory-tree), but the results are cached, so next time you launch Command-T it shows up almost instantly. Command-T will now show you a list of <i>all</i> the files in your project. Now you can just start typing parts of the filename (or even of the path to the file) and Command-T will filter out the matching files. If the correct file is selected, simply press enter and Command-T will open the file. I really find this a lot easier than hunting down the file myself.</p>
<p>One last feature of Vim I use for projects are sessions. If your Vim is compiled with session-support (it probably is), you can let Vim write a file which contains a list of all the buffers you have opened (and mappings etc which you have defined while editing). When you want to continue working on your project, you can simply instruct Vim to open the session from the session-file and Vim will restore all the opened buffers, mappings etc.</p>
<p>While this is already useful, I think it still requires to many manual actions. No problem, plugins to the rescue! The <a href="http://www.vim.org/scripts/script.php?script_id=2010">SessionMan plugin</a> makes all of this a lot easier. The first time you start your project, simply save your session with <code>:SessionSave</code>. SessionMan will notice that you currently don't have a session and ask for a name, so you can enter 'foobar' (if that is the very original name of your project). When you start vim again to continue working on your project you can now simply use the command <code>:SessionOpen foobar</code> to open your foobar session. Also SessionMan will automatically save your session when quitting vim. Another useful command is <code>:SessionList</code> (which I have mapped to <code>,s</code>). This shows a list of all your sessions and lets your select the session which you want to open.</p>
<p>So in short, when I want to continue working on a project:</p>
<ul>
<li>I launch gvim</li>
<li>I type <code>,s</code> to open the sessionlist</li>
<li>I select the correct session</li>
<li>Vim restores all my opened buffers and windows</li>
<li>Thanks to the autocommand for the project, vim is correctly setup for the project</li>
<li>I can quickly open files with <code>\t</code></li>
</ul>Learning Vim2010-09-11T18:05:00+02:002010-12-18T12:31:00+01:00Jeroen Budtstag:budts.be,2010-09-11:/weblog/2010/09/learning-vim<p>When I started working on my first PHP project at <a href="http://inuits.be">Inuits</a> I had to decide which editor or IDE to use. Obviously while I was still working in the .NET-world I used Visual Studio, just as almost everybody else. However I also used jEdit at home for PHP, Ruby etc. I always felt that learning a general purpose editor, and learning it very well, is more interesting than learning an IDE for one specific platform (VS.NET in this case).</p>
<p><a href="http://twitter.com/stijnbe">One of my new colleagues</a> recommended me to use NetBeans for PHP development, so I had a look at it. While I'm sure it has a lot to offer, it just didn't feel like the tool I wanted to use. Obviously I had also installed jEdit. While I have always loved jEdit, somehow I wasn't convinced anymore. I also had a look at gEdit, which certainly has potential if you install some extra plugins and configure it, but compared to other editors and IDE's it seems to be rather limited …</p><p>When I started working on my first PHP project at <a href="http://inuits.be">Inuits</a> I had to decide which editor or IDE to use. Obviously while I was still working in the .NET-world I used Visual Studio, just as almost everybody else. However I also used jEdit at home for PHP, Ruby etc. I always felt that learning a general purpose editor, and learning it very well, is more interesting than learning an IDE for one specific platform (VS.NET in this case).</p>
<p><a href="http://twitter.com/stijnbe">One of my new colleagues</a> recommended me to use NetBeans for PHP development, so I had a look at it. While I'm sure it has a lot to offer, it just didn't feel like the tool I wanted to use. Obviously I had also installed jEdit. While I have always loved jEdit, somehow I wasn't convinced anymore. I also had a look at gEdit, which certainly has potential if you install some extra plugins and configure it, but compared to other editors and IDE's it seems to be rather limited. So then there was still that other editor. The editor which has fascinated me since at least 5 years. The editor which I have been using from time to time to make small edits on config files. The one editor which has a history which dates back to 1976. Yes, indeed, I'm talking about <a href="http://en.wikipedia.org/wiki/Vi">vi</a> and it's modern incarnation <a href="http://www.vim.org/">vim</a> (Vi IMproved).</p>
<p>As I already mentioned I had been using vi for at least 5 years to make small changes to config files, mostly over SSH on webservers, so I knew the basics. But the basics are, imho, just not enough to do some serious development. Therefore I decided to try and learn at least one new thing about vim everyday. Be it a new shortcut, a plugin, whatever. Reading an entire article with lots and lots of vim-shortcuts really isn't the best method to learn vim, because it's impossible to memorize them all at once.</p>
<p>However after using other editors and IDE's, such as VS.NET, for so many years, it is difficult to just start with vim, because it has a steep learning curve. By example, I got used to navigating code with the arrow keys, certainly in combination with the control and shift keys, to move the cursor by words and select text. Because I did not yet know the correct vim keys and learning them all at once is impossible I had to find a solution to ease my transition. I found this solution in the mswin.vim script which comes with vim by default. You can enable this script by placing the following lines in your .vimrc file:</p>
<div class="highlight"><pre><span></span>source $VIMRUNTIME/mswin.<span class="k">vim</span>
behave mswin
</pre></div>
<p>This script makes vim behave more like other text editors. It's Vim with bicycle training wheels. You will be able to select text by using the arrow-keys in combination with shift, copy and paste with <CTRL+C> and <CTRL+V>, save with <CTRL+S> etc. Sadly it also uses some bindings, like <CTRL+Y>, which have, by default in vim, a different function thus making those default commands unavailable. While this script is very useful, my goal has always been to learn the real vi-shortcuts so in the end it should be possible to disable the script. You don't keep your training wheels either do you? And a few days ago I learned how to copy/paste from the global clipboard, which I believe was the last shortcut I was missing, so as of yesterday I have disabled the script. Now I hope I don't crash on my face because of the missing wheels :).</p>
<p>Another nice trick I found is to change the color of the statusline depending on the current status. When I'm in normal mode, my statusline is gray, the default for the Mustang colorscheme. But while I'm in insert mode the statusline turns green. To configure this add the following lines to your .vimrc:</p>
<div class="highlight"><pre><span></span><span class="c">" first make sure the statusline is always shown</span>
<span class="k">set</span> <span class="nb">laststatus</span><span class="p">=</span><span class="m">2</span>
<span class="c">" then define two autocommands</span>
<span class="k">au</span> <span class="nb">InsertEnter</span> * <span class="k">hi</span> StatusLine <span class="nb">term</span><span class="p">=</span>reverse guibg<span class="p">=</span><span class="mh">#005000</span>
<span class="k">au</span> <span class="nb">InsertLeave</span> * <span class="k">hi</span> StatusLine <span class="nb">term</span><span class="p">=</span>reverse guibg<span class="p">=</span><span class="mh">#444444</span>
</pre></div>
<p>Please not that this configuration only works for gVim, not the terminal version. But it is possible to adapt it for the terminal version as well.</p>
<p>Oh and just as a reference, here are some of the shortcuts I use to replace most of the shortcuts in other editors:
<ul>
<li><b>w</b>: move to the next word (replaces <CTRL+Right Arrow>)</li>
<li><b>b</b>: move to the previous word (replaces <CTRL+Left Arrow>)</li>
<li><b>de</b>: delete the next word (replaces <CTRL+DELETE>)</li>
<li><b>db</b>: delete the previous word (replaces <CTRL+BACKSPACE>)</li>
<li><b>viw</b>: select entire word (replaces <CTRL+SHIFT+Right Arrow>) Note: keep pressing 'w' to select additional words</li>
<li><b>"+p</b>: paste from the global clipboard (replaces <CTRL+V> in case you want to paste text from another application)</li>
<li><b>"+y</b>: copy to the global clipboard (replaces <CTRL+C> in case you want to copy text to another application)</li>
<li><b>"+d</b>: cut to the global clipboard (replaces <CTRL+X> in case you want to cut text to another application)</li>
</ul>
</p>
<p>I'm also using some very useful plugins to help me code, and I have some nice config-settings in my .vimrc, but i'll show these in another blogpost.</p>Married and a new job!2010-06-18T18:18:00+02:002010-12-18T12:31:00+01:00Jeroen Budtstag:budts.be,2010-06-18:/weblog/2010/06/married-and-a-new-job<p>As you might have read on <a href="http://twitter.com/teranex/status/15403437874">my Twitter</a>, I got married two weeks ago. My wife - it still feels strange to say :) - is the most wonderful girl on this planet, and far beyond.</p>
<p>Our marriage really was a day which i will remember for the rest of my life. Everything was perfect. Obviously a few small things went wrong, like arriving at the church without the bridal bouquet (doh!), but we really enjoyed the day!</p>
<p>For those interested, our wedding dance was <a href="http://www.youtube.com/watch?v=c0prLk9xhOQ">Beste Banaan</a> by Kommil Foo. Our DJ was <a href="http://www.djpatrice.be/">DJ Patrice</a>, who really did a wonderful job! A DJ who gets nearly everybody on the dancefloor knows his art! Even people which I never expected on the dancefloor suddenly were shaking their butts off. The people from <a href="http://www.devleeshoeve.be/">De Vleeshoeve</a> served us one of the best BBQs I have ever tasted. Also the icecream from Gelati Van Houcke was really tasty. And thanks to some friends, our reception also was great (thx guys!!)!</p>
<h2>I'm becoming an Inuit</h2>
<p>While most of …</p><p>As you might have read on <a href="http://twitter.com/teranex/status/15403437874">my Twitter</a>, I got married two weeks ago. My wife - it still feels strange to say :) - is the most wonderful girl on this planet, and far beyond.</p>
<p>Our marriage really was a day which i will remember for the rest of my life. Everything was perfect. Obviously a few small things went wrong, like arriving at the church without the bridal bouquet (doh!), but we really enjoyed the day!</p>
<p>For those interested, our wedding dance was <a href="http://www.youtube.com/watch?v=c0prLk9xhOQ">Beste Banaan</a> by Kommil Foo. Our DJ was <a href="http://www.djpatrice.be/">DJ Patrice</a>, who really did a wonderful job! A DJ who gets nearly everybody on the dancefloor knows his art! Even people which I never expected on the dancefloor suddenly were shaking their butts off. The people from <a href="http://www.devleeshoeve.be/">De Vleeshoeve</a> served us one of the best BBQs I have ever tasted. Also the icecream from Gelati Van Houcke was really tasty. And thanks to some friends, our reception also was great (thx guys!!)!</p>
<h2>I'm becoming an Inuit</h2>
<p>While most of the time, I enjoyed working for <a href="http://www.itemsolutions.com/">Item Solutions</a>, i felt that it was time for something new with some new challenges. When i was at <a href="http://fosdem.org/2010/">FOSDEM</a> this year I discovered a job offering for a Linux engineer at <a href="http://inuits.be/">INUITS</a>. After a few weeks - i'm not a linux engineer after all - i decided to give it a try. While that specific job offering was already filled in, they still where interested to meet me. After two talks they offered me a job, starting as a PHP/Drupal/Ruby developer. I didn't have to think long to decide that i really wanted to accept the job. So, as of mid-july I will become an Inuit.</p>
<p><a href="http://inuits.be/">INUITS</a> is a company which does both infrastructure and custom development, but only uses Open Source/Free Software technologies. As i'm a real Open Source fan and only use Linux and FOSS at home, this really feels like a perfect fit. I'm sure i will learn *a lot* in the coming months and probably years. Learning new and excitings things was something I was really missing lately in my current job. Apart from that i was also growing tired of the windows environment. On top of that I had to travel to Brussels everyday (which takes at least 1 hour from where I live). The Inuits office is 3.6 km from our home (according to Google Maps). Quite a difference!</p>
<p>Inuits also considers itself as a real part of the Open Source community, instead of only being interested in profit. They release patches and code. They <a href="http://inuits.be/news/inuit-and-penguin">sponsor a pinguin</a> in the zoo of antwerp and they help other projects to make this world a better place.</p>
<p>So I am REALLY REALLY EXCITED to start working as an Inuit! :)</p>Implicit conversions in C#2009-03-25T18:51:00+01:002010-12-18T12:31:00+01:00Jeroen Budtstag:budts.be,2009-03-25:/weblog/2009/03/implicit-conversions-in-c<p>Yesterday I came across an interesting article: <a href="http://journal.stuffwithstuff.com/2008/04/08/whats-the-opposite-of-nullable/">What's the opposite of Nullable</a>. While the solution for Non-Nullability is interesting, the reason i'm blogging this is because the article also used a C# feature which i didn't know of: implicit conversions.</p>
<p>And guess what? Today I had a situation where I could use these implicit conversions. My app reads data from a CSV-file, so all the input are just strings. Until now that was just fine. However, at one part of my code I had to process one of the fields which has a fixed format. Say a field is a phonenumber and i need the country-prefix. So I created a PhoneNumber-class like this:</p>
<div class="highlight"><pre><span></span><span class="k">public</span> <span class="k">class</span> <span class="nc">PhoneNumber</span>
<span class="p">{</span>
<span class="k">private</span> <span class="k">readonly</span> <span class="kt">string</span> <span class="n">_number</span><span class="p">;</span>
<span class="k">public</span> <span class="nf">PhoneNumber</span><span class="p">(</span><span class="kt">string</span> <span class="n">number</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(!</span><span class="k">new</span> <span class="n">Regex</span><span class="p">(</span><span class="n">PHONE_NUMBER_REGEX</span><span class="p">).</span><span class="n">IsMatch</span><span class="p">(</span><span class="n">number</span><span class="p">))</span>
<span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nf">ArgumentException</span><span class="p">(</span><span class="s">"Invalid phone number"</span><span class="p">,</span> <span class="s">"number"</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">_number</span> <span class="p">=</span> <span class="n">number</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">public</span> <span class="kt">string</span> <span class="n">Prefix</span>
<span class="p">{</span>
<span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="n">GetPrefixFromNumber</span><span class="p">(...);</span> <span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>Now it is possible to create a (helper-)method in another class to get the prefix like this (this is just a simple example):</p>
<div class="highlight"><pre><span></span><span class="k">public …</span></pre></div><p>Yesterday I came across an interesting article: <a href="http://journal.stuffwithstuff.com/2008/04/08/whats-the-opposite-of-nullable/">What's the opposite of Nullable</a>. While the solution for Non-Nullability is interesting, the reason i'm blogging this is because the article also used a C# feature which i didn't know of: implicit conversions.</p>
<p>And guess what? Today I had a situation where I could use these implicit conversions. My app reads data from a CSV-file, so all the input are just strings. Until now that was just fine. However, at one part of my code I had to process one of the fields which has a fixed format. Say a field is a phonenumber and i need the country-prefix. So I created a PhoneNumber-class like this:</p>
<div class="highlight"><pre><span></span><span class="k">public</span> <span class="k">class</span> <span class="nc">PhoneNumber</span>
<span class="p">{</span>
<span class="k">private</span> <span class="k">readonly</span> <span class="kt">string</span> <span class="n">_number</span><span class="p">;</span>
<span class="k">public</span> <span class="nf">PhoneNumber</span><span class="p">(</span><span class="kt">string</span> <span class="n">number</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(!</span><span class="k">new</span> <span class="n">Regex</span><span class="p">(</span><span class="n">PHONE_NUMBER_REGEX</span><span class="p">).</span><span class="n">IsMatch</span><span class="p">(</span><span class="n">number</span><span class="p">))</span>
<span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nf">ArgumentException</span><span class="p">(</span><span class="s">"Invalid phone number"</span><span class="p">,</span> <span class="s">"number"</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">_number</span> <span class="p">=</span> <span class="n">number</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">public</span> <span class="kt">string</span> <span class="n">Prefix</span>
<span class="p">{</span>
<span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="n">GetPrefixFromNumber</span><span class="p">(...);</span> <span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>Now it is possible to create a (helper-)method in another class to get the prefix like this (this is just a simple example):</p>
<div class="highlight"><pre><span></span><span class="k">public</span> <span class="kt">string</span> <span class="nf">GetPrefix</span><span class="p">(</span><span class="n">PhoneNumber</span> <span class="n">phoneNumber</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">phoneNumber</span><span class="p">.</span><span class="n">Prefix</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<p>But when you only have the phonenumber as a string, you'll still have to create an instance of PhoneNumber to be able to call the GetPrefix method:</p>
<div class="highlight"><pre><span></span><span class="kt">var</span> <span class="n">prefix</span> <span class="p">=</span> <span class="n">GetPrefix</span><span class="p">(</span><span class="k">new</span> <span class="n">PhoneNumber</span><span class="p">(</span><span class="s">"+32485123456"</span><span class="p">));</span>
</pre></div>
<p>That is, until we add a method for implicit conversion to the PhoneNumber-class:</p>
<div class="highlight"><pre><span></span><span class="k">public</span> <span class="k">class</span> <span class="nc">PhoneNumber</span>
<span class="p">{</span>
<span class="k">private</span> <span class="kt">string</span> <span class="n">_number</span><span class="p">;</span>
<span class="k">public</span> <span class="nf">PhoneNumber</span><span class="p">(</span><span class="kt">string</span> <span class="n">number</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(!</span><span class="k">new</span> <span class="n">Regex</span><span class="p">(</span><span class="n">PHONE_NUMBER_REGEX</span><span class="p">).</span><span class="n">IsMatch</span><span class="p">(</span><span class="n">number</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nf">ArgumentException</span><span class="p">(</span><span class="s">"Invalid phone number"</span><span class="p">,</span> <span class="s">"number"</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">_number</span> <span class="p">=</span> <span class="n">number</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">public</span> <span class="kt">string</span> <span class="n">Prefix</span>
<span class="p">{</span>
<span class="k">get</span> <span class="p">{</span> <span class="k">return</span> <span class="n">GetPrefixFromNumber</span><span class="p">(...);</span> <span class="p">}</span>
<span class="p">}</span>
<span class="k">public</span> <span class="k">static</span> <span class="k">implicit</span> <span class="k">operator</span> <span class="nf">PhoneNumber</span><span class="p">(</span><span class="kt">string</span> <span class="n">number</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">PhoneNumber</span><span class="p">(</span><span class="n">number</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>Now it is possible to call the GetPrefix method with just a string. The string will be automagically converted to a PhoneNumber, unless it is invalid, in which case the ArgumentException will be thrown:</p>
<div class="highlight"><pre><span></span><span class="kt">var</span> <span class="n">prefix</span> <span class="p">=</span> <span class="n">GetPrefix</span><span class="p">(</span><span class="s">"+32485123456"</span><span class="p">);</span>
</pre></div>Techdays2009-03-12T23:30:00+01:002010-12-18T12:31:00+01:00Jeroen Budtstag:budts.be,2009-03-12:/weblog/2009/03/techdays<p>Gisteren mocht ik voor het werk een dagje van de <a href="http://www.microsoft.com/belux/techdays/">Microsoft Techdays</a> bijwonen. Het was de eerste keer dat ik naar een Microsoft-event ging en had me eerlijk gezegd aan veel show en weinig inhoud verwacht. In sterk contrast tot <del>JavaPolis</del> <a href="http://www.javoxx.com/">Devoxx</a>, waar er veel inhoud en weinig show is. Achteraf bekeken viel dit eigenlijk enorm goed mee. Enkel de keynote ging er wat over. Een Developer Evangelist of Regional Director moet echt niet als één of andere superster worden aangekondigd met loeiharde muziek en lichtshow, maar dat is mijn mening natuurlijk.</p>
<p>Na de keynote heb ik de sessie over C# 4.0 gevolgd en dat was erg interessant. C# 4.0 belooft weer een versie te worden om naar uit te kijken. Eén van de nieuwe features is het <code>dynamic</code> keyword. Dit zorgt ervoor dat je methodes op het object kan oproepen waarbij de compiler niet checked of deze effectief bestaan. De check wordt pas 'at runtime' gedaan. Dit is erg handig om te integreren met andere talen zoals …</p><p>Gisteren mocht ik voor het werk een dagje van de <a href="http://www.microsoft.com/belux/techdays/">Microsoft Techdays</a> bijwonen. Het was de eerste keer dat ik naar een Microsoft-event ging en had me eerlijk gezegd aan veel show en weinig inhoud verwacht. In sterk contrast tot <del>JavaPolis</del> <a href="http://www.javoxx.com/">Devoxx</a>, waar er veel inhoud en weinig show is. Achteraf bekeken viel dit eigenlijk enorm goed mee. Enkel de keynote ging er wat over. Een Developer Evangelist of Regional Director moet echt niet als één of andere superster worden aangekondigd met loeiharde muziek en lichtshow, maar dat is mijn mening natuurlijk.</p>
<p>Na de keynote heb ik de sessie over C# 4.0 gevolgd en dat was erg interessant. C# 4.0 belooft weer een versie te worden om naar uit te kijken. Eén van de nieuwe features is het <code>dynamic</code> keyword. Dit zorgt ervoor dat je methodes op het object kan oproepen waarbij de compiler niet checked of deze effectief bestaan. De check wordt pas 'at runtime' gedaan. Dit is erg handig om te integreren met andere talen zoals Javascript en Ruby.</p>
<p>Een andere interessante feature is 'Generic co- and contra- variance'. Hiermee kan je in speciale gevallen casts uitvoeren zoals:</p>
<div class="highlight"><pre><span></span><span class="kt">var</span> <span class="n">list</span> <span class="p">=</span> <span class="k">new</span> <span class="n">List</span><span class="p"><</span><span class="kt">string</span><span class="p">>();</span>
<span class="p">(</span><span class="n">List</span><span class="p"><</span><span class="kt">object</span><span class="p">>)</span><span class="n">list</span><span class="p">;</span>
</pre></div>
<p>Ook optional en named parameters behoren tot de nieuwe features. Dit is ook erg interessant. Bekijk dit voorbeeldje:</p>
<div class="highlight"><pre><span></span><span class="k">public</span> <span class="k">void</span> <span class="nf">Order</span><span class="p">(</span><span class="kt">string</span> <span class="n">name</span><span class="p">,</span> <span class="kt">int</span> <span class="n">amount</span> <span class="p">=</span> <span class="m">2</span><span class="p">,</span> <span class="kt">int</span> <span class="n">discount</span> <span class="p">=</span> <span class="m">0</span><span class="p">)</span>
<span class="p">{</span> <span class="p">...</span> <span class="p">}</span>
<span class="n">Order</span><span class="p">(</span><span class="s">"jeroen"</span><span class="p">,</span> <span class="n">dicount</span><span class="p">:</span> <span class="m">5</span><span class="p">);</span>
<span class="c1">// the first param - name - is not optional so a value must be supplied.</span>
<span class="c1">// the second param - amount - has default value of 2 which we want to use</span>
<span class="c1">// the third param - discount - has a default value of 0 but we supply 5</span>
</pre></div>
<p>Enkele belangrijke punten bij het gebruikt van deze feature zijn wel dat je parameters absoluut als constante moet beschouwen. Je kan na verloop van tijd in veel gevallen immers niet zomaar de standaard waarde van een parameter aanpassen. Als je in voorgaand voorbeeld de default value van amount zou wijzigen in 3 zouden er plots veel klanten 3 items bestellen in plaats van 2. Ook is het wijzigen van de naam van een parameter niet meer zo vanzelfsprekend omdat deze naam nu ook buiten de methode wordt gebruikt.</p>
<p>De volgende sessie die ik heb bijgewoond ging over WCF. Hoewel de inhoud nogal vrij droog was, was ook dit wel interessant. Vooral de spreker was nogal een grapjas.</p>
<p>De daaropvolgende presentatie ging over WPF en meer specifiek over performantie. Aan de hand van een demo-applicatie waarin een reeks foto's werden ingeladen werden er enkele gangbare performantie problemen getoond en hoe veel van deze problemen vaak eenvoudig opgelost kunnen worden. Bij het laden van 50 foto's gebruikte de applicatie in het begin 1.3 GB geheugen. Na enkele eenvoudige aanpassingen nog slechts 220 MB. Het belangrijkste deel van de oplossing was om ervoor te zorgen dat het aantal elementen in de WPF-tree zo laag mogelijk werd gehouden. Dit werd onder andere bereikt door een VirtualStackPanel te gebruiken ipv een gewone StackPanel, zodat enkel elementen die effectief op het scherm getoond worden ook berekend worden. Een interessante tool die je hierbij kan helpen is <a href="http://blois.us/Snoop/">Snoop</a>. Dit is een open source programma dat ongeveer hetzelfde werkt als de DOM-explorer in Firefox.</p>
<p>Nog een andere sessie die ik heb gevolgd ging over Lean Principles, Agile Techniques, and Team System. Hierbij weerlegde de presentator 7 gangbare foute veronderstellingen ivm software ontwikkeling. Ook liet hij zien hoe je dit kan toepassen mbhv TFS. Gelukkig ging het niet al teveel over TFS en meer over de algemene theorie waardoor ook deze sessie erg leerrijk was.</p>
<p>De laatste sessie ging over Windows 7 for developers. Tijdens de keynote was Windows 7 al even gedemonstreerd, met nadruk op de (multi-)touch features. Tijdens deze presentatie lag de nadruk echter op de gevolgen en impact van Windows 7 voor developers. Natuurlijk werd er wel eerst een globaal overzicht getoond van de nieuwe taskbar en desktop. Die nieuwe taskbar gaat voor vele mensen even wennen zijn, maar ik denk wel dat het potentieel heeft. Een van de andere nieuwe features die me zo nog te binnen schieten die wel interessant zijn, is het beheer van services. In windows 7 is het namelijk mogelijk om te specifiëren wanneer een bepaalde service moet draaien. Een service die een netwerk verbinding nodig heeft verbruikt bijvoorbeeld enkel maar resources als er geen netwerkverbinding is. In Windows 7 kan die service adhv service triggers op de gepaste momenten in en uitgeschakeld worden.</p>
<p>Ook knap was de problem solver. In Windows XP zat er al een soort van problem solver ingebouwd, maar dit was niet erg interessant. Het stelde oplossingen voor die de gebruiker manueel kon proberen en vroeg telkens of het probleem was opgelost om dan een andere oplossing voor te stellen indien het probleem nog steeds aanwezig was. In Windows 7 gebeurt dit geheel automatisch aan de hand van PowerShell-scripts (als ik het correct begrepen heb). Programma's kunnen ook hun eigen problem solver scripts installeren, zodat dit systeem volledig uitbreidbaar is. Voor veel voorkomende problemen lijkt me dit echt wel een interessante en gebruiksvriendelijk feature. Of deze feature echt zal werken hangt natuurlijk af van de hoeveelheid problemen die de problem solver effectief kan oplossen. De demo was knap, maar het was natuurlijk nog altijd een voorbereid 'probleem' (de audio service werd gestopt en de problem solver wist deze correct terug te starten).</p>
<p>Ik heb echter nog wel een bedenking die ik me achteraf nog heb gemaakt na het bekijken van de presentatie over Windows 7. Windows 7 bevat standaard functionaliteit om je eigen applicatie van een ribbon te voorzien (een soort van knoppenbalk zoals in Office 2007), en er werd sterk benadrukt naar developers toe om dit ook te gebruiken. Tijdens andere presentaties kon je al een preview zien van Visual Studio 2010. Het vlaggenschip voor development van Microsoft. En wat valt mij daarbij op? Microsoft maakt hier zelf geen gebruik van de ribbon. Mij lijkt dit toch weer een inconsistentie in de Windows-omgeving. Of zou Microsoft dan toch niet zoveel vertrouwen hebben in de ribbon?</p>