tulipemoutarde.be

Software Developer

Smalltalk, Swift, Java, Obj-C

@fstephany | Email | LinkedIn

I'm currently working at Ta Mère SCRL a small development shop in Belgium.

We mainly do mobile apps (iOS, Android) for clients. We also have a strong interest in Pharo Smalltalk and Rust.

logo Ta Mère SCRL

Seaside WAAnchor fun

14 Jun 2010 in programming seaside smalltalk WAAnchor 

I’m currently playing with Seaside (a Smalltalk web framework) for a pet project. As you maybe know, Seaside is, by default, not very friendly with URLs. I wanted to have bookmarkable URLs for user convenience and for search engine. Ramon Leon explains how he managed to get nice urls for his blog in a super-interesting blog post.

When playing with WAAnchor methods, I fought with a weird behaviour:

html anchor
  callback: [self moveToPage: page];
  useBaseUrl;
  extraPath: page slug;
  with: page title.

did not work, while

html anchor
  useBaseUrl;
  extraPath: page slug;
  callback: [self moveToPage: page];
  with: page title.

worked fine. Can you see the difference in these two snippets?

The reason of the resulting bug is quite simple but is hard to spot when you’re not careful: the method useBaseUrl should always be the first to be called in a method cascade on a WAAnchor. Indeed, both extraPath: and callback: will affect the url of the WAAnchor while useBaseUrl will reset it. This reset will cancel all the operations you’ve done before on the url of the WAAnchor.

Moral of the story: beware of side effect (or How I Learned to Stop Worrying and Love Functional Programming)