In the TinyBlog mini-project of the MOOC, we start by creating the model.
However, since I basically finished the exercises, I wanted to go one step further and ask you guys, what is the correct way _not_ to write all gettters / setters for the fields. TBPost >> titleDo you do it with macros / templates / something else ? I am having a bit of fun (although I would love that they unlock weeks 2 to 7 for me). Thanks in advance. Victor RENE Software engineer, Game designer, Writer Blog: http://victor-rene.com Projects: http://logiqub.com tel: +33 6 26 83 61 76 email: [hidden email] |
Select the class, right click on it: 2016-05-02 17:35 GMT+02:00 Victor RENE <[hidden email]>:
Guillaume Larcheveque
|
In reply to this post by Victor RENE
Hi Victor,
I use the refactoring facilities offered by the contextual menu when a class is selected. You should explore and try this submenus :) Cheers, Cédrik |
In reply to this post by Victor RENE
Or even quicker with the shortcut CMD+H+A
Cheers, Cédrik |
In reply to this post by Victor RENE
Code not tested but ....
#('title' 'text') do: [:each | | body | body := String new streamContents: [ :s | s nextPutAll: each ; cr; tab; nextPutAll: '^ '; nextPutAll: each ; cr]. TBPost compile: body classified: 'accessing' ] Le 2/5/16 à 17:35, Victor RENE a
écrit :
|
1) write them by hand annoying typing required 2) use Class refactorings (right click on class -> refactoring -> class refactoring -> generate accessors; or ctrl+h+a) this will ask you to choose for all attributes… good initially, but really stupid if you are providing e.g. just getters (because then you would need to cancel genreation for all the attributes) 3) use attribute refactorings (right click on class -> refactoring -> inst var refactoring -> accessors -> select attribute) good for individual attributes 4) write the code compilation (ideally as part of some tool) MyClass compile: 'attr ^ attr' classified: 'accessing'. MyClass compile: 'attr: anObject attr := anObject' classified: 'accessing'. Much more typing, but good if you have it as part of some tool (so you can quickly script a gui that would generate it just by clicking on a checkbox or something) 5) use refactoring (this is what the System Browser uses internally) (RBCreateAccessorsForVariableRefactoring variable: #attr class: MyClass classVariable: false) execute 6) use TDD (test driven development) the Debugger will offer you to create the method and you can modify it as you work through (I don't know if TDD is already part of the broadcasted MOOC courses) Typing by hand is annoying, but it's literally two words for getter and four for setter. This mail is probably more words than all the accessors I've created this year… so typing it by hand is no big deal. More importantly the autogenerated code is a bit stupid TBPost >> title: anObject title := anObject this is stupid, so even for generated one I select the argument, press ctrl+t (or right click + suggestions) and select 'rename' ... and rename it into something meaningful like TBPost >> title: aString title := aString But otherwise I regularly use all 1, 2, 4, 5, 6… I never use 3) it's too annoying and distracting because I have to read the labels… I can type in the getter/setter without breaking focus on what I am doing… but it just gave me an idea... :) Peter On Tue, May 3, 2016 at 9:05 PM, stepharo <[hidden email]> wrote:
|
This (usually) doesn't apply to 6 (TDD), because the generated correctly names it based on the real value that is being passed to it. |
Free forum by Nabble | Edit this page |