473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

back-end vs. front-end calculation

Hi all,

Let's say I have a simple math formula:

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

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?

b) Would that difference be enough to warrant having 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.

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

Apr 2 '07 #1
5 6203
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)
Apr 2 '07 #2
On Apr 2, 1:07 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
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 was just relating the math formula itself. That's obviously not
code, haha.
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.
The data is retrieved from the database upon page load. After that,
all calculation is done on the page. After any number of
calculations / modifications, the user can choose to save the data to
the database. That doesn't reload the page, however. Basically, the
user would have to refresh the page explicitly to load data from the
database again.
b) Would that difference be enough to warrant having redundancy on the
calculation?

What is "redundancy on the calculation"?
What I meant was to have the same calculation in two different places
- back end in the database *and* front end in the Javascript.
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
Only two places: on the back end, there is a stored procedure in the
database that calculates the formula and then spits out the resulting
number into XML; on the front end, the HTML generated by the XSL
attached to the aforementioned XML contains Javascript that has that
calculation.

Another thing... the XML generated by the back end functions also
contains x, y and z, which is why even on the initial page load, the
Javascript could easily run the calculation instead of doing it on the
back end... the question is whether it should.
What does your co-workers understand under front and back end?
Actually, both of my co-workers are back end developers, dealing in
Java. I'm the sole front-end developer in the project.
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.
Well, we've already coded on both the back end and the front end. My
co-workers are just debating whether to use the back end code at all,
and I'm caught in the middle. :-(

Personally, I think the difference in speed is negligible if it's even
there. The page seems to load up fast no matter what option we go
with.

However, the one who believes entirely in back end coding keeps
insisting that her way is the best because the calculation on the back
end takes in the scale of milliseconds whereas the calculation on the
front end takes on the scale of seconds (or so she claims but maybe
she's just trying to defend her work haha).

Anyway, just looking for opinions, s'all. I don't know enough about
back end programming to be able to say whether it's any faster or
slower than what could be done on Javascript. I imagine it is faster
to some degree, but not to a degree that's noticeable to a user,
especially with such a simple calculation.

Cheers!
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)

Apr 2 '07 #3
In comp.lang.javascript message <11**********************@d57g2000hsg.go
oglegroups.com>, Mon, 2 Apr 2007 09:47:34, The alMIGHTY N
<na******@yahoo.composted:
>Let's say I have a simple math formula:

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

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.
If I understand your calculation adequately, it will take insignificant
time in comparison with the time taken to fetch and load the page. To
verify that, put the calculation in an outer loop which repeats it 10 or
100 or more times, to make the delay measurable.

If your talents had matched your appellation, you would have thought of
that.

Wherever possible, things should be done only once. That includes
writing and maintaining such code - so do it on the client.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Delphi 3? Turnpike 6.05
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.htmlnews:borland.* Guidelines
Apr 2 '07 #4
The alMIGHTY N wrote on 02 apr 2007 in comp.lang.javascript:
However, the one who believes entirely in back end coding keeps
insisting that her way is the best because the calculation on the back
end takes in the scale of milliseconds whereas the calculation on the
front end takes on the scale of seconds (or so she claims but maybe
she's just trying to defend her work haha).

Anyway, just looking for opinions, s'all. I don't know enough about
back end programming to be able to say whether it's any faster or
slower than what could be done on Javascript. I imagine it is faster
to some degree, but not to a degree that's noticeable to a user,
especially with such a simple calculation.
I do not like the wording back-end and front-end, because the meaning is
not clear unless you, as you did, explain it specifically.

You seem to mean serverside or clientside.

Back-end / front-end could also mean database / serverscripting,
methinks.

The good things about severside are, that the user cannot interfere with
the coding and the influence of different browsers and javascript
availability are absent.

The bad thing about severside is that you do not make use of the
"distributed computing power" gain when a multitude of users want to
calculate at the same time.
Personally, I think the difference in speed is negligible if it's even
there.
The speed difference is not something to contemplate, but should and can
easily be measured.

In the end, it both depends on specific demands and possibilities and is
a very personal choice all the same.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 3 '07 #5
On Apr 2, 4:22 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
In comp.lang.javascript message <1175532454.941241.218...@d57g2000hsg.go
oglegroups.com>, Mon, 2 Apr 2007 09:47:34, The alMIGHTY N
<natle...@yahoo.composted:
Let's say I have a simple math formula:
sum (x * y / 1000) / (sum z / 1000)
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.

If I understand your calculation adequately, it will take insignificant
time in comparison with the time taken to fetch and load the page. To
verify that, put the calculation in an outer loop which repeats it 10 or
100 or more times, to make the delay measurable.

If your talents had matched your appellation, you would have thought of
that.
My appellation? Haha. My name is just a name - about as meaningless
except as a common word as that which you misinterpreted it to
represent.
Wherever possible, things should be done only once. That includes
writing and maintaining such code - so do it on the client.

--
(c) John Stockton, Surrey, UK. ?...@merlyn.demon.co.uk Delphi 3? Turnpike 6.05
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.htmlnews:borland.* Guidelines

Apr 3 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ralph Freshour | last post by:
Is it possible to inhibit the browser Back/Fwd buttons via PHP? Thanks...
1
by: Peter D. Dunlap | last post by:
Hello, I realize that this may not be the best place to ask this question, through the application is asp.net. I also realize that questions about disabling the back button are generally met...
4
by: Hypo | last post by:
I added a 'Back' button to my page, and wrote 'OnClick' code something like this: Response.Write("<script>history.go(-" + iDepthIndex.ToString() + ");</script>"); But, it dosnt work! Effect...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
29
by: Tom wilson | last post by:
I can't believe this is such an impossibility... I have an asp.net page. It accepts data through on form fields and includes a submit button. The page loads up and you fill out some stuff. ...
5
by: Tom wilson | last post by:
I'm developing an application that is a benefits enrolment website. The benefits can be of any type in any order as stored in a SQL server. On each page is a Back and Next button. At a certain...
7
by: Sridhar | last post by:
Hi, I have a question regarding the Page_Load method and Back Button of Internet explorer. I have created a webform. In that webform I have several Text Boxes. Also I have two buttons. When I...
4
by: bendlam | last post by:
I have a page that contains search criteria and when you click on the search button it causes a post back that populates a dataview on the same page. One of the gridview columns contains a link...
12
by: jim.richardson | last post by:
Hi all, I'd like a page to be excluded from the back button history, that is, when a user hits their browser's back button, it never backs into this particular page. Can anybody please tell...
22
by: Rickster66 | last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back" I'm sorry for the late response. I've been gathering up information and carefully with as much...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.