Author |
Topic |
|
Adequat
Tomato Guru
182 Posts |
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Feb 26 2018 : 07:25:10 AM
|
Interesting, are you using a lot of free functions in your code? I was not aware this was a trend, but there is always something new to learn.
Are these free functions placed into a namespace? Or are they in the global namespace?
Also, what happens with different numbers or types of parameters? The example in the GIF is interesting, and it shows the behaviour very clearly, but if I understand correctly, it also assumes / requires that all of the free functions take a single (or at least the first) parameter of the filesystem type. I haven't watched the video yet, but I do wonder how widely this idea can be applied. At least in my experience nearly every "class" (group of related functions) I have also have some data that goes with them, making a traditional class implementation make sense. |
zen is the art of being at one with the two'ness |
|
|
accord
Whole Tomato Software
United Kingdom
3287 Posts |
Posted - Feb 26 2018 : 11:55:38 AM
|
We're considering to implement this at some point:
case=101652 |
|
|
Adequat
Tomato Guru
182 Posts |
Posted - Feb 27 2018 : 01:20:34 AM
|
quote: Are these free functions placed into a namespace? Or are they in the global namespace?
Both cases are possible.
quote: what happens with different numbers or types of parameters?
Does not matter, because only the first parameter is important.
The pattern is this:
someFunction(myobject, arg2, arg3, ...)
if you type:
myobject.
then the list of all functions that use myobject as first parameter, are proposed.
quote: in my experience nearly every "class" (group of related functions) I have also have some data that goes with them, making a traditional class implementation make sense.
This makes sense at first sight... but this complicates things when the class grows and grows. I personally maintain a 2 million lines application with big classes, and have started to refactor some parts with free functions.
If you have time, look at the video, it is enlightening and a good summary on the topic.
This is a not a new topic actually. It all started in 2000, from an article of the respected C++ guy Scott Meyers. http://www.drdobbs.com/cpp/how-non-member-functions-improve-encapsu/184401197?pgno=3
I believe it gains momentum these days because programs become more complex and many programmers start to realize (some of) the advantages of the functional programming approach.
|
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
Posted - Feb 27 2018 : 07:01:17 AM
|
The feature request already handles the extra parameters, which is good to know. I was wondering how this part was going to work, so I am glad this is covered properly.
Big classes are always going to be a problem, along with big functions. I have come across a few big functions that just make sense as one block, even though it can make it hard to work with them. Beyond this, it is easy to say refactor and break things up sensibly, but its sometimes easier said than done.
I have some of Scott Meyers books, a very good author with a lot of very interesting things to say! Mainly I just wanted to understand the thinking a bit better here, some ideas look good at first, but don't work so well when studied. |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|
|
|