We'd like to remind Forumites to please avoid political debate on the Forum... Read More »
We're aware that some users are experiencing technical issues which the team are working to resolve. See the Community Noticeboard for more info. Thank you for your patience.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
Can you explain this Excel formula?
Options
Comments
-
DVardysShadow wrote: »But a lack of understanding on the part of the Author makes it inherently ambiguous. OK, it can be said to have an unambiguous interpretation. But if you doubt the Author's understanding of precedence, you must doubt that the code matches the Author's intent.
Don't forget that code is required to communicate in 2 directions - to a compiler or run-time environment and to a human reading it. Regardless of the precedence rules implemented by the compiler, strong account should e taken of the human aspect - otherwise we would still all be writing assembler.
You cant say, my programmers are idiots therefore their code must be idiotic.
Again I doupt somone knows how to use brackets so the meaning of
x-(100*y) is unclear.
To avoid confusion they must use
a = 100 * y
b = x -a
I can go even further and doupt they know how operators actually work in their given language (somthing most really wont know) and ban their use as well.DVardysShadow wrote: »And I think I would take more intermediate results using precedence rather than brackets.
Just because YOU need clarification, doesn't mean the intermediate steps are needed, by defination you can write any single experssion and rely on precedence and it would be the same as the brackets version.0 -
tomstickland wrote: »/8600 is bad practice though - it's a "magic number". Better practice to have "24 * 60"
Why do at runtime what can be done at coding time?
I agree it is a magic number, but you deal with that by defining a variable
SECONDS_IN_DAY = 86400
Additionally note that 24 and 60 are magic numbers.Hi, we’ve had to remove your signature. If you’re not sure why please read the forum rules or email the forum team if you’re still unsure - MSE ForumTeam0 -
tomstickland wrote: »I've worked in mathematical software for years and it's absolutely assumed that people understand mathematical precedance.
x-100*y is totally clear and there is nothing ambigious about it.
Mathematicians understand precedence. Straight BODMAS precedence is fairly OK - but there is a large heirarchy of other operators. What is the precedence between % and / for example? Yes, you can look it up, but there are too many operators.
And the visual effect of precedence gets worse when you use meaningful variable names.Hi, we’ve had to remove your signature. If you’re not sure why please read the forum rules or email the forum team if you’re still unsure - MSE ForumTeam0 -
DVardysShadow wrote: »8600 -> 86400.
Why do at runtime what can be done at coding time?Stompa0 -
If it's a compiled language then the compiler will almost certainly (by default) perform the 24*60 calculation at compile time rather than runtime anyway.
However the important point is to make scrutinisable the Magic Numbers which Tom mentionedHi, we’ve had to remove your signature. If you’re not sure why please read the forum rules or email the forum team if you’re still unsure - MSE ForumTeam0 -
If it said "8654492" and then had a comment like "this is the number of seconds in a day" then that'd be fine.
Re mathematics versus programming language. A properly designed compiler will have precedence rules built in. If it's some flaky crap then I could see the benefit of extra brackets.Happy chappy0 -
tomstickland wrote: »If it said "8654492" and then had a comment like "this is the number of seconds in a day" then that'd be fine.
Re mathematics versus programming language. A properly designed compiler will have precedence rules built in. If it's some flaky crap then I could see the benefit of extra brackets.Hi, we’ve had to remove your signature. If you’re not sure why please read the forum rules or email the forum team if you’re still unsure - MSE ForumTeam0 -
DVardysShadow wrote: »But not with an interpreted language.DVardysShadow wrote: »However the important point is to make scrutinisable the Magic Numbers which Tom mentionedStompa0
-
...
True. My reason for making it non-magic in this instance was that I thought that formulae in Excel were interpreted rather than compiled. I could well be wrong though, does anybody know for sure?
I don't dabble with excel, but if I were to do an industrial strength spreadsheet, I think I would put Magic Numbers on a hidden page of their own, with descriptions. And I would be looking for a Macro facility or possibly even some built in predefined values - I would be very surprised if you could not predefine some constants.Hi, we’ve had to remove your signature. If you’re not sure why please read the forum rules or email the forum team if you’re still unsure - MSE ForumTeam0 -
tomstickland wrote: »I've worked in mathematical software for years and it's absolutely assumed that people understand mathematical precedance.
x-100*y is totally clear and there is nothing ambigious about it.
Agree 100%. I, too, have worked with developing and using analytical / mathematical software for a good many years (trading and risk management in the banking sector) and would have absolutely no tolerance for a programmer who did not have a full grasp of mathematical operator precedence. There is just no excuse.
In fact, I am astounded at some of what I have read in this thread (eg. the insistence upon parenthesis at academic level).0
This discussion has been closed.
Confirm your email address to Create Threads and Reply

Categories
- All Categories
- 351K Banking & Borrowing
- 253.1K Reduce Debt & Boost Income
- 453.6K Spending & Discounts
- 244K Work, Benefits & Business
- 599K Mortgages, Homes & Bills
- 176.9K Life & Family
- 257.4K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.1K Discuss & Feedback
- 37.6K Read-Only Boards