Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > If you could change the C or C++ or Java syntax, what would you like different?

Reply
Thread Tools

If you could change the C or C++ or Java syntax, what would you like different?

 
 
Tim Streater
Guest
Posts: n/a
 
      10-09-2010
In article
<(E-Mail Removed)>,
James Dow Allen <(E-Mail Removed)> wrote:

> (4) Declarations like char* a, b, c;
> are confusing: a is a pointer but b and c are not.
> (It's little problem for most of us, who write instead
> char *a, b, c;
> )


Doesn't stop it being rubbish syntax. Along with the crap preprocessor
it was one of the irritations I endured when first writing in C. It
makes no sense that when I think I'm declaring a char, it turns out that
some of the things I'm declaring are not, in fact, chars, but rather
pointers to char (or, possibly, far worse).

Too late to change now, though.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      10-09-2010
Ian Collins <(E-Mail Removed)> writes:

> On 10/ 9/10 08:02 PM, James Dow Allen wrote:
>> On Oct 9, 2:09 am, Alexander<(E-Mail Removed)> wrote:
>>> ... anything you do not like in the C ... syntax.

>>
>> (4) Declarations like char* a, b, c;
>> are confusing: a is a pointer but b and c are not.
>> (It's little problem for most of us, who write instead
>> char *a, b, c;
>> )

>
> No problem at all for those of us who declare our variables at the
> point of initialisation.


Eh? How does char* a = 0, b = 0, c = 0; make the syntax any less
error-prone? Did you mean "for those of us who declare our variables
one per declaration"?

For the record, I *like* C's declaration syntax and, left to my own
devices, I'd be very happy to declare

char buf[SIZE], *start = buf, c = *buf;

Part of the reason I like it is that it is compact. The more of the
semantically important code I can take in at once, the happier I am.

I don't recall any hard bugs being due to a mistaken declaration. I'd
imaging that most get found at the first compile. I agree that the
layout is important. I can't abide either char* a; or char * a;.

--
Ben.
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      10-09-2010
On 10/ 9/10 11:12 PM, Ben Bacarisse wrote:
> Ian Collins<(E-Mail Removed)> writes:
>
>> On 10/ 9/10 08:02 PM, James Dow Allen wrote:
>>> On Oct 9, 2:09 am, Alexander<(E-Mail Removed)> wrote:
>>>> ... anything you do not like in the C ... syntax.
>>>
>>> (4) Declarations like char* a, b, c;
>>> are confusing: a is a pointer but b and c are not.
>>> (It's little problem for most of us, who write instead
>>> char *a, b, c;
>>> )

>>
>> No problem at all for those of us who declare our variables at the
>> point of initialisation.

>
> Eh? How does char* a = 0, b = 0, c = 0; make the syntax any less
> error-prone? Did you mean "for those of us who declare our variables
> one per declaration"?


Maybe "at the point of first use (which happens to be the point of
initialisation)" would have been clearer?

--
Ian Collins
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      10-09-2010
On 10/ 9/10 11:12 PM, Ben Bacarisse wrote:
> Did you mean "for those of us who declare our variables
> one per declaration"?


That too!

--
Ian Collins
 
Reply With Quote
 
BartC
Guest
Posts: n/a
 
      10-09-2010
"Ben Bacarisse" <(E-Mail Removed)> wrote in message
news:0.d8d18d98b65e37458b9e.20101009111241BST.87lj (E-Mail Removed)...
> Ian Collins <(E-Mail Removed)> writes:


>> No problem at all for those of us who declare our variables at the
>> point of initialisation.

>
> Eh? How does char* a = 0, b = 0, c = 0; make the syntax any less
> error-prone? Did you mean "for those of us who declare our variables
> one per declaration"?


Perhaps he means at the point of first use. Although this doesn't help much
here:

fn(&a);

where fn is expected to initialise a which has not yet been declared.

> For the record, I *like* C's declaration syntax and, left to my own
> devices, I'd be very happy to declare
>
> char buf[SIZE], *start = buf, c = *buf;


This is actually confusing; I wasn't sure what sort of pointer c was
supposed to be at first, as I read it as c = &buf..

> Part of the reason I like it is that it is compact.


Not needing to declare variables is even more compact...

If you mean you can declare arrays, pointers and single characters all in
the same statement, then I suppose it might be. But not everyone would agree
it's a good thing.

--
Bartc

 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      10-09-2010
Dann Corbit wrote:

> If I were to add any feature to C, it would be a totally safe string
> type, that carries its length.


You can always write a library that wraps all string-handling functions from the standard library so
that it can use a customized string data type (i.e., struct c_string {}. No matter how you cut
it, the solution to that issue (which isn't necessarily a problem) will always assume that form.


Rui Maciel
 
Reply With Quote
 
BartC
Guest
Posts: n/a
 
      10-09-2010
"James Dow Allen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Oct 9, 2:09 am, Alexander <(E-Mail Removed)> wrote:
>> ... anything you do not like in the C ... syntax.

>
> I'll offer 2 cents worth:
>
> (1) I happen to *love* C syntax. You might prefer
> Pascal syntax but, at the risk of sounding rude,
> why don't you just then go code in Pascal?


The languages don't do the same thing. Some people want to have the same
coding freedom C provides, but with a different, perhaps more formal,
syntax.

I'm not a C programmer. But from attempting to compile other people's open
source projects, it seems to me that a C programmer needs to know 4
languages:

(A) The C syntax itself

(B) The preprocessor language, which at first looks ultra-simple, just a few
#-directives, until you start using macros. This can lead to code which is
no longer C, and horrendous to decipher if you are not the author.

(C) Type declaration syntax. I'm surprised no-one has mentioned this
elephant in the room. I find it utterly impossible once I go beyond the
basics. I always need to try random combinations with CDECL until I get what
I want, then safely lock the result away until I might need it again.

(D) Make-file syntax. If you're trying to build an application, and no other
instructions exist to assemble the project, then you're at the mercy of this
syntax. Especially if the make-syntax is not compatible with your compiler,
or you need to make changes.

Taken all together, the whole thing can look a mess to anyone who doesn't
deal with this every day and who thinks nothing of it.

These comments apply to C. For C++, you can probably add (E) and (F). In
other words, a nightmare.

Java I don't know anything about; I understand it's big (having once spent
ages downloading a 28MB version (as 20 chunks at 9.6Kbaud), then finding I
needed another 20MB to download the docs before I could do anything).

--
Bartc

 
Reply With Quote
 
Felix Palmen
Guest
Posts: n/a
 
      10-09-2010
* Ian Collins <(E-Mail Removed)>:
> On 10/ 9/10 11:12 PM, Ben Bacarisse wrote:
>> Ian Collins<(E-Mail Removed)> writes:
>>> No problem at all for those of us who declare our variables at the
>>> point of initialisation.

>>
>> Eh? How does char* a = 0, b = 0, c = 0; make the syntax any less
>> error-prone? Did you mean "for those of us who declare our variables
>> one per declaration"?

>
> Maybe "at the point of first use (which happens to be the point of
> initialisation)" would have been clearer?


Which would be -- in the general case of first using them somewhere in
the middle of a scope block -- illegal in C89.

In fact, I like this C89 restriction. The beginning of a scope block is
also a good place to document the variables that are needed inside with
an appropriate comment. I even employ this in languages that would allow
declarations anywhere, like C#.

Regards,
Felix

--
Felix Palmen (Zirias) + [PGP] Felix Palmen <(E-Mail Removed)>
web: http://palmen-it.de/ | http://palmen-it.de/pub.txt
my open source projects: | Fingerprint: ED9B 62D0 BE39 32F9 2488
http://palmen-it.de/?pg=pro + 5D0C 8177 9D80 5ECF F683
 
Reply With Quote
 
Felix Palmen
Guest
Posts: n/a
 
      10-09-2010
* Tim Streater <(E-Mail Removed)>:
> Doesn't stop it being rubbish syntax. Along with the crap preprocessor
> it was one of the irritations I endured when first writing in C. It
> makes no sense that when I think I'm declaring a char, it turns out that
> some of the things I'm declaring are not, in fact, chars, but rather
> pointers to char (or, possibly, far worse).


Well, I have to admit it surprised me, too, because I first looked at C
after programming some object pascal, so I was used to the concept that
the attribute "pointer" applies to the type. But I think the C point of
view, that the notion of a type only relates to the stored data and the
attribute "pointer" instead applies to the individual variable, is
equally valid.

Regards,
Felix

--
Felix Palmen (Zirias) + [PGP] Felix Palmen <(E-Mail Removed)>
web: http://palmen-it.de/ | http://palmen-it.de/pub.txt
my open source projects: | Fingerprint: ED9B 62D0 BE39 32F9 2488
http://palmen-it.de/?pg=pro + 5D0C 8177 9D80 5ECF F683
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      10-09-2010
Ian Collins <(E-Mail Removed)> writes:

> On 10/ 9/10 11:12 PM, Ben Bacarisse wrote:
>> Ian Collins<(E-Mail Removed)> writes:
>>
>>> On 10/ 9/10 08:02 PM, James Dow Allen wrote:
>>>> On Oct 9, 2:09 am, Alexander<(E-Mail Removed)> wrote:
>>>>> ... anything you do not like in the C ... syntax.
>>>>
>>>> (4) Declarations like char* a, b, c;
>>>> are confusing: a is a pointer but b and c are not.
>>>> (It's little problem for most of us, who write instead
>>>> char *a, b, c;
>>>> )
>>>
>>> No problem at all for those of us who declare our variables at the
>>> point of initialisation.

>>
>> Eh? How does char* a = 0, b = 0, c = 0; make the syntax any less
>> error-prone? Did you mean "for those of us who declare our variables
>> one per declaration"?

>
> Maybe "at the point of first use (which happens to be the point of
> initialisation)" would have been clearer?


I'm not sure. If the following line is

while (a[b] != c) ...

then the "point of first use" is the declaration I wrote. Similarly, if
you need:

char buf[SIZE], *start = buf, c = *start;

I can't think of a form that is closer to declaring them at "the point
of first use" than this! I accept that some people don't like this
form, but I don't think it's related to initialising things just prior
to use.

--
Ben.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If you could change the C or C++ or Java syntax, what would you like different? Alexander C++ 68 11-08-2013 01:23 PM
don't like, so don't waste your time thinking and buy them. You know,if you don't like one thing, it means nothing for you.</p> fashion t shirts seller Cisco 0 06-13-2011 02:01 AM
If you could change the C or C++ or Java syntax, what would you like different? Alexander Java 60 11-04-2010 05:36 AM
Incredible - I bet you would like a camera like this! ~BD~ Computer Security 1 02-26-2009 09:45 PM
Would you like to host a website about Java programming? Jaga Java 0 12-02-2003 06:12 PM



Advertisments