Ayende @ Rahien

Unnatural acts on source code

Redefining If

I had time today to sit on several Brail bugs. I keep getting more and more and more amazed by the power that Boo is giving me.

In order to fix some of those bugs, I had to literally change the meaning of the if statement. (I defined my own nullable propagator, which I had to implement deeply into the language).

Damn, I love this language.

Oh, and FYI, if 2+2 == 4 will not do the expected thing anymore :-) 

Comments

Avish
10/04/2007 07:49 PM by
Avish

How did you redefine if? A custom compiler step?

Ayende Rahien
10/04/2007 07:51 PM by
Ayende Rahien

Yeah, fairly amazing.

https://svn.castleproject.org/svn/castle/trunk/MonoRail/

Castle.MonoRail.Views.Brail/FixTryGetParameterConditionalChecks.cs

Basically, transform "if ?Errors" to "if not TryGetParameter("Errors") isa IgnoreNull"

Steven Harman
10/04/2007 08:38 PM by
Steven Harman

if 2+2 == 4 will not do the expected thing anymore

And what about the Principle of Least Surprise... breaking your own rules, eh? :)

Miles Thompson
10/04/2007 09:20 PM by
Miles Thompson

Ayende,

I worship you like a god (small G) but.. seriously 'redefining if'.. argh, sounds much more like something one would read at the daily wtf (worsethanfailure.com) than here..

Ayende Rahien
10/04/2007 09:26 PM by
Ayende Rahien

Steven,

that was a joke, I am afraid.

Ayende Rahien
10/04/2007 09:30 PM by
Ayende Rahien

Moles,

Oh, then I guess I shouldn't tell when I did to the goto statement, then :-D

Steven Harman
10/04/2007 09:38 PM by
Steven Harman

Haha... my bad. I guess my sarcasm didn't quite come across... I seem to have trouble with that when it comes to written communication. I supposed I could have used a little markup to help.

insert snarky comment here

:)

Avish
10/05/2007 12:30 AM by
Avish

Uhm, maybe I'm not reading it right, but wouldn't it be easier to make your null object equal to null by overriding Equals()? then you'd still be able to do "if ?Errors" etc. What am I missing?

Ayende Rahien
10/05/2007 12:38 AM by
Ayende Rahien

It would be easier, but Boo emits an opEquality test, and since we are dealing with duck typing here, it will not note the user defined opEquality or the Equals() override

Comments have been closed on this topic.