Skip to content

Comment on Epic Answer - Avoiding If statements

Comments

It's easy - use switch/case statements!

But seriously, isn't it true that Smalltalk doesn't have if statements?

Yes. Smalltalk has the ifTrue: and ifFalse: methods on the Boolean object.

  x > y ifTrue: [ Transcript show: 'Truthy' ]
So it is using polymorphism as the main mechanism. The True object implements ifTrue: by evaluating the block argument and implements ifFalse: by doing nothing. The False object does the opposite.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.