learn me c

C

CBFalconer

Default said:
How about one that delivers electric shocks to top-posters?
Of course, that would require platform-specific elements.

Since 98.34% of those are winders users, it would suffice to apply
the blue screen of death. This could also be used on detecting an
isolated u or lowercase i. This can be done on all the aforesaid
winders systems. Provision needs to be made for allowing such in
source code.

--
Some informative links:
< <http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>
 
B

Bill Reid

Here's a vague idea for a project that will take you through a lot of
useful concepts:

1. Model a deck of playing cards.

2. Shuffle the cards.

3. Deal poker hands from the deck.

4. Evaluate the relative values of the hands dealt.

5. Implement betting, and draw-poker with turns.
As somebody who's actually done this in both languages, I can
say this is much better accomplished in C++ than C, because C++
is "object-oriented".

The real brilliance is coming up with a well thought-out
heirarchy of classes: "Card", "Deck_Cards", "Player", "Dealer",
"Table", etc., for one game (I started with blackjack), then
just reusing them with a "Game" class that uses different
"game rules" to "quickly" model another game (blackjack to
poker, or vice versa), as opposed to just starting over
completely from scratch in C.

Just sayin'...
 
A

Andrew Poelstra

Bill Reid said:
As somebody who's actually done this in both languages, I can
say this is much better accomplished in C++ than C, because C++
is "object-oriented".

The real brilliance is coming up with a well thought-out
heirarchy of classes: "Card", "Deck_Cards", "Player", "Dealer",
"Table", etc., for one game (I started with blackjack), then
just reusing them with a "Game" class that uses different
"game rules" to "quickly" model another game (blackjack to
poker, or vice versa), as opposed to just starting over
completely from scratch in C.

In C you can "emulate" OO, and IMHO, this is actually clearer
in a lot of situations. In this case I wouldn't care either way:

Deck d = new Deck;
d.Shuffle();
Card c = d.drawFromAll();

As opposed to:
Deck d = create_deck();
Card c;
shuffle (d);
c = draw_from_all (c);
 
J

jmcgill

Bill said:
The real brilliance is coming up with a well thought-out
heirarchy of classes: "Card", "Deck_Cards", "Player", "Dealer",
"Table", etc., for one game (I started with blackjack), then
just reusing them with a "Game" class that uses different
"game rules" to "quickly" model another game (blackjack to
poker, or vice versa), as opposed to just starting over
completely from scratch in C.

While I don't disagree that an OO language lead to some very useful
programming idioms, I do strongly disagree with the notion that C cannot
be written in such a way as to have reusable modules.
 
R

Richard Heathfield

Bill Reid said:

The real brilliance is coming up with a well thought-out
heirarchy of classes: "Card", "Deck_Cards", "Player", "Dealer",
"Table", etc., for one game (I started with blackjack), then
just reusing them with a "Game" class that uses different
"game rules" to "quickly" model another game (blackjack to
poker, or vice versa), as opposed to just starting over
completely from scratch in C.

Ever heard of "libraries"?
 
J

jmcgill

Bill said:
As somebody who's actually done this in both languages, I can
say this is much better accomplished in C++ than C, because C++
is "object-oriented".

If you really want to change the subject from C to another C-related
language, I want to change it to Objective-C where I'm living these
days, not C++.

Whether the OP wants to do C++ or not is up to him, but this is comp.lang.c.

I participate in other newsgroups where other languages are topical.
 
T

Tom St Denis

Andrew said:
In C you can "emulate" OO, and IMHO, this is actually clearer
in a lot of situations. In this case I wouldn't care either way:

Deck d = new Deck;
d.Shuffle();
Card c = d.drawFromAll();

As opposed to:
Deck d = create_deck();
Card c;
shuffle (d);
c = draw_from_all (c);

You can do better than that.

struct Deck {
struct card (*drawFromAll)(struct Deck *self);
/* ... */
}

struct card deckDrawFromAll(struct Deck *self) {
return self->somecard;
}

struct Deck newDeck(void)
{
struct Deck ret;
ret.drawFromAll = deckDrawFromAll;
return ret;
}

int main(void)
{
struct Deck mydeck = newDeck();
struct Card mycard = mydeck.DrawFromAll(&mydeck);
// etc
return 0;
}

:)

Tom
 
M

Malcolm

Spiros Bousbouras said:
How long does the bus from Leeds to Bradford take ,
about an hour ? Books on C++ tend to be hundreds
of pages long ; if you managed to read hundereds of
pages within 1 hour then you're a very talented person.
Did you also read and understand all the code examples
the book had ? Even without that it is still an amazing feat.
Did you remember a few days afterwards the meaning of
all the keywords ? If yes your memory is impressive.

I suspect different people mean different things by "learn"
in this thread. But I don't know how to make it more concrete.
Personally I can't imagine in my wildest dreams learning C in
a few days.
An hour or so.
Enough time to leaf through a book and learn five or six keywords and the
essentially simple idea of object-orientation. Of course I already had
considerable experience of computer programming.

I went to Oxford, and one of the things Oxford teaches you is not to mess
about when material needs to be learnt. For instance on my first day we were
invited in for a chat and some sherry, and asked about our journeys. Then it
was "and O, by the way, ladies and gentlemen, essays on Tennyson by the day
after tomorrow, if you wouldn't mind." Most of us hadn't read a word of his
poetry. So we had to go into the library and get something down on paper.
Most people don't have that. But it is not a superhuman feat by any stretch
of the imagination. It shouldn't take a long time to learn a programming
language.
 
B

Bill Reid

Tom St Denis said:
Andrew Poelstra wrote:

You can do better than that.

struct Deck {
struct card (*drawFromAll)(struct Deck *self);
/* ... */
}

struct card deckDrawFromAll(struct Deck *self) {
return self->somecard;
}

struct Deck newDeck(void)
{
struct Deck ret;
ret.drawFromAll = deckDrawFromAll;
return ret;
}

int main(void)
{
struct Deck mydeck = newDeck();
struct Card mycard = mydeck.DrawFromAll(&mydeck);
// etc
return 0;
}
Ah, yes, you're getting closer to C++ here, nice use of a function
pointer within the structure, very good...

Actually, though, the "deck" doesn't "draw" from itself, the "dealer"
does. The "deck" is just mostly an array of "cards" with fewer remaining
cards as they are dealt "from the top" (we're not modeling "cheating"
here...yet). Can you make a "Dealer" struct that is a "friend"
of the "Deck" struct that is the only struct that is allowed to access
the "Deck" depletion function?
 
B

Bill Reid

Richard Heathfield said:
Bill Reid said:



Ever heard of "libraries"?
I think so...ever hear of "inheritance"?

Look, judging from the response, I sorry I brought up the C**
language. I myself have not "abandoned" C in favor of C++ for
everything, because there is a lot of stuff that can be done quicker
(and better) in C. I actually am predisposed to writing in C
when possible because all the extra typing required in C++
aggravates my incipient carpal tunnel syndrome...

However, some of OO "extensions" provided by C++ can be
very useful for certain types of projects, that's all. Sure you can
emulate a lot of this stuff in C (C++ was originally a preprocessor
extension of C), but that's true of a whole bunch of other stuff
too, and there does a come a point of just asking yourself, "Why
am I re-inventing the wheel here, especially since the wheel
is just a matter of naming my files *.cpp..."
 
R

Richard Heathfield

Bill Reid said:
I think so...ever hear of "inheritance"?

Sure. But you don't need C++-style inheritance just to play a different game
of cards.
Look, judging from the response, I sorry I brought up the C**
language.

Given that the subject line is "learn me c", I think you're wise to be
sorry. :)


I actually am predisposed to writing in C
when possible because all the extra typing required in C++
aggravates my incipient carpal tunnel syndrome...

That in itself is significant. Me, I don't have incipient carpal tunnel
syndrome. But then, I hardly ever use C++.
However, some of OO "extensions" provided by C++ can be
very useful for certain types of projects, that's all.

Not in comp.lang.c they can't. If you want to discuss C++, there's a dirty
great newsgroup just down the corridor where they like nothing better.

Sure you can
emulate a lot of this stuff in C

Er, no thanks. I have no desire to emulate carpal tunnel syndrome. :)

(C++ was originally a preprocessor
extension of C), but that's true of a whole bunch of other stuff
too, and there does a come a point of just asking yourself, "Why
am I re-inventing the wheel here, especially since the wheel
is just a matter of naming my files *.cpp..."

Um, the wheel was already invented. C++ simply painted it a new colour, and
its advocates insist that the new colour is the only "right" one - which is
silly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top