Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: rms from rosettacode

Reply
Thread Tools

Re: rms from rosettacode

 
 
Kaz Kylheku
Guest
Posts: n/a
 
      12-27-2011
On 2011-12-27, superpollo <(E-Mail Removed)> wrote:
> what gives?


What gives is that you're not yet competent enough in C to be working on
Rosetta Code examples. Please find a different hobby.
 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      12-27-2011
On 2011-12-27, Kaz Kylheku <(E-Mail Removed)> wrote:
> On 2011-12-27, superpollo <(E-Mail Removed)> wrote:
>> what gives?


> What gives is that you're not yet competent enough in C to be working on
> Rosetta Code examples. Please find a different hobby.


I would rather see people be in over their heads on Rosetta Code than on
medical equipment.

-s
--
Copyright 2011, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      12-28-2011
On 12/27/2011 3:31 PM, superpollo wrote:
> Kaz Kylheku ha scritto:
>> On 2011-12-27, superpollo <(E-Mail Removed)> wrote:
>>> what gives?

>>
>> What gives is that you're not yet competent enough in C to be working on
>> Rosetta Code examples. Please find a different hobby.

>
> thanks for your constructive criticism. a beautiful way to lure
> newcomers to the language!


Especially "newcomers" who've participated in this forum since
at least June 2009. "Newcomers" who've taken thirty or more months
to fail to find the FAQ.

Yes, Kaz is being a bit brutal. But I think he's being honest:
If in two and a half years you have not learned what happens when you
"pass an array" to a function, you have scant aptitude for this
particular discipline. Other and worthier disciplines exist; go and
pursue one of those.

--
Eric Sosman
(E-Mail Removed)d
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      12-28-2011
On Dec 28, 1:49*am, Eric Sosman <(E-Mail Removed)> wrote:
> On 12/27/2011 3:31 PM, superpollo wrote:
>
> > Kaz Kylheku ha scritto:
> >> On 2011-12-27, superpollo <(E-Mail Removed)> wrote:
> >>> what gives?

>
> >> What gives is that you're not yet competent enough in C to be working on
> >> Rosetta Code examples. Please find a different hobby.

>
> > thanks for your constructive criticism. a beautiful way to lure
> > newcomers to the language!

>
> * * *Especially "newcomers" who've participated in this forum since
> at least June 2009. *"Newcomers" who've taken thirty or more months
> to fail to find the FAQ.
>
> * * *Yes, Kaz is being a bit brutal. *But I think he's being honest:
> If in two and a half years you have not learned what happens when you
> "pass an array" to a function, you have scant aptitude for this
> particular discipline. *Other and worthier disciplines exist; go and
> pursue one of those.


good grief. So he missed something (something important, admittedly!).
I'm a fan of virtually anyone learning to program. I think it should
be part of 21st century literacy.
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      12-28-2011
On 12/27/2011 08:49 PM, Eric Sosman wrote:
> On 12/27/2011 3:31 PM, superpollo wrote:
>> Kaz Kylheku ha scritto:
>>> On 2011-12-27, superpollo <(E-Mail Removed)> wrote:
>>>> what gives?
>>>
>>> What gives is that you're not yet competent enough in C to be working on
>>> Rosetta Code examples. Please find a different hobby.

>>
>> thanks for your constructive criticism. a beautiful way to lure
>> newcomers to the language!

>
> Especially "newcomers" who've participated in this forum since
> at least June 2009. "Newcomers" who've taken thirty or more months
> to fail to find the FAQ.
>
> Yes, Kaz is being a bit brutal. But I think he's being honest:
> If in two and a half years you have not learned what happens when you
> "pass an array" to a function, you have scant aptitude for this
> particular discipline. Other and worthier disciplines exist; go and
> pursue one of those.


I think you're both being a bit harsh on him. When I saw his comment
about being a newcomer, I had the same response - I remembered him being
a long-term participant. However, when I searched with Google groups, I
also found out he'd been posting here for only 30 months, and I decided
not to comment. It's a fairly long time to have made so little progress
in understanding C. However, if he's learning it on his own time while
working full time, and not taking any classes in C, it's not completely
unreasonable that he might still be at this low level, particularly if
there's any other reason (such as, for example, being a single father)
that most of the rest of his "spare" time is already accounted for.
--
James Kuyper
 
Reply With Quote
 
BartC
Guest
Posts: n/a
 
      12-28-2011
"James Kuyper" <(E-Mail Removed)> wrote in message
news:jdf43c$aph$(E-Mail Removed)...
> On 12/27/2011 08:49 PM, Eric Sosman wrote:


>> If in two and a half years you have not learned what happens when you
>> "pass an array" to a function, you have scant aptitude for this
>> particular discipline. Other and worthier disciplines exist; go and
>> pursue one of those.

>
> I think you're both being a bit harsh on him. When I saw his comment
> about being a newcomer, I had the same response - I remembered him being
> a long-term participant. However, when I searched with Google groups, I
> also found out he'd been posting here for only 30 months, and I decided
> not to comment.


I've been posting here a lot longer, but still have problems with some
things that should be straightforward to a C programmer.

For example, I had trouble the other night with creating a struct with
self-referential members. I tried loads of combinations including forward
declarations and got nowhere. I was about to post here, then came across
this form in some code that was lying around:

typedef struct snode{
int value;
int opcode;
struct snode *aref,*bref;
} node;

That worked, but how can I turn the 'struct snode*' into a much tidier 'node
*'? This doesn't work:

typedef struct {
int value;
int opcode;
node *aref,*bref;
} node;

--
Bartc

 
Reply With Quote
 
Dr Nick
Guest
Posts: n/a
 
      12-28-2011
"BartC" <(E-Mail Removed)> writes:

> "James Kuyper" <(E-Mail Removed)> wrote in message
> news:jdf43c$aph$(E-Mail Removed)...
>> On 12/27/2011 08:49 PM, Eric Sosman wrote:

>
>>> If in two and a half years you have not learned what happens when you
>>> "pass an array" to a function, you have scant aptitude for this
>>> particular discipline. Other and worthier disciplines exist; go and
>>> pursue one of those.

>>
>> I think you're both being a bit harsh on him. When I saw his comment
>> about being a newcomer, I had the same response - I remembered him being
>> a long-term participant. However, when I searched with Google groups, I
>> also found out he'd been posting here for only 30 months, and I decided
>> not to comment.

>
> I've been posting here a lot longer, but still have problems with some
> things that should be straightforward to a C programmer.
>
> For example, I had trouble the other night with creating a struct with
> self-referential members. I tried loads of combinations including
> forward declarations and got nowhere. I was about to post here, then
> came across this form in some code that was lying around:
>
> typedef struct snode{
> int value;
> int opcode;
> struct snode *aref,*bref;
> } node;
>
> That worked, but how can I turn the 'struct snode*' into a much tidier 'node
> *'? This doesn't work:
>
> typedef struct {
> int value;
> int opcode;
> node *aref,*bref;
> } node;


IIRC:

typedef struct snode snode;
struct snode {
int value;
int opcode;
snode *aref,*bref;
};

those empty struct things (I'm keeping well clear of the
definitions/declarations arguments here) aren't needed very often, but
when they are, they are very useful.
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      12-28-2011
On 2011-12-27, superpollo <(E-Mail Removed)> wrote:
> Kaz Kylheku ha scritto:
>> On 2011-12-27, superpollo <(E-Mail Removed)> wrote:
>>> what gives?

>>
>> What gives is that you're not yet competent enough in C to be working on
>> Rosetta Code examples. Please find a different hobby.

>
> thanks for your constructive criticism. a beautiful way to lure
> newcomers to the language!


Sorry, I thought you might have been thinking of actually editing the Rosetta
Code example to "improve" it. Knee-jerk reaction from having fixed bad C on
that site.

I meant "find a hobby other than editing Rosetta Code C examples",
not "stop learning C programming", of course!

Speaking of which, Rosetta Code C solutions are a mixed bag of nuts.
Many are not well-written: poor handling of errors and corner cases, and
written as if the standard library didn't exist (e.g. reimplementing functions
like strchr from scratch). I recently fixed a bunch that neglected to
null terminate strings (nor even allocate space for that).

You could inadvertently pick up bad ideas by studying these examples.
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      12-28-2011
On 2011-12-28, BartC <(E-Mail Removed)> wrote:
> I've been posting here a lot longer, but still have problems with some
> things that should be straightforward to a C programmer.
>
> For example, I had trouble the other night with creating a struct with
> self-referential members. I tried loads of combinations including forward
> declarations and got nowhere. I was about to post here, then came across
> this form in some code that was lying around:
>
> typedef struct snode{
> int value;
> int opcode;
> struct snode *aref,*bref;
> } node;


There is no need for the tag and typedef name to be different. They
are in a different namespace disambiguated by the "struct" keyword:

typedef struct node {
int value;
int opcode;
struct node *aref, *bref;
} node;

Maybe the use of two symbols snode and node adds to your perception
that it is untidy. I mean, if you have N structures, you use 2*N
identifiers in their naming.

> That worked, but how can I turn the 'struct snode*' into a much tidier 'node
> *'? This doesn't work:


This brings to mind an earlier Eric Sosman posting, where he recounted
an analogy from a friend: maybe you're trying to clean the beach of bottle caps
and cigarette butts so that the areas around the rotting whale carcasses are
nice and clean.

How tidy will the overall program be when it grows large and complex?

Big C programs are very hard to keep tidy. Even if the program is developed by
a single developer in his spare time, who is single-mindedly dedicated to
tidiness, tidiness will eventually give way here and there to functionality.

> typedef struct {
> int value;
> int opcode;
> node *aref,*bref;
> } node;



Perfectly valid C++, hint hint:

struct node {
node *aref;
};

In C there is no way around the keyword struct occuring twice, e.g:

/* A */
typedef struct node node;
struct node {
node *aref, *bref;
};


/* B */
struct node {
typedef struct node node;
node *aref, *bref;
};

B loses C++ compatibility though. The typedef name is not scoped to
the struct in C, but in C++ it is in class scope.

Well, there is always preprocessing:

#define node struct node

node { /* oh, boy! */
node *a, *b;
}
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-28-2011
"BartC" <(E-Mail Removed)> writes:
[...]
> For example, I had trouble the other night with creating a struct with
> self-referential members. I tried loads of combinations including forward
> declarations and got nowhere. I was about to post here, then came across
> this form in some code that was lying around:
>
> typedef struct snode{
> int value;
> int opcode;
> struct snode *aref,*bref;
> } node;
>
> That worked, but how can I turn the 'struct snode*' into a much tidier 'node
> *'? This doesn't work:
>
> typedef struct {
> int value;
> int opcode;
> node *aref,*bref;
> } node;


My suggestion is just to drop the "typedef" altogether, and refer to the
type as "struct snode":

struct snode {
int value;
int opcode;
struct snode *aref;
struct snode *bref;
};

If you feel the need to have a one-word name for the type, you can
typedef the incomplete struct type and then complete it by defining it.
Note that there's no need to use different names for the struct tag and
the typedef:

typedef struct snode snode;
struct snode {
int opcode;
snode *aref;
snode *bref;
};

Another common approach is to combine the typedef and struct
declarations -- but then the typedef isn't visible until the end
of the struct declaration:

typedef struct snode {
int opcode;
struct snode *aref;
struct snode *bref;
} snode;

But really, the type already has a perfectly good name, "struct snode".
Hiding its "structness" behind a typedef doesn't buy you anything.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
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
Re: rms from rosettacode BartC C Programming 11 12-28-2011 10:45 AM
Re: rms from rosettacode James Kuyper C Programming 4 12-27-2011 11:46 PM
same or different rms file in different brand phones Spacey Spade Java 4 06-15-2005 08:22 AM
RMS and midlets leggolas Java 4 03-22-2005 01:20 AM
j2me and RMS Rohit Java 1 04-02-2004 02:53 PM



Advertisments