I thought Andy was talking about source code.
Personally, if I have to rename a method, I search for all senders and fix them with copy&paste. Same for class renames, inst var renames, etc. There just are not that many occurrences, so fixing each one individually is quick, plus I get to verify that the change is indeed what I wanted.
There is a tool to automate a lot of this called the Refactoring Browser, which many developers like, but I don't even have it in my image.
Thanks very much to both of you.
Bert, you are quite right, I was talking about changing strings in source code - sorry, I should have made that clear.
The problem is that we I am dealing with an image where a number of strings have been hard coded into various methods. What I was looking for was a global - source code - search and replace. Does that exist? Or, is it possible to FileOut the entire source tree, do a search and replace externally, and then file it in again. I have tried this in the past, but the image never seems to work properly afterwards.
Clearly, the correct way to solve the problem is to abstract the hard coded text into another object - or maybe a global variable? Perhaps I will just have to bite the bullet. This would make it far easier for internationalisation etc. Actually, are there any packages to help with internationalisation?
Cheers Andy
On 9/11/12, Andy Burnett andy.burnett@knowinnovation.com wrote:
I thought Andy was talking about source code.
Personally, if I have to rename a method, I search for all senders and fix them with copy&paste. Same for class renames, inst var renames, etc. There just are not that many occurrences, so fixing each one individually is quick, plus I get to verify that the change is indeed what I wanted.
There is a tool to automate a lot of this called the Refactoring Browser, which many developers like, but I don't even have it in my image.
Thanks very much to both of you.
Bert, you are quite right, I was talking about changing strings in source code - sorry, I should have made that clear.
The problem is that we I am dealing with an image where a number of strings have been hard coded into various methods.
This is surely not good as it is difficult to maintain, i.e. translation of the interface into another language is not easy possible.
What I was looking for was a
global - source code - search and replace. Does that exist? Or, is it possible to FileOut the entire source tree, do a search and replace externally, and then file it in again. I have tried this in the past, but the image never seems to work properly afterwards.
No I would do the refactoring within Squeak.
Clearly, the correct way to solve the problem is to abstract the hard coded text into another object - or maybe a global variable?
Yes, a simple thing you can do is to shift the strings to the class side and collect them there in a method protocol.
So in an instance method you access the string as
self class myHelpStringHowToAchieveThis
and on the class side you have a method protocol labeled 'string constants'. It contains for this case the method
myHelpStringHowToAchieveThis
^'To achieve x you have to do this and that.'
The next step is as you write to have a global string dictionary. For example MyStrings.
You avoid hard coding the link to this dictionary in many methods you have to access the dictionary indirectly.
So you access it with something like this
(Smalltalk at: #HHMyTextStrings) at: 'myHelpStringHowToAchieveThis'
The first part (Smalltalk at: #HHMyTextStrings) gives you the dictionary (a global variable) HHMyTextStrings without hard coding a dependency on it during loading of the code.
then dict at: 'myHelpStringHowToAchieveThis' is a regular access to a string in a dictionary which keeps strings.
Note:
Instead of referencing a dictionary with HHMyTextStrings the object might be more complex.
It could for example understand the message
HHMyTextStrings setDefaultLanguage: #French
and then serve the strings in French.
I hope this makes sense.
--Hannes
Perhaps I will just
have to bite the bullet. This would make it far easier for internationalisation etc. Actually, are there any packages to help with internationalisation?
Cheers Andy
On Tue, 11 Sep 2012, Andy Burnett wrote:
I thought Andy was talking about source code. Personally, if I have to rename a method, I search for all senders and fix them with copy&paste. Same for class renames, inst var renames, etc. There just are not that many occurrences, so fixing each one individually is quick, plus I get to verify that the change is indeed what I wanted. There is a tool to automate a lot of this called the Refactoring Browser, which many developers like, but I don't even have it in my image.
Thanks very much to both of you.
Bert, you are quite right, I was talking about changing strings in source code - sorry, I should have made that clear.
The problem is that we I am dealing with an image where a number of strings have been hard coded into various methods. What I was looking for was a global
- source code - search and replace. Does that exist? Or, is it possible to FileOut the entire source tree, do a search and replace externally, and then
Searching is implemented in SystemNavigation. If you don't want to do manual replace or roll your own code, then you can use the refactoring tools in OmniBrowser (note that it has some known bugs in Squeak 4.x).
If you want to search methods which have a String literal that has 'foo' as a substring, then you can use the following expression:
SystemNavigation default browseMethodsWithString: 'foo' matchCase: true
If you want to search for methods, which have a String literal 'foo', then try this:
SystemNavigation default browseAllSelect: [ :method | method hasLiteralSuchThat: [ :each | each isString and: [ each isSymbol not and: [ each = 'foo' ] ] ] ]
file it in again. I have tried this in the past, but the image never seems to work properly afterwards.
If you filed out "system" code and did the search and replace in that too, then things could have gone wrong.
Clearly, the correct way to solve the problem is to abstract the hard coded text into another object - or maybe a global variable? Perhaps I will just have to bite the bullet. This would make it far easier for internationalisation etc. Actually, are there any packages to help with internationalisation?
If you don't want to hardcode Strings, then you can use a class and create class side methods for each of string. Or you can create a SharedPool, but the class sounds like a better solution for your problem.
In the soon to be released Squeak 4.4 GetText support is coming.
Levente
Cheers Andy
On Tue, Sep 11, 2012 at 2:48 PM, Andy Burnett andy.burnett@knowinnovation.com wrote:
I thought Andy was talking about source code.
Personally, if I have to rename a method, I search for all senders and fix them with copy&paste. Same for class renames, inst var renames, etc. There just are not that many occurrences, so fixing each one individually is quick, plus I get to verify that the change is indeed what I wanted.
There is a tool to automate a lot of this called the Refactoring Browser, which many developers like, but I don't even have it in my image.
Thanks very much to both of you.
Bert, you are quite right, I was talking about changing strings in source code - sorry, I should have made that clear.
The problem is that we I am dealing with an image where a number of strings have been hard coded into various methods. What I was looking for was a global - source code - search and replace. Does that exist? Or, is it possible to FileOut the entire source tree, do a search and replace externally, and then file it in again. I have tried this in the past, but the image never seems to work properly afterwards.
If you select the string in the method pane and press alt + e you get a browser with all occurrences of the selected string
Karl
Clearly, the correct way to solve the problem is to abstract the hard coded text into another object - or maybe a global variable? Perhaps I will just have to bite the bullet. This would make it far easier for internationalisation etc. Actually, are there any packages to help with internationalisation?
Cheers Andy
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
beginners@lists.squeakfoundation.org