Friday, June 22, 2012

Helsinki, Finland, Day 1 - Ruoholahti

Thursday night I flew to Helsinki, catching the 9:25pm flight to Stockholm, followed by a 35 minute stopover before flying to Helsinki arriving at 12:50am Friday morning.  Total flight time including stopover was about 3 hours.  Helsinki is an hour ahead of Oslo.  Arriving into the airport I caught a taxi van that took me to the hotel, the cost was 28 Euros, and took about half an hour.  The driver was quiet, and reminded me of this guy, Sam Rockwell.  I swear it's his twin brother.


My taxi driver.

Another couple took the taxi with me as well, they dropped off pretty close to where I was.  The woman was spanish, and the man, no idea.  I could have taken the bus from the airport but walking around at night at that time, not a good decision, and there's no public transport to the hotel at this hour.The taxi accepts credit cards, good work, as I did not have any cash with me and I didn't find any ATMs near where I was.  Checked in around 2:00am or so, and it's all good.  I'm staying in the Ruoholahti area.  Tomorrow, off to the explore the city.  And take photos as well.  Here's what Ruoholahti looks like from the air.


Ruoholahti, courtesty Wikipedia

This weekend is Midsummer weekend.  Reminds me of the Shakespeare play, a Midsummer Night's dream.  Never really understood what Midsummer meant, I suppose if you've lived in Asia your whole life you would have no clue either, but now that I'm in Europe I've been enlightened.

Friday, June 8, 2012

NDC 2012 Day 3, and the end of the Norway nationwide strike

This is a technical blog entry of what I've learnt during the day. So if you don't have a computing background you might not understand all of it. That or you might find it rather head spinning. 

9am Had a coffee before I started.  First session of the day was "Thinking in Functional Style using F# and (some) C#" by Venkat Subramaniam.  He gave a session on Design Patterns the day before, and that was good so I thought I'll give this one a go too.  I actually own one of his books, "Practises of an Agile developer".  Should have gotten his autograph but I forgot.  He started off by talking about what it means to have a functional language, and whether this means other languages are dysfunctional.  He talked about the paper that Dijkstra published, that using goto is evil.  He talked about immutability, and that it's about transformation of state.  OOP was created in 1967, and made popular by C++, and took 23 years to be popular.  Functional programming has existed for 50+ years, and it's not popular (yet).  But this might change, he talked about how running multithreads on a single processor was like multi processing.  And shared mutability causes problems, that it's the devil's work.  You have to ensure that your X number of threads do not collide, and even providing locks does not necessarily mean your code is correct.  Most concurrent applications are broken.  He said pure functions do not modify state, and mathematicians and those who love correctness of code, love functional programming.  A pure functional language does not modify state after creation, but F# is not pure.


Venkat Subramaniam.


What his session covered.


Variables are bounded once created.  The second assignment (=) is really just a boolean operation, so temperature is still 25.

From the slide above, you can use the mutable keyword to change temperature.  So you can do the following.

let mutable temperature = 25
printfn %d, temperature
temperature <- 15
printfn %d, temperature // Temperature now 15

He talked about higher order functions, functions which call other functions, and allow composition using functions.  And how purity allows easier reordering of functions at will, since there is no state order to maintain.  He talked about how a function has a name, body, return type, and a parameter list.

e.g.
List<int> num = new List<int>() { 1,2,3 };
num.ForEach((e) => Console.Write(e));

(e) is the param list
Console.Write(e) is the body
the function name is an anonymous function whose return type is inferred.  And this makes ForEach a higher order function.  ForEach becomes an internal iterator, it is better and more concise.  It's better than using a for loop which is like a lazy dog. :)

Again he talked about idioms, and programming is not about syntax, but about idioms.  He relates this to idioms in society. e.g. one way to do a for loop in F# is.

let numbers = [1..6]
for e in numbers do
  printf "%d", e
printfn ""

The idiomatic way to do this is
List.iter(fun e -> printf "%d" e) numbers
or
List.iter(printf "%d") numbers // more consise

Functional programming would be nice if there is garbage collection.  He also mentioned that think of functional programming as state transformation and not state mutation.

Here's an example of imperative style in C#

List<int> x = { 1,2,3 };
var doubled = x.Select((e) => e * 2);
... // then foreach

and functional style in F#

let x = [1..6];
printfn "%0" (List.map (fun e -> e *2) numbers) // prints 2..4..6.. 12
printfn "%0" numbers // 1...6 i.e. immutable

He ended with an example as follows to show the highest stock price among selected stocks below the price of $500.



10:20am Next session was "HTML5 and CSS" by Chris Mills from Opera.  His slides will be available at slideshare.net/chrisdavidmills.  He talks about how tech tech undergo a honeymoon period. And then they sort of flatten off.  So do you need it?  Browsers currently have specific implementations for CSS and so you need to use these prefixes. e.g.

background: -webkit-linear-gradient
background: -moz-linear-gradient
background: -ms-linear-gradient
...

And it's important to have graceful degradation.  He said to build a base that works, and works better in modern browsers.  To use media queries for different content depending on the resolution, and to use web fonts.  Sometimes graceful degradation doesn't work, and if that's the case to use a fallback mechanism e.g. flash fallback for the video tag.  Or you could use modernizer to take care of it.  He also mentioned IE conditional includes of CSS are useful.  These are ignored if not required.  Other websites which he mentioned are css3pie.com and selectivizr.com.

I had an early lunch which was Chicken Tiki Masala again.  And took some oranges.  And a smoothie.

11:40am The session before lunch was "How to Destroy the Web" by  Bruce Lawson.  A bit of tongue-in-cheek session.  He started off with talking about his daughter saying it was bad to bomb Iran and he wanted to go to the web to show her that Iran was just full of evil people, instead he found this.


Nice Iranian Girl website, fancy that, really I thought they were all evil!

He said that everything leaks out on the web, and therefore you should only let people with the right browsers in.  E.g. restrict people to websites, and force them to use it.


Bruce Lawson.

One way to force people to use only certain browsers, is to look at user agent strings and block them if they use these. :D


Nuff said..

Another way to destroy the web, is to only allow users with the right devices in, e.g. iPad only websites.  Great idea.  More people in india have phones than access to flushing toilets.  So restrict third world countries by making them iPad only!  Muhahahaha...  another way to destroy the web, require plugins.  For example, the South Korean government requires all banking and ecommerce transactions must use ActiveX on Microsoft Explorer.  Or write something that require Native Client, by Google.  Making the web country specific is another great idea on how to break the web.  He refers to youtube.com as kittens on skateboards.  And showed some opera data that presented the conclusion that people across many countries want to visit the same sites but consume these sites on different devices.

He talked about how the #! hasbang technique broke the URL addressing system, good work guys.  And how the NYSE euronet website has a pretty good example on how to break the web by providing a really stupid user agreement that nobody reads. :)  You can also require specific types of hardware, e.g. need a mouse, so you can force disabled people to not use the web because it would be too hard for them.  He showed examples like the "Create a filter" link in Gmail was created using a span, which does nothing for a screen reader.  Or use empty body tags in HTML and have all content created by javascript. :)  Censoring the web, but only at the government level works, i.e. the Scunthorpe problem, if you search for clitheroe, lightwater, penistone, well it's hard to get results for these words for some reason!!

Ended with a message, that we must "destroy the village to save the village" and the WWW stands for "wealthy western web". ;)

After the session I mostly wandered about and read news on my iPad.  And while walking around I caught this on the wall.


Paul McCartney and Elton John, combined tickets sold 32,530.

At some point during the day they called out prize winners, I stayed around for a few minutes but didn't win anything, boo hoo.  I did take oranges though.  And a smoothie.  Don't remember if I took a coffee, I might have...

1:40pm "Async Part 1 - new feature in Visual Studio 2011 for responsive programming" by Lucian Wischik.  He mentioned how he worked 2 years on Async, and showed a demo with the spinning toilet bowl of death in Windows 7. :D  Windows 8 doesn't have the spinning toilet bowl.  Async was created to help with UI responsiveness.

He showed some code that looked like this

async void Button1_Click() {
  await LoadSettingsAsync(); // kicks off download.  Task remembers where it left off, and some stage, packet arrives, message pump finds Task and finishes LoadSettingsAsync method
  UpdateView();
}


async Task LoadSettingsAsync() { // Async method use Async suffix
  await IO.Network.DownloadAsync(path); 
}


Left side UI thread, right side IOCP thread.

I don't fully understand it yet.  But it's something about the message pump, that the UI message pump is key to async.  Await always resumes back on where it's called from.  Async and await do not create threads.  Task is important too.  For example

Task<string> // means I will at some time in the future return something of string

"Expert C#" book that he recommended to read.  And the take home message was that "Asynchrony and concurrency to not need multiple threads" and all "Async library code should return Tasks and take cancellation tokens".  Everything should be up on blogs.msdn.com/lucian in a week.

Had a coffee before I started the next session.

3pm "Async Part 2 - deep dive into the new language feature of VB/C#" continues from the previous session.  I didn't have much notes written down during this session as it was a lot of code which I didn't fully understand.  Refer to blogs.msdn.com/lucian in a week.

Had some salad and corn before the last session.  And some oranges.

4:20pm Last session of the day was "Caring about Code Quality" by Venkat Subramaniam.  This one good too, and all in all, I attended a total of 3 of his 4 sessions conducted over NDC.  This talk had more slides and pretty much zero code.  Here's what he talked about.

  • You can't be agile if your code sucks.
  • Programs are for people to read, incidentally for machines to execute. (Abelsson and Sussman)
  • Fixing problems are 100x more expensive than during requirements phase.


Managers take note :P
  • Peer reviews catch 60% of defects.  But "priesthood" reviews are useless, people who review code should be people who write the code.  Don't get some architect who writes no code or works on a different project to review someone who works on a different project.
  • Disciplined personal practises can reduce defect introduction rates by up to 75%.
  • Nobody cares about standup meetings.  Ironically most companies practise this, he termed this agile by convenience. ;)
  • Building high dependability software costs 50% more per source instruction.
  • Find a champion for quality in a project, and set a 3, 6, 9 month period on measuring and improving quality for the project.
  • Companies never have time to do it but have time to redo it.
  • Pay your technical debt, this will hamper progress if left undone for a long time.  It's just like credit card debt left unpiled that will just kill you in the end.
  • Code must be readable, that means someone else must be able to read it, not just you.
  • Never leave programmers in isolation.
  • Learn by reading good code.
  • Keep it simple! 


You know which road companies often take.... :P
  • Write tests with high coverage.
  • Run tests before checkin, and checkin frequently.  It's okay to check in stuff that does not work.  Never get merge hell!  Always give it. :)
  • Learn your programming language, i.e. the one you use.
  • Programming is a team effort and requires collective ownership.
  • Promote positive interactions in a team, tell people how it could be better not how bad it is.
  • Provide constructive feedback and constant code reviews in a team.
  • Everybody's code needs to be reviewed, rotate reviewer for each review. "Code review makes me a Hero or makes me Smarter."
  • Treat code coverage as cholesterol levels.  For example the Guantanamo tool will delete all lines of code without tests.  Sounds bloody excellent!!
  • Keep things small, i.e. cyclomatic complexity should be small.
  • Methods should just do one thing, one level of abstraction.
  • Use simian to detect duplicate code (however remember duplicate code for different roles is okay, as according to Robert C Martin)
  • C.R.A.P metric (look it up)
  • Don't reply on JDD, Jesus Driven Development, Hope, and all that sort of thing which crappy companies practise.
  • Risk table! 
    Complexity Low -> Automated Tests Low -> Risk High
    Complexity Low -> Automated Tests High -> Risk Low
    Complexity High -> Automated Tests Low -> Risk High
    Complexity High -> Automated Tests High -> Risk Medium
  • Code smells are somethings that are not right in the code, that make you feel dirty, you can't understand it, it's hard to explain and it does some magic.
  • William Zinsser "On Writing Well" book recommendation.
  • Don't be clever, be clear.
  • Comments should explain why it exists, i.e. you should never have to explain a joke just like a comment.
  • Make it easy to look at errors!
And that's it.  He provided a summary as well but that's pretty much all I've written above.  I took more oranges before leaving.  To conclude, today's the last day of NDC and 5:20pm was the time I left.  There will be an NDC 2012 video torrent available sometime soon on the NDC website.  It's back to the office on Monday. Today was the work summer party as well but I'm tired so I didn't go, opt for the lazy way out and go home instead.  Oh and the nationwide strike ended yesterday, June 7th. The workers ended up not getting anything. That's really too bad for them but they should consider themselves fortunate that they're not Greek right now. Or that Norway's not using the Euro.

Update: NDC 2012 videos are now available on vimeo.  You can thank me by posting a comment. ;)

Thursday, June 7, 2012

NDC 2012 Day 2

This is a technical blog entry of what I've learnt during the day. So if you don't have a computing background you might not understand all of it. That or you might find it rather head spinning.

9am Another morning start and this time the trains ran on time.  I met a work colleague today, turns out he is attending days 2 and 3, but he showed up late for the morning conference.  So we talked for a bit after 1st session.  I chose the session called "Javascript All Over - Sticking your big toe in Node.js" by Sara Chipps.  Unfortunately the session did not meet my expectations, the description of the session said there was going to be a working Node.js program in 60 minutes.  Instead the talk was about failure in one of her hackathon sessions in New York, so it was completely different to what the talk was supposed to be about.  Here's the supposed description "In this talk we will build our first node appliation together.", "learn how to send serverside JS clientside, how to write our own modules and where to look for simple hosting".  Needless to say, I was disappointed.  That's the problem with these talks, you don't really know what you're getting, and in this case it was completely different.  I don't think many people were happy.  Anyway, she suggested a book called Peopleware and mentioned that software failure is often people, not technology.  She mentioned hackathon sessions in new york like Photohack day where if you win the hackathon you get to be on the NASDAQ screen and $10,0000 (Not relevant, but she also made a joke on how $10,000 is like 5 NOK.).  Also talked about the face.com API which is apparently quite interesting, it can recognise your face and tell if you're a girl or a boy in percentage terms and things like that.  Also talked about Node.js hosting.  Which is apparently a javascript framework of sorts, that's as much as I know.  She said she spent too much time on authentication frameworks in her application which was basically allowing anyone to upload a picture and getting an octocat (search for it on google, it's the mascot of the Github website).  And that was the downfall of the team, apparently everyone else in her team of 4 (including her) worked their asses off but she failed them.  So the supposed would be very  cool application, wasn't completed in time during the allocated 24 hours.  Her lesson learnt was to only learn 1 thing new at any one time.  And that's it pretty much.  I didn't learn anything of Node.js which is well, very disappointing.  Not sexist or anything, but I don't usually see female presenters present much, so it was a real letdown!  Also her code presentation broke down several times, bummer.


Sara asking "Who has done client side Javascript?"


Her background.

Had a banana smoothie before the next session.  (Note: The food that I had for the entire day is the same as the previous day.)

10:20am  This session was freaking great.  Venkat Subramaniam presented "Design Patterns for .Net Programmers".  He began with "I hate design patterns" because they are not a good way to innovate design.  He gave an example of how your grandma makes great cakes, and you asking her for instructions to bake one doesn't necessarily mean that you'll make a great cake.  He is referring to the GoF (Gang of Four) design patterns book which are written by "grandmothers" of the industry.  He did say that they are a good tool for communication.  He typed code on the fly and showed how to make them better to read and understand.   The first example he gave was the Cascade pattern.  Basically it allows you to daisy chain functions by returning the object itself.  e.g.

class Mailer { // all void methods
  to(string);
  from(string);
  subject(string);
  body(string);
  send();
}


class Sample {
  mailer = new Mailer();
  mailer.to(...);
  mailer.from(...);
  ...
  mailer.send();
}

Not very nice to read or follow.  Instead change it to the following.

class Mailer {
  Mailer to(string);
  Mailer from(string);
  Mailer subject(string);
  ...
}


class Sample {
  mailer = new Mailer();
  mailer.to(...);
        .from(...)
        ....
        .send();
}

That's now a lot easier to read and use.  But how do you know when to stop, as in knowing that send is the last method to use?  Well you could wrap up the send method up in a static class like this.

class Mailer {
  static send(Action<Mailer> action)  {
    Mailer mailer = new Mailer(); // private c'tor for Mailer
    action(mailer);
  }
}

then to use it, do the following

class Sample {
  Mailer.send((mailer) =>
    mailer.to(...)
              .from(...)
              .subject(...)
              .body(...));
 }

Nice!  He also gave a pluggable behaviour example.  I won't provide the code sample here but it involves using Funcs, which is basically the strategy design pattern.  Also mentioned how idioms are useful, learning idioms from another language can allow you to apply them to a different language.  He also talked about the ExecuteAround pattern which basically means there is only 1 way to use the class.  e.g. try ... finally.. idiom, you can wrap that up in a Resource class and perform the clean up there instead of doing it outside the class.  Then you pass in the Resource class the Action you want to perform on the Resource, and the cleanup will be done by the Resource class.

After the talk ended I had some noodles, the same ones as yesterday, except with chicken.  It was still pretty bad but I just wanted to eat something.  Also had a pear.

11:40am  I attended "Interactive user experience: natural user interfaces" by Alisa Smerdova and Felipe Longe.  They talked about how UI involved over the years, and predicted human to human communication may one day become extinct.  Now that's a scary though.  It will be like Surrogates the movie.  Maybe worse!  Anyway, Felipe gave a demo using Kinect, how he controlled an avatar using his movement on stage, and Alisa talked about Surface and Felipe demo'd that.  Side note, Felipe was reading notes on stage while presenting, not a good idea, does not convey confidence! :)  What else?  WPF 4 provides touch events, and the ScatterView class provides that for free, all you need is to wrap your objects with that class.  After the talk you could walk down and play around with the surface table that was manufactured by Samsung.  Cost?  68,000 NOK or 11,0000 USD.  Surface can detect your entire palm movement as well as the orientation of your finger, so it's a bit more advanced that the iPad.  I played around with a jigsaw game with others around the table for fun, that was interesting.  We were finishing one puzzle when someone else hit another button for a different puzzle so we had to start over, but it shows collaboration isn't that easy and still needs to be though out.


Felipe demonstrating Kinect.


Demonstrating MS Surface.


Demonstrating MS Surface.

Lunch was Chicken tiki masala again.  Had a pear as well.

1:40pm Attended "What is OO?" by Robert C Martin.  Robert started off by talking about epilepsy and how they used to cure epilepsy by separating the left and right hemispheres of the brain.  And that worked, but then people who had that done to them couldn't draw the same triangle/rectangle/bird when presented a triangle/rectangle/bird to them.  Instead they had to vocalise.  So the other half of the brain heard the other half who saw the triangle, and then attempted to draw.  A connection obviously had been broken, and the subjects didn't know they had been rewired.  But that's a side story. :)  Robert said OO is 46 years old, as of this year, and there are 3 paradigms, Structured, OO, and Functional.  He defined paradigm as a restriction that takes things away.  For the structured paradigm, Dijkstra in 1968 published a paper "Goto considered harmful", and that you cannot prove that an algorithm is correct using goto.  This was resolved by using other languages.  So structured programming takes the goto concept.  In 1957, LISP stated that assignment statements are evil, so functional programming takes away assignment.  He suggested reading the SICP book which can be obtained from mitpress.mit.edu/sicp.  The authors in the book mentioned that assignments and threads interfere with time.  In 1967 OO took away function pointers, according to Robert. :)  He also mentioned that the keyword class came from the theory of types from the mathematician Bertrand Russell.  And how Algol led to the Simula language.  Robert also provided examples where C has better encapuslation (since keywords like public, private, etc were not needed in C and in C variables were invisible), has inheritance and can do polymorphism.  So what is OO?  It would be interesting if Robert was interviewing someone for a developer position I think, very interesting.

I had some salad after that.

3pm Attended "Introduction to Rx" by Paul Betts.  He mentioned Core of LINQ is sequence and Monads are what you want to do with data before you actually getting it.  And events aren't composable.  He suggested to watch a video by Eric Meyer proving that IObservable is a list.  And IObservable represents a steam of objects, a future result.  Apparent Rx (Reactive Extensions) solves the problem of race conditions too.  Prior till today I've only watched a video on Rx, and that was more useful than this session.  I feel the talk wasn't much of an introduction.  Was more of a quick dive and a splash.  I didn't really get the talk.  Perhaps I just need to study this on my own. amzn.to/programming-rx provides some videos.

I took a kinder surprise from one of the exhibitors after that.  And some oranges. :D

4:20pm "A better way to learn Refactoring" by Philip Laureano.  I'm indifferent about this session.  It was about refactoring the "FizzBuzz" program.  Look it up on google if you want to know what it's about, it's a simple program.  Basically it involved using Resharper to flatten out every if statement and moving methods into classes, i.e. method extraction.  And anything you don't understand?  You wrap it in a region and then refactor what's outside of the region first.  He did add you shouldn't do this without providing tests first.  Which we know isn't happening in the real world.  I probably should've spent the hour in a different session.  It ended early and I went to another session "Dealing with Dynamically Typed Legacy Code" which by Michael Feathers but that kinda ended early too so I didn't learn anything.

Had some dinner after that, noodles with prawns.  Bland but space filling. :D  And another kinder surprise.  And some oranges too.

5:40pm Last session of the day was "Deep Design Lessons" by Michael Feathers.  He talked about the "tell don't ask" pattern.  Never pass control flags to methods.  Rampant problems in error handling using Exceptions.  And Postel's law, the robustness principle which states "be conservative in what you send and liberal in what you accept".  He related that to a pipe, where the ends are fatter than the parts joining the ends.  Profound!  Also talked about the law of demeter where exposing internals is bad. e.g. account.calculator.table.cell(12,12).adjust(4) is bad because you're going deeper into the object whereas array.sort.unique.map is okay as each method call represents aspects of the same object.  Again the session ended early so I attended 15 minutes of "Debugging the Web with Fiddler" by Ido Flatow and that was quite useful.


Michael Feathers.

There was a party at 7pm (?) but I didn't stay for that.  Another long day tomorrow!