Strange lines of code discovered in water calculator spreadsheets

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
Unless your compiler is smart enough to do it for you that should be simplified to pH = Round(0.4 * Rnd() + 5.2, 2) in order to speed up execution.

I don't know of any modern compiler that wouldn't optimize said code. The suggested type of optimization is for compilers pre circa ~1960.

Preferably one would expand the code:

Randomize()
max = 5.6
min = 5.2
pH = Round((max - min) * Rnd() + min, 2)

Making it easier to read and modify.
 
Well when do you suppose I did most of my coding?

Don't worry bud, I can tell by the code in your spreadsheet that you're getting better at VBA using advanced features, etc...

You have an interesting implementation of Henderson-Hasselbalch. It may be beneficial to some to expand some of that code making it more clear to others what is happening. The speed of current computers and the ability of modern compilers rarely justified writing cryptic code.

The OP was just a bad tech joke, I guess.
 
Well when do you suppose I did most of my coding?

I still remember spending hours typing code onto (or rather into) keypunch cards (each keystroke literally punched holes into the card), then running a huge bundle (stack) of the hole riddled cards through a compiler. Then finally getting the answer kicked out onto a piece of paper (or dreaded error messages). I didn't even know what a monitor was back then. Fortran was the language. Such was the state of the art of computing when I was in college. Some sort of IBM mainframe computer was being used as I recall. I never actually saw it.

I can't quite recall, but it may have been that every line of code required a new keypunch card. I don't think you could get multiple lines of code onto a single card. And it assuredly was the case that each time you made a typo error you had to trash the card and start over.
 
Last edited:
Don't worry bud, I can tell by the code in your spreadsheet that you're getting better at VBA using advanced features, etc...
Yes, I guess so but I'm still groping.

You have an interesting implementation of Henderson-Hasselbalch. It may be beneficial to some to expand some of that code making it more clear to others what is happening.
H-H is the key to the approach for sure but my current strategy is to not explain it at all. The plan is to try to convince people that if they mix a volume of water containing m1 mmoles of bicarbonate, w kg of some malt to it and mLac mmoles of lactic acid all they have to do is find pH that reduces

m1*(Qacid(pH, 6.38,10.38) - Qacid(pHs,6.38,10.38) ) + w*dQ1kg(pH, pHDi, a1,a2,a3) + Qacid(pH,3.86 )

to 0. pHs is the brewing water pH. pHDI is the DI mash pH of the malt and a1, a2, a3 its buffering parameters. 6.38 and 10.38 are the pKs of carbonic acid and 3.86 that of lactic. Qacid is the Henderson - Hasselbalch. It returns the charge on one mmol of carbo at pH. dQm1kg reproduces he titration curve of a malt with the passes parameters (derived from the actual titration curve of the malt). I also need to give them functions that determine how many mmol of lactic acid are in 1 mL of specified strength etc. The plan is, thus, to entirely keep chemistry out if it as as soon as anything like what H-H implies in mentioned people run in terror. Eventually - yes, anbsolutely but not at firsl, and it will go in an Appendi at the back of the manual.

The speed of current computers and the ability of modern compilers rarely justified writing cryptic code.
Sure but habit dies hard. I still code polynomials as (((d*x + c)*x + b)*x + a.


The OP was just a bad tech joke, I guess.
As was my reply.
 
The speed of current computers and the ability of modern compilers rarely justified writing cryptic code.
I thought that was probably true but that was before this Voltmeter spreadsheet got to where it is today. I'm back to looking desperately for ways to save a cycle or two like passing by value, writing polynomials as (((d*x + c)*x + b)*x + a, looking for indications I can get out of a loop faster etc.
 
I thought that was probably true but that was before this Voltmeter spreadsheet got to where it is today. I'm back to looking desperately for ways to save a cycle or two like passing by value, writing polynomials as (((d*x + c)*x + b)*x + a, looking for indications I can get out of a loop faster etc.

I seriously hope you're being facetious. Real time interpretation of script languages has never been better.

Back in the day we referenced "The Dragon Book" (1st edition). I haven't seen the second edition. Read up on your Graph Theory.
 
I seriously hope you're being facetious.
Nope. On this machine (Mac Mini) it takes 4.5719 seconds to evaluate 1 + 2*arg + 3*arg^2 + 4*arg^3 + 5*arg^4 + 6*arg^5 + 7*arg^6 + 8*arg^7 ten million times but only 1.99501 seconds to evaluate ((((((8*arg + 7)*arg +6)*arg + 5)*arg + 4)*arg + 3)*arg + 2)*arg + 1 (which gives the same result) ten million times. Thus the first coding takes 2.29 times longer!

Plus no compiler is smart enough to detect that the derivative in a root-bisection loop has calmed down to the point where it should generates code to switch over to Newton-Raphson. The programmer has to do that.

Read up on your Graph Theory.
I think you had better read up on your Debye-Hückle.
 
Last edited:
Back
Top