1

I am basically working on a legacy system where the legacy code is written in Smalltalk language and trying to convert some of the methods in Smalltalk to equivalent method names in Java . These are some of the method names in Smalltalk for a class called Grid. I am not familiar with Smalltalk syntax . What will be the corresponding names in Java and what will the method signature look like ?

  1. at: cell put: data
  2. foreColor: color1 backColor: color2 cell: cell
Frank Shearar
  • 17,012
  • 8
  • 67
  • 94
Geek
  • 26,489
  • 43
  • 149
  • 227
  • 1
    Or, you could persuade management to convert their legacy java code to smalltalk. Much nicer! – Marcin Sep 09 '12 at 21:47

2 Answers2

7

Smalltalk uses inline parameters - similar to Objective C. In Java (and most other languages derived from Algol) this style is impossible if you are using more than 1 parameters. You must therefore use a convention to convert Smalltalk messages with inline parameters into Java methods.

  • The Cocoa Java bindings join the message names using underscores, and append the parameters in order: at_put(cell, data), foreColor_backColor_cell(color1, color2, cell)

  • You could also use a variant of camel case. This, however could cause name clashes (e.g. if there is a Smalltalk message atPut, then you cannot shorten at:put: to atPut)

Aside from the conversion of inline-parameters, you could also run into the problem that the Smalltalk code uses reserved keywords. For example, for is a perfectly valid message in Smalltalk, but you must not name a Java method for. If you run into such cases, you must employ an escape strategy - e.g. by affixing an underscore so that the Java method becomes for_.

Community
  • 1
  • 1
nd.
  • 8,699
  • 2
  • 32
  • 42
  • what does colon (:) signify in Smalltalk messages ? – Geek Sep 06 '12 at 13:55
  • @Geek the colon separates the message-name-part from a parameter value. If you have multiple parameters, then you've got also multiple colons, one for each parameter. The convention when talking about message names (a.k.a. selectors) is to string together all the parts of the name separated by colons, but without a parameter. Objective C (which is heavily influenced by Smalltalk) uses the same syntax http://stackoverflow.com/questions/738622/selectors-in-objective-c may be of interest for you. – nd. Sep 06 '12 at 14:17
2

That's the wrong way to work, btw. If you need java output, have an experienced smalltalker generate it for you from the source. Smalltalk has good reflective capabilities, and it is easy to generate java skeletons. The more interesting problems with converting smalltalk to a legacy language arise with blocks and perform:.

Stephan Eggermont
  • 15,847
  • 1
  • 38
  • 65