Live data from Hacker News

If-statements in Smalltalk (2008)

pozorvlak.livejournal.com

41–50 of 51 posts

Re: If-statements in Smalltalk (2008)

#41
post #8

Anyone interested in playing around with Smalltalk can use https://pharo.org - I recently tried it and was pretty amazed with the quality of documentation available. It is quite a different experience working in an interactive live environment.

I briefly looked into it, but I can't seem to figure out what to make with it. It looked like you couldn't write an application with any portability, and any user would basically have to run a smalltalk vm to use your application. Am I mistaken?

Re: If-statements in Smalltalk (2008)

#42
post #8

Anyone interested in playing around with Smalltalk can use https://pharo.org - I recently tried it and was pretty amazed with the quality of documentation available. It is quite a different experience working in an interactive live environment.

I briefly looked into it, but I can't seem to figure out what to make with it. It looked like you couldn't write an application with any portability, and any user would basically have to run a smalltalk vm to use your application. Am I mistaken?

I'm no expert (not even close), but I believe they'd have to run Pharo itself, yes. So you could redistribute the Pharo runtime along with your app code (similar to, say, Python).

You may be able to build web applications too (http://seaside.st/).

Re: If-statements in Smalltalk (2008)

#43

Earlier quoted context omitted.

> As in nature the language that thrives is the fittest for its environment, not the most powerful. Now hold on. The most successful sprog of nature is humanity[citation needed] and we're a case study in the fact that raw intelligence is more effective than fitness for any particular niche. So: as in nature, there may be a bunch of niche languages, but in time they'll find themselves with a conservation status while…

So tell me, how is it that Python and JavaScript now seem to rule the Earth, instead of being locked up in a nature reserve?

When programming languages evolve, "can a human being understand this code?" is part of the fitness function, and more succinct and powerful languages aren't always best for that.

Re: If-statements in Smalltalk (2008)

#44
post #37
post #20

Since if-statements are built out of blocks and message sending, you can easily do some cool things. One of them is building up an abstract syntax tree (AST) of an expression without parsing that expression. E.g. suppose you want to build up an AST of the statement (x Instead of starting with an x of type Number, you would start with an object of type ASTVariable, that responds to the message As an sexp: (ASTIfStatem…

This technique is limited by the fact that it only works if all the messages are sent to x, rather than x being sent some message.

You mean "rather than x being sent to some message"? E.g. 0 > x wouldn't work, because the message #> is sent to 0 with x as an argument? In a case like that you can still make it work by exploiting the fact that arithmetic and comparison operators implement double dispatch. The implementation of > for an Integer would send a message to x:

  Integer::> aNumber
    ^x adaptToInteger: self andCompare: #
Even if x is passed as an argument, to interact with it at some point somebody has to send a message to it. I agree that it can become unwieldy to intercept all possible messages, but for a well-defined subset in your DSL, this can usually be done.

Re: If-statements in Smalltalk (2008)

#45

Earlier quoted context omitted.

Thanks - I've noted that in the post.

Do you remember what the title of that post was? We may be able to track down a copy, given more information.

I'm afraid not, and Googling for quotes from the post only shows up Mark Dominus' post. Also, the Wayback Machine doesn't have a copy :-(

Re: If-statements in Smalltalk (2008)

#46

I wish some of these ideas would bleed into the mainstream. A small simple powerful core language and the minimum possible special syntax.

Smalltalk has been very influential in other ways, especially on Ruby. But yes, it would be great if more languages borrowed the "small simple core" bit (possibly adding some syntactic sugar, like ML does).

On the other hand, it's possible to make (core language + standard library) too small. A particularly bad thing to leave out is a module/separate compilation system, ensuring that a zoo of incompatible module systems will grow up.

You may enjoy Guy Steele's talk "Growing a Language": https://www.youtube.com/watch?v=_ahvzDzKdB0

Re: If-statements in Smalltalk (2008)

#47

Earlier quoted context omitted.

I was really trying to make a narrower point here - that there is a reasonable way to distinguish "part of the language" from "part of the (standard) library" - but I'll bite :-) attr_accessor, as it happens ( http://ruby-doc.org/core-2.0.0/Module.html#method-i-attr_acc... ) is implemented in C code, but one could implement it in Ruby, so I'd count it as part of the (standard) library, and creating accessors is just…

Oh, neat! It's always cool when the authors of content pop onto HN (I see from you karma you're new here, welcome!) Yeah - I heard your point when I first read your post, but it took some more time and reading to understand it. It's a good distinction. What I'm not getting is... So you've got a really precise and elegant line between "language" and "library", but it's not clear what the difference is between patterns…

> I see from your karma you're new here, welcome!

You missed the "created: 3246 days ago" bit, then? :-) But you're right that I don't spend much time here - thanks for the welcome!

> it's not clear what the difference is between patterns and.... maybe idioms?

You're right, it's not a clear distinction. But for our purposes, the important point about design patterns is "must be reimplemented from scratch for each use". Have you read the Gang of Four book? Their patterns all require the programmer to define a bunch of new classes from scratch each time the pattern is used. Compare the Decorator pattern (https://en.wikipedia.org/wiki/Decorator_pattern) to Python's decorators - the pattern requires the programmer to create new classes, forward methods, etc, but the Python feature requires the programmer to write one line of code (which then does all the class-creation and method-forwarding under the hood). The Python feature has successfully obviated the need for the pattern. You still need to write the same amount of application-specific business-logic code, but the machine handles all the tedious plumbing for you. Similarly, attr_accessor and has_many handle the tedious plumbing of getters/setters and collections-backed-by-join-queries, respectively. So the necessary abstraction features have already been added, and there's nothing left to fix. An interesting intermediate case is the Iterator pattern in Python (https://en.wikipedia.org/wiki/Iterator_pattern). Python still has explicit iterators, but standardises the interface so library code can make use of user-provided iterators. It also provides a convenient language-level facility for building iterators, using generator syntax. Haskell, arguably, has entirely absorbed iterators into the language, replacing them with lazy lists.

It's worth noting that the key property of Ruby that allows for things like attr_accessor is the ability to add methods and fields to an object or class at runtime, and thus to do so programmatically. Lisp can similarly dispense with a lot of patterns that are necessary in Java, because Lisp has compile-time code generation in the form of macros. Peter Norvig's talk on this is great: http://norvig.com/design-patterns/ppframe.htm

Re: If-statements in Smalltalk (2008)

#48
post #8

Anyone interested in playing around with Smalltalk can use https://pharo.org - I recently tried it and was pretty amazed with the quality of documentation available. It is quite a different experience working in an interactive live environment.

I briefly looked into it, but I can't seem to figure out what to make with it. It looked like you couldn't write an application with any portability, and any user would basically have to run a smalltalk vm to use your application. Am I mistaken?

This is my understanding, yes - http://wiki.c2.com/?ImageBasedLanguage . Some Lisp systems and the Factor language also work like this (though Factor does a lot of work to ensure that the contents of your image matches the code on disk). I believe it's possible to strip down your image for deployment so it only includes code required by your application.

Then again, we live in the era of Docker, in which it's commonplace to ship an entire Linux filesystem along with your web app. So shipping a Smalltalk VM (2.6MB for Pharo 5.0) shouldn't be too much of a stretch.

Re: If-statements in Smalltalk (2008)

#49

Earlier quoted context omitted.

Oh, neat! It's always cool when the authors of content pop onto HN (I see from you karma you're new here, welcome!) Yeah - I heard your point when I first read your post, but it took some more time and reading to understand it. It's a good distinction. What I'm not getting is... So you've got a really precise and elegant line between "language" and "library", but it's not clear what the difference is between patterns…

> I see from your karma you're new here, welcome! You missed the "created: 3246 days ago" bit, then? :-) But you're right that I don't spend much time here - thanks for the welcome! > it's not clear what the difference is between patterns and.... maybe idioms? You're right, it's not a clear distinction. But for our purposes, the important point about design patterns is "must be reimplemented from scratch for each use…

> You missed the "created: 3246 days ago" bit, then? :-)

Tots did. Errr... welcome, travelling from the land of Lurk?

> You're right, it's not a clear distinction...

Still, does the naming sound right? Patterns that get "encoded" into the language, or made trivial by abstraction features within the language, are idioms?

> Have you read the Gang of Four book?

No :/ The closest I've come, weirdly, was tutoring a friend through a design pattern class. Each time she'd come up and say, "The name of this week's pattern is such-and-such", and from that, I'd get 90% of the way to knowing that pattern was. I've always wanted just a simple list of the names, maybe with linked single paragraph descriptions, but every prior time I've looked I haven't been able to find one.

> add methods and fields to an object or class at runtime

Yes! That's a favorite Ruby trick. Straight up tho - what is the formal name of doing that, specifically, the formal name of the category to which attr_accessor and has_many belong to?

Re: If-statements in Smalltalk (2008)

#50

Earlier quoted context omitted.

> I see from your karma you're new here, welcome! You missed the "created: 3246 days ago" bit, then? :-) But you're right that I don't spend much time here - thanks for the welcome! > it's not clear what the difference is between patterns and.... maybe idioms? You're right, it's not a clear distinction. But for our purposes, the important point about design patterns is "must be reimplemented from scratch for each use…

> You missed the "created: 3246 days ago" bit, then? :-) Tots did. Errr... welcome, travelling from the land of Lurk? > You're right, it's not a clear distinction... Still, does the naming sound right? Patterns that get "encoded" into the language, or made trivial by abstraction features within the language, are idioms? > Have you read the Gang of Four book? No :/ The closest I've come, weirdly, was tutoring a friend…

> Patterns that get "encoded" into the language, or made trivial by abstraction features within the language, are idioms?

Yeah, that sounds like a reasonable term to use.

> The closest I've come, weirdly, was tutoring a friend through a design pattern class.

It's a bit old now, but I think it's probably still worth reading the GoF book - it's clearly written, and much better than most subsequent imitators. In particular, each pattern comes with a "when not to use this" discussion, that more people should pay attention to :-/

> I've always wanted just a simple list of the names, maybe with linked single paragraph descriptions

Would http://wiki.c2.com/?CategoryPattern do?

> what is the formal name of doing that, specifically, the formal name of the category to which attr_accessor and has_many belong to?

I'm not sure. Adding methods to a class at runtime is called "metaprogramming" (which has the more general meaning of "writing code that writes or modifies code"). I don't know of a name for a method that performs metaprogramming, though.

Post reply on HN