Category Archives: Uncategorized

Simple vs “Simple”

F# has two key features that makes the code very compact. Significant whitespace and forced compilation order.

Significant whitespace removes the need for curly braces or the use of keywords such as begin/end. Forced compile order means your dependencies have to be declared in code files above yours in the project declaration. This gives your F# projects a natural reading order and makes projects follow a natural order that transcends individual style.

Now there is a user voice suggestion that the enforced compile order be removed.

I think this is a good idea. I am against project files. As soon as you have three or more developers working in the same group of files, any one file used to maintain state is bound to become a source of merge conflicts and strife. Just look at C#.

I am sure your IDE could evaluate the dependency order of your files and present them in that order for you, heck one could probably make a CLI tool to show that same information if the navigational benefits of the current order is what is holding you back. Let us break out of IDE-centric languages and allow the programs to be defined in code rather than config.

Powershell woes

What is the point of powershell?
Trying to orchestrate and automate distributed tests with powershell leads to things such as using remote powershell or psexec to start tests on VMs and to use PSDrives to set up tests and collect logs.
So then you would like some calls to be reliable. Starting WinRM on a remote box, or setting up a PSDrive to get fresh executables to VMs or collecting logs neesd to be reliable.
With a 10% successrate out-of-the-box you wonder how people ever use this stuff, and the truth is of course people don’t, they write reliability layers around it with retries and exception handlers, just for the Happy-path nothing-important-has-failed scenario
Had MS spent the extra five minutes to make the built-in code be less unreliable and weak and perhaps to only return a failure once every means to recover the situation had been exhausted would have spared every single powershell user the work to write their own reliability layer just to get the basics working.
Case in point:  New-PSSession. There is no way in the known universe that should be allowed to fail. OK, if there are HTTPS certificat problems or network connectivity problems, say so, but other than that I deserve an apology. Eloquent and part of the return object.  Problem is 90% of the time New-PSSession will fail, for no reason. No reason whatsover.
I mean I know the test triangle and all that, but for that tip of the triangle I don’t need any help from MS to make the system test EVEN MORE EXPENSIVE to make and maintain.

Powershell

I am extending some tests we are running in powershell. It is used to validate that the chef configs we are setting up so that all moving parts are running.

One thing I tried to google that wasn’t  perfectly clear to a n00b like me was how to use static objects in powershell, specifically take byte array and interpret it as a UTF8 string.

Apparently this is how you do it:

$enc = [System.Text.Encoding]::UTF8
$c = $enc.GetString($result.Content)

Where the $result came out of a WebRequest. This means I can test that $c contains an expected value and fail the script, and thus – the build, if the result is unexpected.

TDD setup in VS14

I’ve been trying out VS14 CTP4, doing some code katas and I was thinking if there is a better way I could set up my Visual Studio environment. The NuGet console works well for running tests on the command line or committing code but of course there is an XUnit runner plugin that works well to run the tests from within the IDE. After checking what the gurus say it seems having the test and the production code side by side is the way to go, which is easy when you have one class and one test. Ideally there would be a way to keep the window structure organised in some semi-automated way, but my limited googling has not given me any good answers, although unpinning most windows and keeping the test runner at the bottom and test- and production code in the rest of the screen is quite usable.

I haven’t installed ReSharper on this Visual Studio CTP which gives me a rare opportunity to try the native features before ReSharper saves the day and although the shortcuts are wrong (but you could easily remap Ctrl+. to Alt+Enter and feel less lost immediately) it does have the most basic features you need such as extract method and rename.

Overall it is possible to have a neat workflow as before but you would be hard pressed to let go of ReSharper as the quick create-shortcuts and the easy-to-use refactorings are hard to live without once you have used them in anger.

Posh Git

I have tried to get my head around PowerShell for a while, and I’ve read blogs by Scott Hanselman about PsReadline and PoshGit and decided to finally get on with it and use it properly.

This post is just a repository of my current setup.

Install PsGet if you don’t have it:

(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex

Install PsReadline:

Install-Module PsReadline

Install Git for Windows

http://git-scm.com/download/win

Install posh-git

Install-Module posh-git

Update the profile.ps1 file

Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

# Load posh-git module from current directory
Import-Module PSReadLine
Import-Module posh-git

# If module is installed in a default location ($env:PSModulePath),
# use this instead (see about_Modules for more information):
# Import-Module posh-git


# Set up a simple prompt, adding the git prompt parts inside git repos
function global:prompt {
 $realLASTEXITCODE = $LASTEXITCODE

 # Reset color, which can be messed up by Enable-GitColors
 $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor

 Write-Host($pwd.ProviderPath) -nonewline

 Write-VcsStatus

 $global:LASTEXITCODE = $realLASTEXITCODE
 return "> "
}

Enable-GitColors

Pop-Location

Start-SshAgent -Quiet

set-alias -name np -value "C:\Program Files\Sublime Text 2\sublime_text.exe"

function vsh() {
 Write-Output "Opening first solution..."
 $sln = (dir -in *.sln -r | Select -first 1)
 Write-Output "Found $($sln.FullName)"
 Invoke-Item $sln.FullName
}
 
function title($str) {
 (get-host).ui.rawui.windowtitle = $str
}
 
function ga() {
 Write-Output "Staging all changes..."
 git add -A
 git status
}

function gs() {
 git status
}

function gsd() {
 Write-Output "Pushing changes to subversion..."
 git svn dcommit
}

function gsf() {
 Write-Output "Checking subversion for recent changes..."
 git svn fetch
}
 
function gco() {
 param([switch]$amend, [switch]$a)
 
 $argstr = $args -join ' '
 $message = '"', $argstr, '"' -join ''
 
 if ($amend -or $a) {
 Write-Output "Amending previous commit with message: $message"
 git commit -m $message --amend
 } else {
 Write-Output "Committing with message: $args"
 git commit -m $message
 }
}
 
function gca() {
 $argstr = $args -join ' '
 $message = '"', $argstr, '"' -join ''
 
 Write-Output "Amending previous commit with message: $message"
 git commit -m $message --amend
}

Links

Windows 10 tech preview

So, later than everybody else I installed Win10 tech preview.

I am not agreeing with the versioning strategy and feel like Windows 8.2 had been a more fitting identifier given the limited changes, but the ill-deserved but yet pervasive stigma of the new-fangled Windows 8 had to go away, so I see why going with a major version increase might have made sense.

Multiple desktops is easier to use than Sysinternals Desktops, with the isolation being less complete, so you can Windows Tab between all apps irrespective of desktops and easily move windows between them.

The semi transparent console window thingy is pretty neat but I’m surptised by the limited font choices. Copy / Paste and proper selection just worksTM and I suspect that just like after Ctrl-S arrived in Notepad on Windows 2000 it will probably be inconceivable that it ever worked differently. I installed the operating system on VMWare player and threw in VS14 which diesn’t compile the ASP.NET vNext, but I have spent literally 0 seconds figuring out why and I suspect I haven’t configured something right. The MS Twitter app doesn’t work on my VM, neither does OneGet specifically because Chocolatey is not a provider and no methods of adding providers worked.

I resorted to install Git like a barbarian, downloading the installer from git-scm.com/downloads, but posh-git and psreadline worked as expected. Finally I had a very neat git environment set up in a few moments. I like.

The start menu feels a bit weird, but does make more sense with a desktop OS and I will probably find it more useful as time goes by.

So anyway, if you have an extra computer laying around, get Win10 and try it out. I’ve reported my gripes to the feedback tool, I suggest you do the same. Don’t believe they hype, it’s just a really nice Windows 8.1 Update 2/ Windows 8.2, not  a revolution by any means, just good small improvements overall.

MOVSXD

I have relocated to the Southeastern outskirts of London with my family since I last posted. After 5 years with Jayway it was strange to leave, but a new adventure in a new country awaited. I started working at Cloudhouse Technologies that are developing application virtualisation- and data access virtualisation products. A whole heap of very clever developers work here and we are looking for more such people. We provide ways for companies to leverage new technologies to run applications developed for earlier platforms and network topologies and the work ranges from analysing network logs, designing distributed systems, playing with various low-level API:s and sometimes smithing some websites. I couldn’t believe the job spec when I saw it, it’s like a kinder surprise with all fun things rolled into one. Anyway, so that’s what I have been doing and what has kept me busy.

Microsoft, Apple and the future

I have seen a bunch of uninformed blogs on LinkedIn about the state of large corporations with conclusions based only on hardware preferences of the author, loose speculation and nothing else. I thought why don’t I blog uninformedly on the same subject? I am going to take some of my opinions and state them as fact because let’s face it, I’m right.

Apple vs Microsoft. In a recent study of cool companies people want to work for, Apple scored on top and MS dropped out of the top 20. That seems perfectly reasonable. Microsoft got labelled boring and the wrong kind of evil in the nineties and gradually being proven a lot less evil than both Google and Apple doesn’t help them become cool. Their products are good, not cool. Granted not the best, but better than a lot of them out there, but definitely not cool.

Apple meanwhile deliver decently specified hardware with good margins, iffy software with while showing sub par security conscience. Their iWork Office killer is far from MS Office in terms of features, but sadly for Microsoft, that doesn’t quite matter as much as they would hope. People will take iffy build quality of a laptop (yes), a few missing features of an office suite and a not-very-successful cloud solution if they get a cool laptop that has good battery life. I am not being bitter or sarcastic her. I for instance want the dustbin (the Mac Pro) with very little supporting technical data that would make it win over a traditional tower.

Microsoft just let Nokia fork Android. I’ve said this before, but this would have been the ideal thing to do in the first place. Making several operating systems from scratch just because you think you can is maybe not the most profitable solution. Especially since throughout the early life of Windows Phone, the patents around Android were Microsoft’s top revenue source in the mobile space. Instead having went with an Android fork, focussed on providing excellent gateways towards Microsoft services, driving revenue in Bing/Azure/Office365 could have been far more efficient in my not so humble or well grounded opinion.

Microsoft have always done well in providing API:s and documenting them thoroughly, knowing that engaging developers to extend and combine your products really helps you in the long run. Eventually Apple realised the same thing and overcame Jobs’ doubts and created the AppStore for iOS and that was a roaring success obviously.

Yes, Microsoft made API:s and an awesome development environment Visual Studio and they brought forth evangelists to tell people what to make with their products, but Apple and Google were on a roll. Quickly scores of .NET developers, that still felt that they could never go Apple because they detested the brand and all it stands for, instead found that switching to Java was a survivable pain to get to develop for a mobile platform that essentially is Windows XP for mobile, a platform where you can do whatever you want with the phone and put it in the store.

The problem is that Microsoft desperately wanted to provide the entire foundation of the ecosystem. While Steve Jobs even back in 1985 was overseeing work on the Big Mac that was UNIX based – what later became NeXTStep and OSX, Microsoft soldiered on making everything themselves from drivers to OS to apps, and they were big enough for a while to get away with it, but it is easier if you take things that exist and work and build on them.

This is where Satya Nadella comes in. His division of Microsoft were forerunners in Microsoft working with open source, as in opening their own projects as well as adhering to external open source standards (OWIN, for instance). Apple, Google and others have a far bigger legacy in Open Source, of course, but Microsoft has been turning around, slowly but surely, and Nadella’s org as been the driving force behind this development. Perhaps this can be an opening for Microsoft getting a little leaner. focussing on a few key revenue sources allowing other areas of significant spend to be dropped, adopting open standards and simply contributing to existing community projects.

The only reason the security problems Apple have faced have been so limited despite the complete non-action from Apple over the decades is that they based their OS:es on a core that other people kept going for them. They made it easy for developers to harness the power of what I like to call the dark side, the *nix open source community, which is as vast as the universe itself, In a way that Windows doesn’t.

As an example of the MS of old: When MS started dogfooding Windows Server in large scale clusters they realised that they need a secure file transfer mechanism and a scripting environment that had a bit more muscle than CMD.exe. They could have implemented an SSH server and gotten both – in a standard way no less, but instead they made Powershell and MS Deploy. Purists would have argued in favour of a proper Bash shell and a unified file system with mount points instead of the unfashionable disk drive system, but that even today can be implemented or at least simulated for the desperate among us.

Maybe the course that Nadella set out is one that will lead to a turnaround for Microsoft. The shrinking OS license revenue will be a problem for a while, but I think there is a way out on the other side, and I am suspecting Nadella might know it.

Finding dependent columns in SQL Azure

When fiddling with database relations in an Azure database you quickly notice you are on your own in terms of tooling in a way that you’re not used to from Microsoft. Metadata however is available so you can work around these things relatively easily.

So: when you are dropping and recreating tables as you design them – here’s a quick snippet to see which columns are depending on the particular table you are editing now:

create procedure show_referencing_relations 
@schemaname sysname, 
@tablename sysname 
as 
select 
 [DropSQL] = 'ALTER TABLE [' + @schemaname + '].[' 
 + ptbl.name + '] DROP CONSTRAINT [' + fks.name + '];',
  [AddSQL] = 'ALTER TABLE [' + @schemaname + '].[' 
 + ptbl.name + '] ADD CONSTRAINT [' + fks.name + 
  '] FOREIGN KEY (' + pcol.name + ') REFERENCES ['
 + @schemaname + '].[' + @tablename + '] (' + col.name + ')',        [ConstraintName] = fks.name,
[Source Column Name] = col.name,
[Parent Table Name] = ptbl.name,
[Parent Column Name] = pcol.name 
from sys.foreign_keys fks 
 inner join sys.all_objects ao on fks.referenced_object_id = ao.object_id 
 inner join sys.foreign_key_columns fkc on 
fks.object_id = fkc.constraint_object_id
 inner join sys.all_columns col on 
 col.object_id = ao.object_id and 
 fkc.referenced_column_id = col.column_id
 inner join sys.all_objects ptbl on fkc.parent_object_id = ptbl.object_id
 inner join sys.all_columns pcol on 
 fkc.parent_column_id = pcol.column_id and 
 pcol.object_id = fkc.parent_object_id
 --inner join sys.all_objects pcol on fkc.constraint_column_id = pcol.object_id
 where ao.name = @tablename

Run it with schema and table names, and you get some SQL to use before and after your planned change. First one to remove the constraints and the second one to restore them. The results of the stored procedure show the name of the constraint, the column in your table that is being referenced plus the parent table and column involved in the relationship.

Then you can quickly write code to drop and recreate these relations.