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?

 
 
Marcin Grzegorczyk
Guest
Posts: n/a
 
      10-09-2010
Ben Bacarisse wrote:
> Anand Hariharan <(E-Mail Removed)> writes:
>
>> On Oct 9, 5:12 am, Ben Bacarisse <(E-Mail Removed)> wrote:
>> (...)
>>> 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;

>>
>> Assuming this was local to a function, what is the value of 'c'?
>> Isn't it UB to dereference buf (access buf[0]) without initialising
>> buf?

>
> Only if char has trap representations.


It appears that accessing any object using type ‘char’ cannot cause UB
(6.2.6.1p5 specifically excludes all character types), regardless of the
object representation, so arguably char cannot have trap representations.

> Otherwise the value is
> indeterminate but a valid value for the type.


Note that this provision is specific to C99, and that C1X is restricting
it to objects that reside in memory (i.e. have a static or thread
storage duration, or have their address taken). For more information,
see DR #338 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_338.htm>.
--
Marcin Grzegorczyk
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      10-09-2010
On 10/10/10 12:15 PM, Richard Harter wrote:
> On Sat, 09 Oct 2010 16:35:36 +0100, Ben Bacarisse
> <(E-Mail Removed)> wrote:
>
>
>> I'd be prepared to say that "mixed" declarations (declarations with
>> multiple forms of declarator) were considered idiomatic in "old" C. I
>> remember coming across the advice of having one declarator per
>> declaration quite late and thinking it rather odd and fussy.

>
> Count me as odd and fussy. I'm of the school that believes that
> variables should have a well defined meaning and that that
> meaning should be documented.


And the best way to do that is to give them a meaningful name and
declare them when they are needed. That way the use is obvious.

--
Ian Collins
 
Reply With Quote
 
 
 
 
BartC
Guest
Posts: n/a
 
      10-09-2010


"August Karlstrom" <(E-Mail Removed)> wrote in message
news:i8qsd9$ihp$(E-Mail Removed)...
> On 2010-10-08 21:09, Alexander wrote:
>> Please share your oppinion on anything you do not like in the C or C++
>> or Java syntax (they're quite similar).

>
> The assignment operator `=' will confuse any newcomer with a basic
> knowledge of mathematics. You can only imagine how many bugs it has caused
> in C and C++ when being inadvertently used as an equality operator instead
> of `=='.


This was the biggest problem I had, when trying to code a sizeable C project
a couple of years back.

The syntax I normally used had for ":=" for assignment, and "=" for
equality.

Wrongly using ":=" in C just gave a syntax error. Wrongly using "=" in the
other languages (using my own not very robust compilers), either caused a
crash, or silently did nothing (certainly not assignment). While using "="
in C instead of "==" had it's own problems...

But, yes, the use of "=" and "==" in C I don't think were the best choices,
but they have propagated through to too many other languages now.

--
Bartc

 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      10-10-2010
http://www.velocityreviews.com/forums/(E-Mail Removed) (Richard Harter) writes:

> On Sat, 09 Oct 2010 16:35:36 +0100, Ben Bacarisse
> <(E-Mail Removed)> wrote:
>
>>I'd be prepared to say that "mixed" declarations (declarations with
>>multiple forms of declarator) were considered idiomatic in "old" C. I
>>remember coming across the advice of having one declarator per
>>declaration quite late and thinking it rather odd and fussy.

>
> Count me as odd and fussy. I'm of the school that believes that
> variables should have a well defined meaning and that that
> meaning should be documented.


I agree (how could anyone not agree?) but I think I must have missed
your point because I don't see the connection with what I wrote. Would
you elaborate?

> Comments!? We don't need no steenking comments!


--
Ben.
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      10-10-2010
On 10/10/10 03:46 PM, Richard Harter wrote:
> On Sun, 10 Oct 2010 12:27:26 +1300, Ian Collins
> <(E-Mail Removed)> wrote:
>
>> On 10/10/10 12:15 PM, Richard Harter wrote:
>>> On Sat, 09 Oct 2010 16:35:36 +0100, Ben Bacarisse
>>> <(E-Mail Removed)> wrote:
>>>
>>>
>>>> I'd be prepared to say that "mixed" declarations (declarations with
>>>> multiple forms of declarator) were considered idiomatic in "old" C. I
>>>> remember coming across the advice of having one declarator per
>>>> declaration quite late and thinking it rather odd and fussy.
>>>
>>> Count me as odd and fussy. I'm of the school that believes that
>>> variables should have a well defined meaning and that that
>>> meaning should be documented.

>>
>> And the best way to do that is to give them a meaningful name and
>> declare them when they are needed. That way the use is obvious.

>
> Some people actually believe that.


The truth is like that.

--
Ian Collins
 
Reply With Quote
 
ClassCastException
Guest
Posts: n/a
 
      10-10-2010
On Fri, 08 Oct 2010 12:09:19 -0700, Alexander wrote:

> Please share your oppinion on anything you do not like in the C or C++
> or Java syntax (they're quite similar).
>
> In order to maintain the integrity of the discussion (have everything at
> the same place) please respond on comp.lang.c.
>
> Cheers,
> Alexander


Ahh. <grabs popcorn> <lies back>

....

<munch, munch>

Er, where's all the action?

What, only five replies? What, nobody's even SUGGESTED operator
overloading in Java yet? Waaah, where's the flamewar!? I feel like I sat
down in the theatre to watch a Jean Claude Van Damme movie and so far it
more resembles the Ya-Ya Sisterhood of Traveling Bra-Straps III or
whatever the latest damn chick flick is called.

Okay, then, I guess it's up to me. I've got to stop lurking and take
action. A man's gotta do what a man's gotta do.

Lisp macros and first-class lambdas. In all three languages.
 
Reply With Quote
 
Felix Palmen
Guest
Posts: n/a
 
      10-10-2010
* Ian Collins <(E-Mail Removed)>:
> On 10/10/10 01:28 AM, Felix Palmen wrote:
>> 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.

>
> If they have a sensible name and are declared where needed, they don't
> need a descriptive comment.
>
>> I even employ this in languages that would allow
>> declarations anywhere, like C#.

>
> Or modern C. Doing that must make you unpopular with your colleagues,
> it certainly would on a C++ project.


While descriptive names are mandatory for clear code, they can't replace
having an overview of all variables used inside a block entirely in any
case. I find code separating declarations from actual statements
generally better readable. As scope blocks should be small in /good/
code, it's admittedly not that much of a difference...

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-10-2010
* August Karlstrom <(E-Mail Removed)>:
> The assignment operator `=' will confuse any newcomer with a basic
> knowledge of mathematics. You can only imagine how many bugs it has
> caused in C and C++ when being inadvertently used as an equality
> operator instead of `=='. In code comments it also makes the usage of
> the mathematical `=' slightly ambiguous which forces people to use `=='
> instead. UGLY is the word.


Agreed with that. But I think the /worst/ thing in existence are
languages using the single 'equals' sign for both, assignment AND
comparison, depending on the context. (...basic...*cough*)

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
 
luser- -droog
Guest
Posts: n/a
 
      10-10-2010
On Oct 9, 6:58*pm, "BartC" <(E-Mail Removed)> wrote:
> "August Karlstrom" <(E-Mail Removed)> wrote in message
>
> news:i8qsd9$ihp$(E-Mail Removed)...
>
> > On 2010-10-08 21:09, Alexander wrote:
> >> Please share your oppinion on anything you do not like in the C or C++
> >> or Java syntax (they're quite similar).

>
> > The assignment operator `=' will confuse any newcomer with a basic
> > knowledge of mathematics. You can only imagine how many bugs it has caused
> > in C and C++ when being inadvertently used as an equality operator instead
> > of `=='.

>
> This was the biggest problem I had, when trying to code a sizeable C project
> a couple of years back.
>
> The syntax I normally used had for ":=" for assignment, and "=" for
> equality.
>
> Wrongly using ":=" in C just gave a syntax error. Wrongly using "=" in the
> other languages (using my own not very robust compilers), either caused a
> crash, or silently did nothing (certainly not assignment). While using "="
> in C instead of "==" had it's own problems...
>
> But, yes, the use of "=" and "==" in C I don't think were the best choices,
> but they have propagated through to too many other languages now.
>


Ooo, I know!
We can replace both "=" and "==" with "is" and let the compiler
figure it out! You could give it a hint with
#pragma is_assignment
c=getchar();
#pragma is_equality_test
if (c==EOF) ...

--
imagine i'm emphatically raising my eyebrows.
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      10-10-2010
On 10/10/10 08:20 PM, Felix Palmen wrote:
> * Ian Collins<(E-Mail Removed)>:
>> On 10/10/10 01:28 AM, Felix Palmen wrote:
>>> 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.

>>
>> If they have a sensible name and are declared where needed, they don't
>> need a descriptive comment.
>>
>>> I even employ this in languages that would allow
>>> declarations anywhere, like C#.

>>
>> Or modern C. Doing that must make you unpopular with your colleagues,
>> it certainly would on a C++ project.

>
> While descriptive names are mandatory for clear code, they can't replace
> having an overview of all variables used inside a block entirely in any
> case. I find code separating declarations from actual statements
> generally better readable. As scope blocks should be small in /good/
> code, it's admittedly not that much of a difference...


That is true.

One point which is often overlooked is variables (for lack of a better
name) that are constants can be declared as const if they are declared
when needed. This may be a small detail, but it does add to the self
documenting nature of the code and my help with optimisations.

I prefer not to mix calculations with comparisons, so I often assign the
result of a calculation to a const and then use it in a comparison. For
example in code dealing with power calculations I'd write

const int power = amps*volts;

if( power > 42 ) {..}

rather than

if( amps*volts > 42 ) {..}

That style isn't as clear if power had to be declared at the top of the
scope.

--
Ian Collins
 
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