Re: Missing in misc.e

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete Lomax wrote:

> Juergen Luethje wrote:
>>
>> They are not necessary, because it's so easy to write
>> 
>> minVal = y
>> if x < y then
>>    minVal = x
>> end if
>> 
> False. I use min and max all the time:
> C:\Program Files\Edita\eacca.e:95  baseline=Min(selY,CursorY)
> C:\Program Files\Edita\eacolor.ew:427  y=Max(MAXnColours-4,18)*20+95
> C:\Program Files\Edita\eacolor.ew:522  y+=Max(0,16-MAXnColours)*20+40
> C:\Program Files\Edita\eaerror.ew:258	  pukkaWidth=Max(dX+30,200)   -- set
> initial
> width
> C:\Program Files\Edita\eamisc.e:53 global function Min(integer a, integer b)
> C:\Program Files\Edita\eamisc.e:58 global function Max(integer a, integer b)
> C:\Program Files\Edita\eaqj.ew:83  setIndex(ROUTINELIST, Min(ind+5,tally))
> C:\Program Files\Edita\easynld.e:573	  bracelevel=Min(ch-'0',7)
> C:\Program Files\Edita\eaundo.ew:269	   mY=Min(selY,CursorY)
> C:\Program Files\Edita\eaundo.ew:270	   mX=Min(selX,CursorX)
> C:\Program Files\Edita\eaundo.ew:286	    CursorX=Min(selX,CursorX)
> C:\Program Files\Edita\edita.exw:964 
> paintRqd=Min(paintRqd,Min(linefrom,lineto))
> C:\Program Files\Edita\edita.exw:966	 
> paintLast=Max(paintLast,Max(linefrom,lineto))
> C:\Program Files\Edita\edita.exw:969  paintRqd=Min(linefrom,lineto)
> C:\Program Files\Edita\edita.exw:970  paintLast=Max(linefrom,lineto)
> C:\Program Files\Edita\edita.exw:2711	  for idx = Min(ixFrom,ixTo) to
> Max(ixFrom,ixTo)
> do
> C:\Program Files\Edita\edita.exw:3355	     CursorY=Min(selY,CursorY)
> C:\Program Files\Edita\edita.exw:3356	     cX=Min(selX,CursorX)
> C:\Program Files\Edita\edita.exw:3374	cY=Min(selY,CursorY)
> C:\Program Files\Edita\edita.exw:3375	cX=Min(selX,CursorX)
> C:\Program Files\Edita\edita.exw:3376	sX=Max(selX,CursorX)
> C:\Program Files\Edita\edita.exw:4699	    CursorY =
> Min(adjustLine(CursorY,+linesPerPage,CursorX),filelen-1)
> C:\Program Files\Edita\edita.exw:5112	   newY =
> Min(adjustLine(TopLine,linesPerPage-1,TopChunk),length(filetext[currfile])-1)
> C:\Program Files\Edita\edita.exw:5244	    CursorY =
> Min(length(filetext[currfile])-1,
> C:\Program Files\Edita\edita.exw:5248	    CursorY =
> Min(adjustLine(TopLine,floor((y-ClipRect[2])/CharHeight),TopChunk),
> C:\Program Files\Edita\edita.exw:5281	    CursorX =
> Min(Column+floor((x-ClipRect[1]-foldMargin)/CharWidth),
> C:\Program Files\Edita\edita.exw:5383	     
> Min(Column+floor((x-ClipRect[1])/CharWidth),
> C:\Program Files\Edita\edita.exw:5385	     
> Min(adjustLine(TopLine,floor((y-ClipRect[2])/CharHeight),TopChunk),
> C:\Program Files\Edita\edita.exw:6914	   CursorY =
> Min(adjustLine(TopLine,screenY,CursorX),length(filetext[currfile])-1)
> C:\Program Files\Edita\edita.exw:6918 --      CursorY =
> Min(adjustLine(CursorY,+linesPerPage,CursorX),filelen-1)
> 
> 
>> 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.
>> 
> For me it is pretty ingrained that min() takes two parameters and returns the
> smaller. Finding the smallest element of an arbitrary length list is a much
> rarer thing,

Not for me.
Also, of course finding the smallest element of a list is the general
principle, and finding the smallest of 2 given values is a special case.
This means:
a) A special function
      x = mini2(a,b)
   is not necessary, because always the general function can be used instead:
      x = min({a,b})  

b) If the special functions that take 2 parameters actually are going to
   be implemented, then their names should be min2() and max2() (because
   they compare 2 objects) -- or something similar. The general function 
   that takess a sequence as parameter should have the general name 'min'.

And, quoting myself:
| 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.

Regards,
   Juergen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu