commas

  • Follow


Are there any languages where you can actually use commas in the numbers?

So, instead of having to write:

int x = 5000000;

You could write:

int x = 5,000,000;

I think this could improve clarity a lot.

Is there really a good reason no one has done this?
0
Reply bob3904 (245) 6/12/2012 2:09:19 PM

On Tue, 12 Jun 2012 07:09:19 -0700 (PDT), bob <bob@coolfone.comze.com>
wrote:

>Are there any languages where you can actually use commas in the numbers?
>
>So, instead of having to write:
>
>int x = 5000000;
>
>You could write:
>
>int x = 5,000,000;
>
>I think this could improve clarity a lot.
>
>Is there really a good reason no one has done this?


While commas specifically are probably a bad idea, since they're used
as other sorts of separators in most languages, there are languages
that allow that sort of thing.  Ada and Perl, for example, let you
write numeric literals with underscores for separation (so
"5_000_000").

Handy occasionally, but unless you're writing numbers in binary,
constants that large are not all that frequent, so it's usually a
modest issue.
0
Reply robertwessel2 (1353) 6/12/2012 2:16:47 PM


On Tue, 12 Jun 2012 07:09:19 -0700 (PDT), bob <bob@coolfone.comze.com> wrote:

>Are there any languages where you can actually use commas in the numbers?
>
>So, instead of having to write:
>
>int x = 5000000;
>
>You could write:
>
>int x = 5,000,000;
>
>I think this could improve clarity a lot.
>
>Is there really a good reason no one has done this?

Be aware that in some locales the comma is used as the decimal seperator instead of the
thousands seperator.



-- 
Regards, Paul Herber, Sandrila Ltd.
http://www.sandrila.co.uk/          
0
Reply paul2239 (21) 6/12/2012 2:37:30 PM

On 6/12/2012 9:16 AM, Robert Wessel wrote:
> On Tue, 12 Jun 2012 07:09:19 -0700 (PDT), bob<bob@coolfone.comze.com>
> wrote:
>
>> Are there any languages where you can actually use commas in the numbers?
>>
>> So, instead of having to write:
>>
>> int x = 5000000;
>>
>> You could write:
>>
>> int x = 5,000,000;
>>
>> I think this could improve clarity a lot.
>>
>> Is there really a good reason no one has done this?
>
>
> While commas specifically are probably a bad idea, since they're used
> as other sorts of separators in most languages, there are languages
> that allow that sort of thing.  Ada and Perl, for example, let you
> write numeric literals with underscores for separation (so
> "5_000_000").
>
> Handy occasionally, but unless you're writing numbers in binary,
> constants that large are not all that frequent, so it's usually a
> modest issue.

yeah, my scripting language (BGBScript) also does this (uses '_' as a 
spacer for numbers).

0
Reply cr88192355 (1754) 6/12/2012 2:53:09 PM

Paul Herber wrote:

> Be aware that in some locales the comma is used as the decimal seperator
> instead of the thousands seperator.

This is true.  It is also one of the most annoying features that found their 
way to some particularly popular software packages, particularly when 
different interpretations of what a comma is supposed to represent lead to 
silent conversions between formats, which in turn introduce numerical errors 
which are measured in several orders of magnitude.


Rui Maciel
0
Reply rui.maciel (1761) 6/12/2012 3:14:59 PM


"Robert Wessel" <robertwessel2@yahoo.com> wrote in message 
news:gjjet7t3jsftl11sqf1l7kqm13n70oeepq@4ax.com...
> On Tue, 12 Jun 2012 07:09:19 -0700 (PDT), bob <bob@coolfone.comze.com>
> wrote:
>
>>Are there any languages where you can actually use commas in the numbers?
>>
>>So, instead of having to write:
>>
>>int x = 5000000;
>>
>>You could write:
>>
>>int x = 5,000,000;
>>
>>I think this could improve clarity a lot.
>>
>>Is there really a good reason no one has done this?
>
>
> While commas specifically are probably a bad idea, since they're used
> as other sorts of separators in most languages, there are languages
> that allow that sort of thing.  Ada and Perl, for example, let you
> write numeric literals with underscores for separation (so
> "5_000_000").
>
> Handy occasionally, but unless you're writing numbers in binary,
> constants that large are not all that frequent, so it's usually a
> modest issue.

I use 'big' numbers frequently enough (benchmarking loops, testing compilers 
with numbers near the limits, big number libraries etc.) that it's something 
I would use frequently. And the numbers don't need to be that big: 10000 and 
100000 can easily be mixed; 10_000 and 100_000 much less so.

Also sometimes you want digits grouped in a certain way, to reflect use 
(especially hex and binary) or to highlight a pattern.

And if the language has binary, and therefore has a separator, why not use 
it for other bases too.

But since it has virtually zero cost, there's no reason why a language 
shouldn't have this feature.

However I don't use commas (when I have to implement the feature) unless 
it's for user input, and even then they can be troublesome when entering a 
list.

-- 
Bartc 

0
Reply bc (2221) 6/12/2012 3:33:26 PM


"bob" <bob@coolfone.comze.com> wrote in message 
news:f0d3d247-8eac-4ce0-bb61-296a58ea2035@googlegroups.com...
> Are there any languages where you can actually use commas in the numbers?
>
> So, instead of having to write:
>
> int x = 5000000;
>
> You could write:
>
> int x = 5,000,000;
>
> I think this could improve clarity a lot.
>
> Is there really a good reason no one has done this?

Yes, because it interferes with syntaxes when comma is used for other 
purposes, such as separating elements of a list:

int x[] = {100,200,300,400};

Is that 4 elements, or the single number 100200300400?

But if the language doesn't provide some other way of separating digits, 
then sometimes you can provide something yourself:

int y = strtoint("100,200,300,400");

except it would be slower.

-- 
Bartc 

0
Reply bc (2221) 6/12/2012 3:37:34 PM

BartC wrote:

> Yes, because it interferes with syntaxes when comma is used for other
> purposes, such as separating elements of a list:

That, and some programming languages actually have a comma operator that 
also handles and returns integral types.


Rui Maciel
0
Reply rui.maciel (1761) 6/12/2012 4:10:12 PM

On 6/12/12 7:09 AM, bob wrote:
> Are there any languages where you can actually use commas in the numbers?
>
> So, instead of having to write:
>
> int x = 5000000;
>
> You could write:
>
> int x = 5,000,000;
>
> I think this could improve clarity a lot.
>
> Is there really a good reason no one has done this?

I believe Java 7 has that capability, sort of.

Instead of "," you use "_", but the idea is the same, grouping digits

int x = 5_000_000;

equivalent to

int x = 5000000;

Honestly, I think this should be a function of the editor, and not the 
language itself, but I haven't seen an IDE that abstracts the 
programming language that extensively but remains useful.
0
Reply newsgroup.nospam (534) 6/12/2012 4:32:54 PM

Daniel Pitts <newsgroup.nospam@virtualinfinity.net> writes:

> I believe Java 7 has that capability, sort of.
>
> Instead of "," you use "_", but the idea is the same, grouping digits
>
> int x = 5_000_000;
>
> equivalent to
>
> int x = 5000000;
>
> Honestly, I think this should be a function of the editor, and not the
> language itself, but I haven't seen an IDE that abstracts the
> programming language that extensively but remains useful.

Emacs has "glasses" mode, described as:

    Glasses minor mode makes `unreadableIdentifiersLikeThis' readable by
    altering the way they display.  It knows two different ways to do this:
    by displaying underscores between a lower-case letter and the following
    capital letter, and by emboldening the capital letters.  It does not
    alter the buffer text, only the way they display, so you can use it
    even on read-only buffers.  You can use the command `M-x glasses-mode'
    to enable or disable the mode in the current buffer; you can also add
    `glasses-mode' to the mode hook of the programming language major modes
    in which you normally want to use Glasses mode.

I guess that it would be a minor modification to this mode to
make it also display underscores as part of numbers.
0
Reply blp (3953) 6/12/2012 4:54:54 PM

"Daniel Pitts" <newsgroup.nospam@virtualinfinity.net> wrote in message 
news:XaKBr.14619$hJ3.3099@newsfe14.iad...
> On 6/12/12 7:09 AM, bob wrote:
>> Are there any languages where you can actually use commas in the numbers?

> I believe Java 7 has that capability, sort of.
>
> Instead of "," you use "_", but the idea is the same, grouping digits
>
> int x = 5_000_000;
>
> equivalent to
>
> int x = 5000000;
>
> Honestly, I think this should be a function of the editor, and not the 
> language itself, but I haven't seen an IDE that abstracts the programming 
> language that extensively but remains useful.

You could argue that half the syntax in a language could be the 
responsibility of the editor.

For example, the language proper might only have hexadecimal constants, 
leaving it to the editor to display as decimal.

Obviously that would have all sorts of disadvantages (when posting code to a 
group such as this for example).

But why would it be such a big deal for language syntax to help out with 
this sort of stuff?

(And if anyone knows the answer to that, perhaps they can tell me why you 
can't, generally, have embedded spaces when entering a credit-card number 
on-line, so that it matches the way it is shown on the card and is far 
easier to check.)

-- 
Bartc 

0
Reply bc (2221) 6/12/2012 5:05:36 PM

On 6/12/12 10:05 AM, BartC wrote:
> "Daniel Pitts" <newsgroup.nospam@virtualinfinity.net> wrote in message
> news:XaKBr.14619$hJ3.3099@newsfe14.iad...
>> On 6/12/12 7:09 AM, bob wrote:
>>> Are there any languages where you can actually use commas in the
>>> numbers?
>
>> I believe Java 7 has that capability, sort of.
>>
>> Instead of "," you use "_", but the idea is the same, grouping digits
>>
>> int x = 5_000_000;
>>
>> equivalent to
>>
>> int x = 5000000;
>>
>> Honestly, I think this should be a function of the editor, and not the
>> language itself, but I haven't seen an IDE that abstracts the
>> programming language that extensively but remains useful.
>
> You could argue that half the syntax in a language could be the
> responsibility of the editor.
>
> For example, the language proper might only have hexadecimal constants,
> leaving it to the editor to display as decimal.
Kind of, however the decision of the base to use for a number might be 
better left to a human.  A bit-mask makes more sense to represent in 
Hex, Binary, or Octal, where a time-unit makes more sense in Decimal.
>
> Obviously that would have all sorts of disadvantages (when posting code
> to a group such as this for example).
Unless your newsreader was aware of the language, and was able to do the 
rendering appropriate. Although that really is a potential disadvantage 
to "not-entirely-text" files.
>
> But why would it be such a big deal for language syntax to help out with
> this sort of stuff?
Not a big deal, but you can get more out of a smart editor than a 
complex language.  The editor can express things that aren't textual at 
all. For instance, good HTML editors will show colors as swatches next 
to the definition of that color.
>
> (And if anyone knows the answer to that, perhaps they can tell me why
> you can't, generally, have embedded spaces when entering a credit-card
> number on-line, so that it matches the way it is shown on the card and
> is far easier to check.)

It's somewhat off-topic, but indeed the server should be smart enough to 
pre-process the input to remove spaces.  The JavaScript which does 
whatever kind of pre-validation (length of string?) can be made to 
support spaces. The problem is supporting non-JS enabled browsers 
gracefully. You can specify a maximum length, but that is different 
between "spaced" numbers and "unspaced".

My real point was that code editors can go beyond simple textual 
rendering (and some are starting too), and allow coding "style" to be 
customized by the reader, not by the writer.  Code folding is one 
example which is becoming common. I'm imagining a future editor where 
aspects are folded inline, from the join-points, and join-points are 
visible from the advice, etc... I think there could be novel ways of 
visualizing classes, interfaces, and their interactions, *without* 
interfering with the ability to manipulate them. Perhaps an improved way 
to manipulate the system (think refactoring) that is visualized in a 
easily consumable way.

IDE's are headed in this direction, and I'm excited to see it happen. 
The difficulty is balancing text-representable language and the other 
features, especially if the text is ill-formed. Some textual constructs 
are easier (for computers) recognize when they become corrupt than 
others. This could be solved by ignore textual representation, and 
having all the structure of a program be stored in an object model that 
can only be manipulated in "syntactically correct" manors.  Though doing 
that could make creation more difficult, if not done correctly.

Anyway, I've rambled on enough, and perhaps incoherently.  Just a 
fraction of my brain-dump on the subject.

Sincerely,
Daniel.
0
Reply newsgroup.nospam (534) 6/12/2012 6:51:43 PM

"Daniel Pitts" <newsgroup.nospam@virtualinfinity.net> wrote in message 
news:4dMBr.6769$5r4.2739@newsfe18.iad...

> IDE's are headed in this direction, and I'm excited to see it happen. The 
> difficulty is balancing text-representable language and the other 
> features, especially if the text is ill-formed. Some textual constructs 
> are easier (for computers) recognize when they become corrupt than others. 
> This could be solved by ignore textual representation, and having all the 
> structure of a program be stored in an object model that can only be 
> manipulated in "syntactically correct" manors.  Though doing that could 
> make creation more difficult, if not done correctly.

I've thought about stuff like that too (from the point of view of language 
design).

You could almost get rid of ordinary syntax; either it would look something 
like Lisp, or be in some complicated machine-readable format as you suggest. 
In fact modules can also disappear, you're just left with a tree-structure 
of variables, functions and types; just a database really.

But since I'm still using 1980s-style console-based IDEs and text editors, I 
designed not to take that route yet..

-- 
Bartc

 

0
Reply bc (2221) 6/12/2012 7:36:34 PM

On 6/12/12 12:36 PM, BartC wrote:
> "Daniel Pitts" <newsgroup.nospam@virtualinfinity.net> wrote in message
> news:4dMBr.6769$5r4.2739@newsfe18.iad...
>
>> IDE's are headed in this direction, and I'm excited to see it happen.
>> The difficulty is balancing text-representable language and the other
>> features, especially if the text is ill-formed. Some textual
>> constructs are easier (for computers) recognize when they become
>> corrupt than others. This could be solved by ignore textual
>> representation, and having all the structure of a program be stored in
>> an object model that can only be manipulated in "syntactically
>> correct" manors. Though doing that could make creation more difficult,
>> if not done correctly.
>
> I've thought about stuff like that too (from the point of view of
> language design).
>
> You could almost get rid of ordinary syntax; either it would look
> something like Lisp, or be in some complicated machine-readable format
> as you suggest. In fact modules can also disappear, you're just left
> with a tree-structure of variables, functions and types; just a database
> really.
Very much what I've thought about. Syntax disappears from the 
programmers concerns and is replaced with pure conceptualization.
>
> But since I'm still using 1980s-style console-based IDEs and text
> editors, I designed not to take that route yet..
There are a lot of obstacles to such a system, not least of which is the 
wide-spread use and utility of text-editors.
0
Reply newsgroup.nospam (534) 6/12/2012 11:28:49 PM

On 6/12/2012 8:09 AM, bob wrote:
> Are there any languages where you can actually use commas in the numbers?
>
> So, instead of having to write:
>
> int x = 5000000;
>
> You could write:
>
> int x = 5,000,000;
>
> I think this could improve clarity a lot.

I haven't used Fortran in decades, but my recollection is it allowed arbitrary 
spaces to be embedded in source.  If that is still the case, you could write
        x = 5 000 000

-- 
Thad
0
Reply ThadSmith (1279) 6/18/2012 4:38:47 AM

On Sun, 17 Jun 2012 22:38:47 -0600, Thad Smith <ThadSmith@acm.org>
wrote:

>On 6/12/2012 8:09 AM, bob wrote:
>> Are there any languages where you can actually use commas in the numbers?
>>
>> So, instead of having to write:
>>
>> int x = 5000000;
>>
>> You could write:
>>
>> int x = 5,000,000;
>>
>> I think this could improve clarity a lot.
>
>I haven't used Fortran in decades, but my recollection is it allowed arbitrary 
>spaces to be embedded in source.  If that is still the case, you could write
>        x = 5 000 000


Indeed, mistyping:

  DO 100 I = 1, 10

with a period instead of a comma, would result in:

  DO100I = 1.10

Which, of course, doesn't loop as intended, implicitly declares a
variable called DO100I and assigns a value to it, and would typically
not produce any sort of diagnostic.  And when you're debugging a paper
listing, printed on low quality paper with a cheap, almost worn out,
ribbon, that was not easy to spot.
0
Reply robertwessel2 (1353) 6/18/2012 5:02:57 AM

In article <97dtt756jsdcgrjiufo8jlpb9e51djufdv@4ax.com>,
Robert Wessel  <robertwessel2@yahoo.com> wrote:
> On Sun, 17 Jun 2012 22:38:47 -0600, Thad Smith <ThadSmith@acm.org>
> wrote:
> 
> >On 6/12/2012 8:09 AM, bob wrote:
> >> Are there any languages where you can actually use commas in the numbers?
> >>
> >> So, instead of having to write:
> >>
> >> int x = 5000000;
> >>
> >> You could write:
> >>
> >> int x = 5,000,000;
> >>
> >> I think this could improve clarity a lot.
> >
> >I haven't used Fortran in decades, but my recollection is it allowed arbitrary 
> >spaces to be embedded in source.  If that is still the case, you could write
> >        x = 5 000 000

Quite belatedly, for the record maybe ....

That was true of old-style FORTRAN (standards up through FORTRAN 77).
Fortran 90 [*] introduced an alternate source format ("free form", as
opposed to the older "fixed form") with a lot fewer restrictions on
column alignment and so forth, and in this new format spaces *are*
significant.  In the new format the mistake described below wouldn't
be possible -- though neither would the above trick for making
numeric constants more readable.  The compilers I've used support
both formats, with the choice determined by either the filename
extension or a compiler switch.  (Backward compability, you know.)

Fortran these days -- if one can judge by comp.lang.fortran, it
continues to evolve and to have an active and enthusiastic user base,
but it's something of a niche language.

[*] Yeah, they also decided to drop the all-caps spelling.

> 
> Indeed, mistyping:
> 
>   DO 100 I = 1, 10
> 
> with a period instead of a comma, would result in:
> 
>   DO100I = 1.10
> 
> Which, of course, doesn't loop as intended, implicitly declares a
> variable called DO100I and assigns a value to it, and would typically
> not produce any sort of diagnostic.  And when you're debugging a paper
> listing, printed on low quality paper with a cheap, almost worn out,
> ribbon, that was not easy to spot.
> 

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.
0
Reply blmblm (1187) 7/6/2012 7:01:29 PM

On 12-Jun-12 16:09 PM, bob wrote:
> Are there any languages where you can actually use commas in the numbers?
>
> So, instead of having to write:
>
> int x = 5000000;
>
> You could write:
>
> int x = 5,000,000;
>
> I think this could improve clarity a lot.
>
> Is there really a good reason no one has done this?

Is

x = 5,00,000;

a syntax error? Is

x = 5,,000;

a syntax error? Is

x = 5,000.000,001;

a syntax error?

Anyway, *a* reason programming languages do not support this might be 
it's quite unusual to have such large constants hardcoded. For any 
really large numbers, one is more inclined to write

0x80000001

than

-2,147,483,647.

[Jw]

(I mis-counted the zeros in that hex constant! Perhaps it /would/ be 
nice to be able to write "8000:0001h" instead and let the computer sort 
it out.)
0
Reply jongware (25) 7/30/2012 1:53:41 PM

"Jongware" <jongware@no-spam.plz> wrote in message 
news:501691e6$0$6876$e4fe514c@news2.news.xs4all.nl...
> On 12-Jun-12 16:09 PM, bob wrote:
>> Are there any languages where you can actually use commas in the numbers?

> Is
>
> x = 5,00,000;
>
> a syntax error? Is
>
> x = 5,,000;
>
> a syntax error? Is
>
> x = 5,000.000,001;
>
> a syntax error?

If commas are allowed, then these can be warnings. That means you might end 
up getting the 5 million that was probably intended rather than 500,000.

> Anyway, *a* reason programming languages do not support this might be it's 
> quite unusual to have such large constants hardcoded. For any really large 
> numbers, one is more inclined to write
>
> 0x80000001
>
> than
>
> -2,147,483,647.

Sure, and one would write 0xF4240H instead of 1000000!

Even in your hex example, it's very easy to miss out one of those zeros.

-- 
Bartc 

0
Reply bc (2221) 7/30/2012 2:50:58 PM

On Mon, 30 Jul 2012 15:53:41 +0200, Jongware <jongware@no-spam.plz>
wrote:

>Is
>
>x = 5,00,000;
>
>a syntax error?
Not in India, you are showing the number in Lakhs.

rossum
0
Reply rossum48 (643) 7/30/2012 6:57:27 PM

"BartC" <bc@freeuk.com> writes:
>>0x80000001
>Sure, and one would write 0xF4240H instead of 1000000!

  That might be written as

(1u<<31)+1u

  and

1E6

  , respectively. One can also write

123_456

  (in Java, meaning the same as �123456�). In C, possibly

CONCAT2(123,456)

  with an appropriatly defined macro �CONCAT2�.

0
Reply ram (2839) 7/31/2012 12:05:41 PM

"Stefan Ram" <ram@zedat.fu-berlin.de> wrote in message 
news:numerals-20120731140512@ram.dialup.fu-berlin.de...
> "BartC" <bc@freeuk.com> writes:
>>>0x80000001
>>Sure, and one would write 0xF4240H instead of 1000000!

> ... One can also write
>
> 123_456
>
>  (in Java, meaning the same as �123456�). In C, possibly
>
> CONCAT2(123,456)
>
>  with an appropriatly defined macro �CONCAT2�.

Yes, I know, C's macro processor can do almost anything. (I've sometimes 
wondered what that language would look like if you took out everything that 
could instead be implemented, now matter how awkwardly, with a macro.)

But, having to extend the language yourself doesn't count! Anyway having to 
write CONCAT2(123,456) is only marginally more useful than just writing 
123*1000+456, which at least is universal.

-- 
Bartc 

0
Reply bc (2221) 8/1/2012 12:56:41 AM

"BartC" <bc@freeuk.com> writes:

> "Stefan Ram" <ram@zedat.fu-berlin.de> wrote in message
> news:numerals-20120731140512@ram.dialup.fu-berlin.de...
>> "BartC" <bc@freeuk.com> writes:
>>>>0x80000001
>>>Sure, and one would write 0xF4240H instead of 1000000!
>
>> ... One can also write
>>
>> 123_456
>>
>>  (in Java, meaning the same as »123456«). In C, possibly
>>
>> CONCAT2(123,456)
>>
>>  with an appropriatly defined macro »CONCAT2«.
>
> Yes, I know, C's macro processor can do almost anything. (I've
> sometimes wondered what that language would look like if you took out
> everything that could instead be implemented, now matter how
> awkwardly, with a macro.)
>
> But, having to extend the language yourself doesn't count! Anyway
> having to write CONCAT2(123,456) is only marginally more useful than
> just writing 123*1000+456, which at least is universal.

It's not universal in C because the arithmetic could overflow, but the
macro (if it does as its name suggests) would yield a literal constant.

-- 
Ben.
0
Reply ben.usenet (6516) 8/1/2012 2:31:06 AM

22 Replies
67 Views

(page loaded in 0.247 seconds)

Similiar Articles:


















7/22/2012 1:29:43 AM


Reply: