Hacker News new | past | comments | ask | show | jobs | submit login

Let me add a classic "tutorial":

t.rotate (a, v); // Original

t rotate (a, v); // Who needs dot?

t rotate a, v; // Who needs brackets?

t rotate by: a around: v; // Who needs ambiguity?

t rotateBy: a around: v // This is Smalltalk




That's literally from page 2 of this, you could at least state that you're quoting the document.

Also, you missed a step. Before "ambiguity":

  t rotate by a around v; //Who needs commas?


  t.rotate(a, v);
  ...
  t rotateBy: a around: v
I will consider only first and last as the rest is just fluffing around.

Objectively speaking (yeah right) there is no difference and both serve the same purpose. For whatever reason the first form is more visually and mentally pleasing to me.

If it was written by me it would be:

  t.rotate(angle, around);
would also have something more meaningful instead of t unless the scope is very small.


Why not compare it with t.rotate(rotateBy, around)? Could a,v used for many purposes and this example allows us to indicate their role for this specific call?


Because a and v would be more typical variable names than rotateBy and around. Note that the author did not change the variable names in the translation process, they left them alone. So you could drop any variable in there but the calling of rotate becomes clearer (subjective) by switching to keywords and no longer relies on programmer discipline to have good variable names.

And yes, they probably could be used for other purposes. The names are mnemonics for "angle" (a) and "vector" (v). How you arrive at them and what you'd use them for could easily vary across a system.


Because those are names the caller decided upon, so they can just as easily misinform the reader as correctly educate them. The caller could have mistyped the call as

     t.rotate(around, rotateBy)
and the error in the effect might seem very mysterious indeed. The beauty of keyword args is that the mapping of caller's name to function argument name is explicit, and therefore reads correctly or incorrectly immediately at the callsite

     t rotateBy: point around:degrees
is obviously an error, without sending the reader to look up the definition.

Compiler-enforced clarity rather than relying on every individual piece of client code to always name things well & never make a mistake.


[t rotateBy: a around: v] // This is Objective-C

I’ve never seen Smalltalk before, but I did find the verbose syntax of ObjC had some benefits.

That being said, typical C programmers don’t add all that whitespace, so the “who needs dots” and stuff is a bit misleading.


Okay, now do something that's fairly readable in non-smalltalk syntax:

t.rotate(a, v).translate(x, y).scale(w, h);

A better way to remove all the "who needs X" is s-expressions. At least then you are left with something that composes a little bit.


In Toit, which is in some ways a Smalltalk dialect that would be:

t.rotate a v

Alternatively if the rotate method uses named args:

t.rotate --by=a --around=v

(See toitlang.org).




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: