Re: Missing in misc.e
- Posted by Juergen Luethje <j.lue at ?mx.de> Jul 19, 2007
- 704 views
CChris wrote: > Juergen Luethje wrote: >> >> Thanks for the comprehensive reply. >> >> CChris wrote: <snip> >>> 2c/ get_min(sequence s) return the minimum element in s >>> 2d/ get_max(sequence s) return the maximum element in s >> >> IMHO the names just should ne min() and max(). >> > > Strange, I have _alwats_ seen min() and max() used for the two functions in > 3/. Perhaps it's a french thing, but I have my doubts. Further, get_ and find_ > aren't too difficult to figure out, are they? a) I did not say find_ should be changed. I only wrote about the prefix get_ in this context. b) Starting routine names with get_ is tempting sometimes, but that can easily end with too many names which start with get_. c) It's important that users easily can remember what a function does, when they think of its name. When there are functions max() and get_max() it is hard to rememner which of those functions takes a sequence as parameter, and which one takes 2 objects. With functions max() and max2(), this is much easier, as I alredy wrote. >>> These 4 routines rely on a single find_bound() function using different >>> values >>> for the find_bound_mode control integer. This avoids repeating code and the >>> number of extra tests is minimal. >>> >>> Internally, find_bound() starts with the first element of s (storing it as >>> candidate >>> value and 1 as candidate index), then examines in turn each other element in >>> increasing index order. Whenever one is found which is less than or greater >>> than (depending on the current find_bound_mode) than the candidate value, >>> its >>> value and position are stored as candidate result. When the sequence is >>> exhausted, >>> either the recorded index or value is returned, depending again on >>> find_bound_mode. >>> >>> 3a/ min(object x,object y) returns the lesser of x and y >>> 3b/ max(object x,object y) returns the greater of x and y. >> >> I think these two functions are not necessary, so we can use the names >> for the really important finctions above. >> If they actually are going to be implemented, then their names IMHO >> should be min2() and max2() (because they compare 2 values). This is >> easier to remember. >> > > Why aren't they? I expect them to be used more, rather... Not sure everyone > will inline them, though it is obviously an option. They are not necessary, because it's so easy to write
minVal = y if x < y then minVal = x end if
And as I already wrote: | If they actually are going to be implemented, then their names IMHO | should be min2() and max2() (because they compare 2 values). This is | easier to remember. <snip> >> To avoid naming conflicts (especially in programs that do not use these >> functions anyway), the functions shouldn't be added to misc.e, but should >> be in a new include file, as Pete has suggested. >> E.g. min() and max() do not only apply to numbers, so e.g. minmax.e might >> be a proper name. However, when the main focus is on mathematics, and whith >> functions such as abs() ans sign(), then the proper name probably would >> be 'math.e'. I'll actually suggest that name. Sooner or later it's good >> to have a 'math.e' include file anyway, because there will come more math >> stuff. >> > > Personally, I find it a nag to need including a file because you just need > upper() > or where(). I forget it all the time. This is why splitting include files > further > doesn't look to me as a very good thing Nobody want's to split existing include files. The decisive term in this context is "modularization". Putting this stuff into "misc.e" might _unnecessarily_ cause naming conflicts, which can easily be avoided by putting it in a separate file (as already has been mentioned). Also, people who don't want to remember and to write so many include file names, can easily create a file like this: -----------[ allinc.e ]----------- include database.e include dll.e include file.e include get.e include graphics.e include image.e include machine.e include mouse.e include msgbox.e include safe.e include sort.e include wildcard.e include misc.e include math.e ---------------------------------- Then in their programs people just can write: include allinc.e and they are done. Regards, Juergen