Today I was at a seminar by Andy Hunt called "How Hard Can It Be?" at Valtech (Stockholm, Sweden).
It was a great and very funny seminar and I recommend anyone that has a chance to go to the next one.
One thing that got to me was the discussion about complexity... that is accidental complexity and essential complexity. One example he used was the way a language like Java could isn't very intuitive for people new to development compared to a language like Ruby due to accidental complexity.
In Java you would need "public static void Main(.... System.out.println(..." for the basic Hello, World example, whereas in Ruby you would type 'puts "Hello, World!"'.
IDE's do us a great disservice in hiding accidental complexity by using macros to autogenerate code that is required by the language, but probably isn't of any value for the task at hand.
The point of it all is that when the domain is complex, we have essential complexity, but we should avoid accidental complexity, extra code that creates noice, making the code less readable without adding any value.
He also hinted on the irony of the waterfall method that it wasn't supposed to be used the way it has and in fact the document describing the method was a example of a flawed, non-working model of development.
Some time ago I found a really nice book that uses this way of avoiding accidental complexity that Ruby does for introducing newcomers to programming, Learn to program (pragmatic bookshelf).
On the way home I listened to a podcast about RoR, the Ruby on Rails Podcast episode featuring Stuart Halloway. I've only listened to one episode so far but it was great :), got me thinking of contributing a bit more to Open Source.
Thursday, November 15, 2007
Thursday, November 8, 2007
Degrading link_to_remote
I've been learning RubyOnRails and I noticed that the 'link_to_remote' helper didn't degrade gracefully...
Here's the fix I used (Inspired by this blog post).
(in helpers/application_helper.rb)
Just keep in mind that this uses a HTTP GET when javascript is disabled. A HTTP GET should not have side effects. I can't think of a good way to do a HTTP POST from a link (trigger a form-post) without using javascript.
Here's the fix I used (Inspired by this blog post).
(in helpers/application_helper.rb)
def link_to_remote(name, options = {}, html_options = {})
unless html_options[:href]
html_options[:href] = url_for(options[:url])
end
link_to_function(name, remote_function(options),
html_options)
end
Just keep in mind that this uses a HTTP GET when javascript is disabled. A HTTP GET should not have side effects. I can't think of a good way to do a HTTP POST from a link (trigger a form-post) without using javascript.
Labels:
code,
frameworks,
Javascript,
learning,
Ruby,
RubyOnRails,
Web
Tuesday, September 25, 2007
Dojo at Agical
Yesterday I was at a dojo at Agical in Stockholm.
The idea of a dojo is to as a group drive out the design of a piece of code using TDD. The goal is to practice TDD outside of real live projects.
We used a method called randori that meant that we worked on the code as a pair, describing to everyone what we did and switching out one of us every now and then. It was a trilling experience to say the least, if only too short! I'm definitely going to go to more of these dojo's :)
When we where done we got into discussing the differences between BDD and TDD. What does it really mean to drive your development based on behavior?
The sense I got from it was to not let the testing run away with you. To focus on the real behaviour. What is the point of creating tests for code that define a behavior that you don't have any story for? Excessive error handling can be a suspect in this category.
Aside from that I also got some repetition on the TDD cycle: Red, Green and Refactor. Focus on passing the test, save all refactoring for when it's green. To get ahead of yourself is like premature optimization, tempting but probably not a good idea...
The discussion then continued into whether Code Coverage is a good metric from a BDD perspective. When doing BDD/TDD the number will be high, but it will not tell you if you implemented functionality that was really required or not. You're goal is to solve the problem at hand, not achieving full coverage.
But there are uses for it, one opinion where that the coverage serve as well needed positive feedback for the developers, another that it can be a great tool for finding uncovered code that ought to be run by a test.
I wish that I'd had the time to stay after the dojo, but it was late and I had an early morning :(. It's not often that you get the chance to meet people that actually know their way around these concepts in real life!
The idea of a dojo is to as a group drive out the design of a piece of code using TDD. The goal is to practice TDD outside of real live projects.
We used a method called randori that meant that we worked on the code as a pair, describing to everyone what we did and switching out one of us every now and then. It was a trilling experience to say the least, if only too short! I'm definitely going to go to more of these dojo's :)
When we where done we got into discussing the differences between BDD and TDD. What does it really mean to drive your development based on behavior?
The sense I got from it was to not let the testing run away with you. To focus on the real behaviour. What is the point of creating tests for code that define a behavior that you don't have any story for? Excessive error handling can be a suspect in this category.
Aside from that I also got some repetition on the TDD cycle: Red, Green and Refactor. Focus on passing the test, save all refactoring for when it's green. To get ahead of yourself is like premature optimization, tempting but probably not a good idea...
The discussion then continued into whether Code Coverage is a good metric from a BDD perspective. When doing BDD/TDD the number will be high, but it will not tell you if you implemented functionality that was really required or not. You're goal is to solve the problem at hand, not achieving full coverage.
But there are uses for it, one opinion where that the coverage serve as well needed positive feedback for the developers, another that it can be a great tool for finding uncovered code that ought to be run by a test.
I wish that I'd had the time to stay after the dojo, but it was late and I had an early morning :(. It's not often that you get the chance to meet people that actually know their way around these concepts in real life!
Friday, August 17, 2007
Just a heads up on some Opera browser behavior...
I just discovered a bit of a quirk of Opera (9.01). When you read the .value of a text field and the text field contains something like "Hello <b>world</b>", opera returns "Hello <B>world</B>". I did not find any way of fixing this, except to not assume lowercase input (which seems obvious to me now :). However, I found this interesting blog post about this upcase behavior and other similar things. Just hope this post can help someone avoid the premature assumption that the browser would return what's actually there :).
Thursday, July 19, 2007
TinyMCE inside of an ASP.NET Ajax UpdatePanel
Yesterday I went hunting for information on how to get the
web WYSIWYG editor TinyMCE to work inside of an ASP.NET UpdatePanel.
There are a few solutions for this on the web, nothing near as complete as Jesper Lind's post (Swedish), but even that failed to work. I replied to the post asking if he had some simple example that he could show and as a result we now have this complete example.
Here is a VB.NET version of Jesper's example I made when adapting the code to work in my VB.NET project at work.
Update: 2007-07-30
Having had some experience with using this I'd highly recommend that you use webservices as the editors inside of any non-trivial updatepanel setup can become quite slow to reload.
To use TinyMCE on an Ajax form, load TinyMCE at page load as usual, but run "tinyMce.updateContent(text-area-id)" after you load text into the textareas so that it is displayed. If you have any problems with IE6 not updating the content, check this thread out. Also run tinyMCE.triggerSave(true, true) before saving so that TinyMCE copies text back from the editors.
web WYSIWYG editor TinyMCE to work inside of an ASP.NET UpdatePanel.
There are a few solutions for this on the web, nothing near as complete as Jesper Lind's post (Swedish), but even that failed to work. I replied to the post asking if he had some simple example that he could show and as a result we now have this complete example.
Here is a VB.NET version of Jesper's example I made when adapting the code to work in my VB.NET project at work.
Update: 2007-07-30
Having had some experience with using this I'd highly recommend that you use webservices as the editors inside of any non-trivial updatepanel setup can become quite slow to reload.
To use TinyMCE on an Ajax form, load TinyMCE at page load as usual, but run "tinyMce.updateContent(text-area-id)" after you load text into the textareas so that it is displayed. If you have any problems with IE6 not updating the content, check this thread out. Also run tinyMCE.triggerSave(true, true) before saving so that TinyMCE copies text back from the editors.
Tuesday, May 15, 2007
Neat session state trick
Just thought I'd share a neat little bit of code for handling session state in ASP.NET.
The trick is to create a class that keeps it's own sessionstate, like this:
Then you can save data in session like this:
I heard about this in .NET Rocks! episode 82 where Richard Hale Shaw where speaking of his way of storing session state in a safe way. It's at about 54 minutes into the podcast episode if you want to check it out for yourself =)
The trick is to create a class that keeps it's own sessionstate, like this:
public class CustomerSession
{
private string mName = "";
private string mTelephone = "";
// To enshure unique session key
private static string mGuid = "PlaceGUIDHere";
public string Name
{
get { return mName; }
set { mName = value; }
}
public string Telephone
{
get { return mTelephone; }
set { mTelephone = value; }
}
private CustomerSession() { }
public static CustomerSession GetInstance(HttpSessionState session)
{
CustomerSession o = (CustomerSession)session[mGuid];
if(o == null) {
o = new CustomerSession();
session[mGuid] = o;
}
return o;
}
}
Then you can save data in session like this:
protected void btnSave_Click(object sender, EventArgs e)
{
CustomerSession data = CustomerSession.GetInstance(Session);
data.Name = txtName.Text;
data.Telephone = txtTelephone.Text;
}
I heard about this in .NET Rocks! episode 82 where Richard Hale Shaw where speaking of his way of storing session state in a safe way. It's at about 54 minutes into the podcast episode if you want to check it out for yourself =)
Sunday, May 6, 2007
Partial classes and regions
Just read this blog post about using partial classes to separate the public interface and the private and protected members, which is a great idea.
This got me thinking of a problem I faced this week when working on using the MVP pattern for windows forms development.
One of the forms had two very distinct areas. The left side contained lists to lookup information and the right side displayed the details. This seemed to me like the perfect place to use two views. Now to implement two views in the same code-behind file you'd want some way to separate them. Regions goes some way to solving this, but it's hardly ideal. I'd much rather switch between partial classes in different files than between regions.
Now here's the issue... if you create another partial class to a windows form (in addition to the .Designer partial) the Visual Studio 2005 IDE automatically thinks it is another designer form. You would think they had thought of this scenario?
This got me thinking of a problem I faced this week when working on using the MVP pattern for windows forms development.
One of the forms had two very distinct areas. The left side contained lists to lookup information and the right side displayed the details. This seemed to me like the perfect place to use two views. Now to implement two views in the same code-behind file you'd want some way to separate them. Regions goes some way to solving this, but it's hardly ideal. I'd much rather switch between partial classes in different files than between regions.
Now here's the issue... if you create another partial class to a windows form (in addition to the .Designer partial) the Visual Studio 2005 IDE automatically thinks it is another designer form. You would think they had thought of this scenario?
Subscribe to:
Posts (Atom)