Review Request: Generate accessors (getters/setters) for C++

Andreas Pakulat apaku at gmx.de
Tue Jan 3 10:56:14 UTC 2012



> On Jan. 3, 2012, 2:11 a.m., Henry Miller wrote:
> > Without even looking at the code or UI, I'm compelled to ask: Do we really want to encourage this type of programming? As a general rule getters/setters are a code smell.  Your classes should do something. Instead of asking a class what values it holds, have it do something that depends on those values. Getters/setters make it hard to change internal implementation latter.
> > 
> > Of course there are exceptions to all general rules, sometimes you need a getter/setter for some purpose.  The question is do we want "purists" that make it hard to write bad code, or do we make it seem obvious to novice programmers that they should do something that most of the time they should not.
> 
> Aleix Pol Gonzalez wrote:
>     I don't know what you're talking about. In C++ in almost all cases variables are read and written using getters and setters.
> 
> Jonas Jacobi wrote:
>     I don't think it encourages a special type of programming, it just makes a common task easier.
>     If you don't know how object oriented encapsulation works, you won't magically know about it, if this dialog is missing, but will just write the same crappy code without it.
>     If you know how it works, you often have to create getters/setters anyway and this will make the task easier.

As Aleix and Jonas already said just because you can shoot yourself in the foot with this is not a reason to not have the feature. Of course its usually not necessary to have getters/setters for all internal members, but there are usually at least 2 or 3 in a class that one needs - depending on what the class models.

Not providing a GUI to make this tedious task easy will not prevent anybody from writing getters/setters unecessarily, it'll just make them switch to an IDE that makes it easier to do so.


- Andreas


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/103613/#review9487
-----------------------------------------------------------


On Jan. 2, 2012, 4:35 p.m., Jonas Jacobi wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/103613/
> -----------------------------------------------------------
> 
> (Updated Jan. 2, 2012, 4:35 p.m.)
> 
> 
> Review request for KDevelop.
> 
> 
> Description
> -------
> 
> Generate accessors (getters/setters) for C++.
> 
> This patch adds the possibility to create accessor methods for class member variables via the gui.
> The dialog offers the following features:
> - shows all members of a selected class in a tree view (with getters/setters as children), if it was opened on a class member that one is pre-selected
> - only shows setters if applicable (non-const member)
> - accessor method definitions can be created inline or separate (in the fitting source file, if applicable)
> - configurable automatic creation of method names with manual override for each accessor method
> - access policy (visibility) setting global and invidualy for each accessor method
> - configurable default setter parameter name with manual override for each setter (void setFoo(int myParamterName))
> - selectable getter return type (e.g. Type, Type&, const Type& for a member of type Type)
> - create setters as slots for QObject subclasses
> 
> The code isn't polished and the patch contains whitespace issues in sourcemanipulation.cpp, but it's in a usable state and i would like to get some feedback on the dialog, especially on usability improvements.
> 
> Regards,
> Jonas
> 
> 
> Diffs
> -----
> 
>   languages/cpp/CMakeLists.txt a1fb97c 
>   languages/cpp/codegen/generateaccessorsdialog.h PRE-CREATION 
>   languages/cpp/codegen/generateaccessorsdialog.cpp PRE-CREATION 
>   languages/cpp/codegen/generateaccessorsmodel.h PRE-CREATION 
>   languages/cpp/codegen/generateaccessorsmodel.cpp PRE-CREATION 
>   languages/cpp/codegen/simplerefactoring.h b2187c3 
>   languages/cpp/codegen/simplerefactoring.cpp fd62ccf 
>   languages/cpp/codegen/ui/cppgenerateaccesors.ui PRE-CREATION 
>   languages/cpp/cppduchain/missingdeclarationassistant.cpp bafc159 
>   languages/cpp/cppduchain/sourcemanipulation.h 6f8a79b 
>   languages/cpp/cppduchain/sourcemanipulation.cpp 5cb6a67 
>   languages/cpp/tests/CMakeLists.txt 40d07b0 
>   pics/mini/CMakeLists.txt c3316e7 
>   pics/mini/private_slot.png PRE-CREATION 
>   pics/mini/protected_slot.png PRE-CREATION 
>   pics/mini/public_slot.png PRE-CREATION 
> 
> Diff: http://git.reviewboard.kde.org/r/103613/diff/diff
> 
> 
> Testing
> -------
> 
> 
> Screenshots
> -----------
> 
> 
>   http://git.reviewboard.kde.org/r/103613/s/392/
> 
>   http://git.reviewboard.kde.org/r/103613/s/393/
> 
> 
> Thanks,
> 
> Jonas Jacobi
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20120103/760ab5bf/attachment.html>


More information about the KDevelop-devel mailing list