[fpc-pascal] Underscores in numerical literals - grouping

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Tue Nov 22 12:30:22 CET 2016


On 2016-11-21 23:59, Dmitry Boyarintsev wrote:
> I find it a made up problem, inspired by sales department.

Not at all. I do agree that using constants is a very good idea, instead
of hard-coded "magic numbers", but sometimes you use a value only once
in your code, and a constant is simply overkill.

Here is an example of actual code I have:


  checksum := $B1B0AFBA - (checksum and $ffffffff);


Quickly look at that and tell me how many "f" are in the last hex value.
Did I make a typo by adding to many or to few f's? Can't tell
(monospaced font or not), so you have to carefully count that to be
sure. Making small typos in such values could take hours to debug and find.


Now, lets look at the same code again, but formatted as mentioned in the
Java blog. Quickly, how many f's did I type now in either hex value?
Instantly you can see I made no typos.

  checksum := $B1B0_AFBA - (checksum and $ffff_ffff);

Group formatting of numerals - via a underscore or more intelligent text
rendering by the text editor - would be very very useful to eliminate
those subtle bugs. It's exactly the same as what syntax highlighting
does - making reading and writing source code easier, and with less
mistakes.


Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp



More information about the fpc-pascal mailing list