Re: back-end vs. front-end calculation



The alMIGHTY N wrote on 02 apr 2007 in comp.lang.javascript:

Hi all,

Let's say I have a simple math formula:

sum (x * y / 1000) / (sum z / 1000)

sum (x * y / 1000) / sum( z / 1000) ???


sum? That is not javascript! Is that a function?


I have to do this across 50 items, each with an x, y and z value, when
the page first loads AND when a user modifies any of the x, y and z
values.

Needless to say, I need to have a Javascript function that handles
this formula to deal with the modifications.

However, I have a choice on page load to either have the database in
which this data is initially stored perform this calculation or to
have the same Javascript function that will handle the onchange event
handle the initial calculation as well.

a) Would it be noticeably faster to do it on the database side?

That depends on how often you want to fetch the data from the database
and where they are stored then.

b) Would that difference be enough to warrant having redundancy on the
calculation?

What is "redundancy on the calculation"?

One of my co-workers feels that it's always better to do calculations
on the back-end period, no exceptions. My other co-worker feels that
it's bad to have the same calculation in two different places,
especially when one place is back end and the other front end, because
that adds to the list of things we need to handle for future
maintenance.

There are 3, not 2 places to handle things, if I understand your Q
enough:

1 in the serverside querystring of the database [what engine?]
2 in serverside jscript or vbscript [talking ASP]
3 javascript on the client/browser

What does your co-workers understand under front and back end?

What's your opinion on which is the better way to do things?

Depends on your preferences, your joy in coding, and if those two do not
suffice, trying out and measuring the 3 or more possible ways.

My personal favorite is to code as I like when I come to it.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
.



Relevant Pages

  • Re: back-end vs. front-end calculation
    ... have the same Javascript function that will handle the onchange event ... handle the initial calculation as well. ... The data is retrieved from the database upon page load. ...
    (comp.lang.javascript)
  • back-end vs. front-end calculation
    ... Let's say I have a simple math formula: ... handle the initial calculation as well. ... Would it be noticeably faster to do it on the database side? ... One of my co-workers feels that it's always better to do calculations ...
    (comp.lang.javascript)
  • RE: Response.redirect inside a Timer Event
    ... I would call a web service/page method from javascript to ask if the ... My timer is on the .aspx page, and I need to wait until a value exist in my ... database, so I use the timer event to search in the database for this value ... "Braulio Diez" wrote: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Graphically edit a page?
    ... I realized after posting that PHP is rather beside the point. ... >| using PHP to save the info in my database. ... The onClick function will point to a javascript function to tell the ... If the user is using a text only browser then the page is unusable - ...
    (comp.lang.php)
  • Re: prototype.js object persistance
    ... Mechanism in the database? ... Ideally an application wide javascript update can be done ... polls the server for new updates the server will send back ...
    (comp.lang.javascript)