You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Will Glass-Husain <wg...@forio.com> on 2004/01/06 07:26:57 UTC

integer division... some data

Hi,

Tim suggested the following:

> Maybe Will could parse a whole bunch of his users *.vm files to get
> stats on "/" usage and use cases? Might help to see if #1 would truly
> break anything or maybe not.

Well, I did a grep through about 50 Velocity based apps, and to my surprise
I have three findings:
 (a) division is a useful technique for calculating column widths (this was
the only use)
 (b) this type of division requires integer division
 (c) only a couple of actual users used division, but one superuser did it
in 10 apps.  So it's obviously a useful technique if you are familiar with
it.

Clearly this is not an authoritative study.  Other apps might have different
use patterns, and users really haven't had a chance to try out a true
floating point division feature.  But I am now much more worried about the
compatibility issue.

USE CASE #1
A number of our apps involve tables with a dynamic number of columns.
(Specifically, tables of numerical data).  To make the columns line up
properly, it's best to calculate the column width by dividing the number of
columns into the table width.

USE CASE #2
A more elaborate example is creating a tabbed layout.  The actual tabs are
specified in an #parse statement  for modularity.  When the page is
displayed, the tabs are evenly allocated along the top of a table.

USE CASE #3
A lot of our applications involve graphs of variables.  Sometimes the
legends of the graphs are displayed in an HTML table.  Again widths are
calculated using division.

In all cases the division is used to produce pixels which must be an
integer.  If Velocity reported a decimal, I believe this would be invalid
HTML.  I'm going to test this later.

It occurs to me there's another possible problem, which occurs if division
is used to generate a number used in a range with a foreach statement.
(e.g. $foreach ($a in [1..$mustbeinteger] )   ).  This might be the case if
you wanted to repeat text every two columns.  But I didn't see an example of
this.

For specifics, it turns out that one of my colleagues wrote a "how-to" on
the tabbed layout technique and published it here:  (The forum does a poor
job of showing formatted code but should demonstrate the point.)

http://broadcast.forio.com/discuss/forum/broadcast/messages.htm?topic_id=1506

You can see these tabs in action in this app (you'll have to click through a
bunch of screens until you get the the end result, a tabbed interface
showing some graphs).
http://broadcast.forio.com/pro/aftermarket

WILL


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 6, 2004, at 1:48 AM, Dave Newton wrote:

> On Tue, 2004-01-06 at 01:26, Will Glass-Husain wrote:
>>  (a) division is a useful technique for calculating column widths 
>> (this was
>> the only use)
>>  (b) this type of division requires integer division
>
> Well, maybe you need to end up with an integer, but you have to round
> up, not down, to make sure there's enough space-can't just truncate.
>
> I've also used division for kludgy pagination stuff, also rounding up.
>
> My $0 worth. Damn; integers.

$dollars$dot$cents

Remember, use the data from the model :)

geir

>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Dave Newton <da...@solaraccess.com>.
On Tue, 2004-01-06 at 03:19, Nathan Bubna wrote:
> agreed.  i use division for calculating all sorts of HTML dimensions (the apps
> i create are heavily dependent on numerous varying charts and graphs).  i
> typically prefer integer *results* but do not want integer *division*
> happening along the way.  the distinction is very significant to this issue.
> can you be more specific about which of these your users are doing?

Yep; like you said, integer results, not division, rounded up.

(I also agree that 1 pixel is rarely an issue, but it can be, especially
if multiple tables don't line up.)

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Will Glass-Husain <wg...@forio.com>.
The users want integer results, so as not to violate the HTML spec
(inserting a double into an HTML width tag).  Ideally, this would also be
exact same calculation in the next release as it was in the last release,
hence integer division.  Although practically no one will likely notice if a
column is off by one pixel.   But if a browser barfs on the invalid width
tag (IE 6 didn't, but some other version might), then the problems could be
very visible.

I think it would make sense, if we designed everything from scratch, to have
common-sense floating point division.  (with a floor/ceil math tool for
integer calcs).  But based on this (admittedly small sample) of research,
I'm now worried about backwards compatibility for users with existing
templates.

There's no perfect answer.

WILL


----- Original Message ----- 
From: "Nathan Bubna" <na...@esha.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Tuesday, January 06, 2004 12:19 AM
Subject: Re: integer division... some data


> Dave Newton said:
> > On Tue, 2004-01-06 at 01:26, Will Glass-Husain wrote:
> > >  (a) division is a useful technique for calculating column widths
(this
> was
> > > the only use)
> > >  (b) this type of division requires integer division
> >
> > Well, maybe you need to end up with an integer, but you have to round
> > up, not down, to make sure there's enough space-can't just truncate.
> ...
>
> agreed.  i use division for calculating all sorts of HTML dimensions (the
apps
> i create are heavily dependent on numerous varying charts and graphs).  i
> typically prefer integer *results* but do not want integer *division*
> happening along the way.  the distinction is very significant to this
issue.
> can you be more specific about which of these your users are doing?
>
> whether we switch to real division or keep integer division, i will still
be
> doing floating point calcs and using $math.roundToInt($ans) and
> $ans.intValue() on the results when the situation demands.  the question
for
> me here is whether i will have to continue using the MathTool to get real
> division or if i will be able to trust that #set( $foo = $num / 2 ) will
> behave consistently.
>
> Nathan Bubna
> nathan@esha.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Serge Knystautas <se...@lokitech.com>.
Nathan Bubna wrote:
> agreed.  i use division for calculating all sorts of HTML dimensions (the apps
> i create are heavily dependent on numerous varying charts and graphs).  i
> typically prefer integer *results* but do not want integer *division*
> happening along the way.  the distinction is very significant to this issue.

As an example of this, I was just checking through some templates, and I 
had to work around the lack of FP division this way, even if I do want 
integer result:

   #set ($imagewidth = 400 * $answer.percent / 100)

Will Glass-Husain wrote:
 > There's no perfect answer.

Yeah, I agree.

In terms of backwards compability though, I'm not as worried with this 
sample set.  The W3C says only integer pixel widths, but I'm not sure 
how a browser could screw this up.  Worst case would be it ignores the 
pixel width.  But most browsers handle missing </tr> tags, and generally 
they seem very lenient.  Anyone got a testing environment (or a good 
book) that can get us more info on how browsers might handle FP pixel sizes?

-- 
Serge Knystautas
President
Lokitech >>> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Nathan Bubna <na...@esha.com>.
Dave Newton said:
> On Tue, 2004-01-06 at 01:26, Will Glass-Husain wrote:
> >  (a) division is a useful technique for calculating column widths (this
was
> > the only use)
> >  (b) this type of division requires integer division
>
> Well, maybe you need to end up with an integer, but you have to round
> up, not down, to make sure there's enough space-can't just truncate.
...

agreed.  i use division for calculating all sorts of HTML dimensions (the apps
i create are heavily dependent on numerous varying charts and graphs).  i
typically prefer integer *results* but do not want integer *division*
happening along the way.  the distinction is very significant to this issue.
can you be more specific about which of these your users are doing?

whether we switch to real division or keep integer division, i will still be
doing floating point calcs and using $math.roundToInt($ans) and
$ans.intValue() on the results when the situation demands.  the question for
me here is whether i will have to continue using the MathTool to get real
division or if i will be able to trust that #set( $foo = $num / 2 ) will
behave consistently.

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Dave Newton <da...@solaraccess.com>.
On Tue, 2004-01-06 at 01:26, Will Glass-Husain wrote:
>  (a) division is a useful technique for calculating column widths (this was
> the only use)
>  (b) this type of division requires integer division

Well, maybe you need to end up with an integer, but you have to round
up, not down, to make sure there's enough space-can't just truncate. 

I've also used division for kludgy pagination stuff, also rounding up.

My $0 worth. Damn; integers.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Daniel Dekany <dd...@freemail.hu>.
Tuesday, January 6, 2004, 7:26:57 AM, Will Glass-Husain wrote:

> Hi,
>
> Tim suggested the following:
>
>> Maybe Will could parse a whole bunch of his users *.vm files to get
>> stats on "/" usage and use cases? Might help to see if #1 would truly
>> break anything or maybe not.
>
> Well, I did a grep through about 50 Velocity based apps, and to my surprise
> I have three findings:
>  (a) division is a useful technique for calculating column widths (this was
> the only use)
>  (b) this type of division requires integer division
>  (c) only a couple of actual users used division, but one superuser did it
> in 10 apps.  So it's obviously a useful technique if you are familiar with
> it.
[snip]

Integer division is often needed when you render views, but note that:

a) A \ B, for non-programmer means: A divided by B. So it should mean
that in a template language.
   
b) I think that most non-programmers doesn't know the operation "integer
division". They know division, and integer part. These are two ops.
Just, usually you need rounding or integer part after division, so as a
practical thing, a template engine may introduces this operator (I'm not
sure that's a good idea or not...). But that op shouldn't be /. idiv or
something... Well, Velocity 2.0 topic...

Also, note that the W3C validator accepts widths as 10.5 (pixels) or
10.5%, however in the case of size measured in pixels, the specification
says "an *integer* that represents the number of pixels" (emphasis by
me).

-- 
Best regards,
 Daniel Dekany



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 6, 2004, at 1:37 AM, Will Glass-Husain wrote:

> One more note on this.
>
> It turns out that IE 6.0 and Mozilla 0.6 both display decimal column  
> widths
> correctly, at least according to a quick test on my machine.  (Example:
> width="100.5")
>

I think that's because browsers are fundamentally broken wrt spec  
enforcement, resulting in billions of pages of crap, spec-wise, because  
people could be sloppy.

> But I'm still worried this might break on some combination of OS and
> Browser.  We've been bitten by these type of issues before.  Anyone  
> else
> ever play with this?

There's something else to remember and that people use Velocity for  
more than HTML.  Because IE won't wet the bed when something that  
should be an integer is a float doesn't meant that Oracle's SQL parser  
won't...

geir

>
> Best,
> WILL
>
>
>
> ----- Original Message -----
> From: "Will Glass-Husain" <wg...@forio.com>
> To: <ve...@jakarta.apache.org>
> Sent: Monday, January 05, 2004 10:26 PM
> Subject: integer division... some data
>
>
>> Hi,
>>
>> Tim suggested the following:
>>
>>> Maybe Will could parse a whole bunch of his users *.vm files to get
>>> stats on "/" usage and use cases? Might help to see if #1 would truly
>>> break anything or maybe not.
>>
>> Well, I did a grep through about 50 Velocity based apps, and to my
> surprise
>> I have three findings:
>>  (a) division is a useful technique for calculating column widths  
>> (this
> was
>> the only use)
>>  (b) this type of division requires integer division
>>  (c) only a couple of actual users used division, but one superuser  
>> did it
>> in 10 apps.  So it's obviously a useful technique if you are familiar  
>> with
>> it.
>>
>> Clearly this is not an authoritative study.  Other apps might have
> different
>> use patterns, and users really haven't had a chance to try out a true
>> floating point division feature.  But I am now much more worried  
>> about the
>> compatibility issue.
>>
>> USE CASE #1
>> A number of our apps involve tables with a dynamic number of columns.
>> (Specifically, tables of numerical data).  To make the columns line up
>> properly, it's best to calculate the column width by dividing the  
>> number
> of
>> columns into the table width.
>>
>> USE CASE #2
>> A more elaborate example is creating a tabbed layout.  The actual  
>> tabs are
>> specified in an #parse statement  for modularity.  When the page is
>> displayed, the tabs are evenly allocated along the top of a table.
>>
>> USE CASE #3
>> A lot of our applications involve graphs of variables.  Sometimes the
>> legends of the graphs are displayed in an HTML table.  Again widths  
>> are
>> calculated using division.
>>
>> In all cases the division is used to produce pixels which must be an
>> integer.  If Velocity reported a decimal, I believe this would be  
>> invalid
>> HTML.  I'm going to test this later.
>>
>> It occurs to me there's another possible problem, which occurs if  
>> division
>> is used to generate a number used in a range with a foreach statement.
>> (e.g. $foreach ($a in [1..$mustbeinteger] )   ).  This might be the  
>> case
> if
>> you wanted to repeat text every two columns.  But I didn't see an  
>> example
> of
>> this.
>>
>> For specifics, it turns out that one of my colleagues wrote a  
>> "how-to" on
>> the tabbed layout technique and published it here:  (The forum does a  
>> poor
>> job of showing formatted code but should demonstrate the point.)
>>
>>
> http://broadcast.forio.com/discuss/forum/broadcast/messages.htm? 
> topic_id=1506
>>
>> You can see these tabs in action in this app (you'll have to click  
>> through
> a
>> bunch of screens until you get the the end result, a tabbed interface
>> showing some graphs).
>> http://broadcast.forio.com/pro/aftermarket
>>
>> WILL
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Will Glass-Husain <wg...@forio.com>.
One more note on this.

It turns out that IE 6.0 and Mozilla 0.6 both display decimal column widths
correctly, at least according to a quick test on my machine.  (Example:
width="100.5")

But I'm still worried this might break on some combination of OS and
Browser.  We've been bitten by these type of issues before.  Anyone else
ever play with this?

Best,
WILL



----- Original Message ----- 
From: "Will Glass-Husain" <wg...@forio.com>
To: <ve...@jakarta.apache.org>
Sent: Monday, January 05, 2004 10:26 PM
Subject: integer division... some data


> Hi,
>
> Tim suggested the following:
>
> > Maybe Will could parse a whole bunch of his users *.vm files to get
> > stats on "/" usage and use cases? Might help to see if #1 would truly
> > break anything or maybe not.
>
> Well, I did a grep through about 50 Velocity based apps, and to my
surprise
> I have three findings:
>  (a) division is a useful technique for calculating column widths (this
was
> the only use)
>  (b) this type of division requires integer division
>  (c) only a couple of actual users used division, but one superuser did it
> in 10 apps.  So it's obviously a useful technique if you are familiar with
> it.
>
> Clearly this is not an authoritative study.  Other apps might have
different
> use patterns, and users really haven't had a chance to try out a true
> floating point division feature.  But I am now much more worried about the
> compatibility issue.
>
> USE CASE #1
> A number of our apps involve tables with a dynamic number of columns.
> (Specifically, tables of numerical data).  To make the columns line up
> properly, it's best to calculate the column width by dividing the number
of
> columns into the table width.
>
> USE CASE #2
> A more elaborate example is creating a tabbed layout.  The actual tabs are
> specified in an #parse statement  for modularity.  When the page is
> displayed, the tabs are evenly allocated along the top of a table.
>
> USE CASE #3
> A lot of our applications involve graphs of variables.  Sometimes the
> legends of the graphs are displayed in an HTML table.  Again widths are
> calculated using division.
>
> In all cases the division is used to produce pixels which must be an
> integer.  If Velocity reported a decimal, I believe this would be invalid
> HTML.  I'm going to test this later.
>
> It occurs to me there's another possible problem, which occurs if division
> is used to generate a number used in a range with a foreach statement.
> (e.g. $foreach ($a in [1..$mustbeinteger] )   ).  This might be the case
if
> you wanted to repeat text every two columns.  But I didn't see an example
of
> this.
>
> For specifics, it turns out that one of my colleagues wrote a "how-to" on
> the tabbed layout technique and published it here:  (The forum does a poor
> job of showing formatted code but should demonstrate the point.)
>
>
http://broadcast.forio.com/discuss/forum/broadcast/messages.htm?topic_id=1506
>
> You can see these tabs in action in this app (you'll have to click through
a
> bunch of screens until you get the the end result, a tabbed interface
> showing some graphs).
> http://broadcast.forio.com/pro/aftermarket
>
> WILL
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: integer division... some data

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 6, 2004, at 1:26 AM, Will Glass-Husain wrote:

> Hi,
>
> Tim suggested the following:
>
>> Maybe Will could parse a whole bunch of his users *.vm files to get
>> stats on "/" usage and use cases? Might help to see if #1 would truly
>> break anything or maybe not.
>
> Well, I did a grep through about 50 Velocity based apps, and to my 
> surprise
> I have three findings:
>  (a) division is a useful technique for calculating column widths 
> (this was
> the only use)
>  (b) this type of division requires integer division
>  (c) only a couple of actual users used division, but one superuser 
> did it
> in 10 apps.  So it's obviously a useful technique if you are familiar 
> with
> it.
>
> Clearly this is not an authoritative study.  Other apps might have 
> different
> use patterns, and users really haven't had a chance to try out a true
> floating point division feature.  But I am now much more worried about 
> the
> compatibility issue.

Thanks for doing this.

geir

-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org