Welcome, Guest. Please login or register.

Author Topic: Learning C with the Amiga  (Read 32436 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Learning C with the Amiga
« Reply #89 on: February 08, 2007, 08:30:23 AM »
@AJCopland
Quote
Now that should teach you to structure code. By structure I mean that you'll make a conscious decision to implement things in a particular way and in a methodical manor as opposed to other languages where you implement things in a certain way... because it's the only way that the language will let you.

Amen to that (and the rest of the message). Well put.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Learning C with the Amiga
« Reply #90 on: February 08, 2007, 08:37:34 AM »
Well yeah, it's quite pointless to hand optimize bubblesort in assembler, when you could have just replaced the algorithm with quick- or mergesort. ;-)
 

Offline Sys_64738

  • Newbie
  • *
  • Join Date: Jan 2007
  • Posts: 3
    • Show only replies by Sys_64738
Re: Learning C with the Amiga
« Reply #91 on: February 08, 2007, 09:31:35 AM »
@Karlos

Quote

There's nothing "specific" in the STL or anything for data serialization


If we somehow consider Boost an STL++ (and in fact Boost is a widely accepted standard in C++ programmers community), you may find this useful:

http://www.boost.org/libs/serialization/doc/index.html


Quote

class StreamStorable {

  public:
    virtual bool write(OutputStream& s) = 0;
    virtual bool read(InpputStream& s) = 0;

}


Is this not complete right?
Defining an interface class without a virtual destructor is an invitation to disasters :-)


 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Learning C with the Amiga
« Reply #92 on: February 08, 2007, 09:33:29 AM »
No, it's not complete as I was focusing on the actual serialization mechanism and not polymorphism in general. Yes the actual class has a virtual destructor. I'll add it to th4e example for completeness ;-)
int p; // A
 

Offline AJCopland

Re: Learning C with the Amiga
« Reply #93 on: February 08, 2007, 11:11:43 AM »
@lou_dias
Well I didn't give her the idea to use C but I'm sure that Mel has good reason :-) Indeed it matches my own viewpoint that C is a good starting language though.

The trouble with learning in some languages are that they force you to think in a certain manor. That's partly because it is the only way that language can do something. C has this to some degree as well (it is still a language and so that's unavoidable) but if you want to go down a particular route it'll pretty much let you and assume that you know what you're doing. I think that's a good thing because it means you have to plan, or at least think, about what it is that you're trying to do.

Going from a relatively unstructured language like C that lets you do some incredibly stupid things and just assumes that you know what you're doing, to another language that is more restrictive can be very frustrating because of the feeling that you're being locked into it's way of working. Conversely however, going from a more restrictive language to C can not only be daunting because of that freedom, it can also be unproductive because you won't know how it can be used and you'll end up using in the manor of the more restrictive language you came from.

This is not to say that C is the greatest language ever or anything. It has pitfalls and problems. I think most of my bad habits came from years of hacking in C before I learnt C++, but it's a very widely used base. The knowledge that Mel gains from learning C will be transferable to almost any other mainstream (where mainstream means a language you're likely to encounter in business) language Higher or Lower level and to any platform which is something that cannot be said for anything else, even C++ compilers aren't available on/for absolutely everything.

It looks like the place the Mel works at uses C++ so getting a grounding C first then moving onto C++ before you can develop some nasty habits might be my only real advice from all this btw :-D

Damn I'm at work not meant to be replying on here!

Andy
Be Positive towards the Amiga community!
 

Offline CannonFodder

  • Hero Member
  • *****
  • Join Date: Sep 2003
  • Posts: 1115
    • Show only replies by CannonFodder
Re: Learning C with the Amiga
« Reply #94 on: February 08, 2007, 11:19:21 AM »
Quote
The knowledge that Mel gains from learning C will be transferable to almost any other mainstream (where mainstream means a language you're likely to encounter in business)


That´s not strictly true in every case, but is a decent enough generalization. ;-)
People are hostile to what they do not understand - Imam Ali ibn Abi Talib(AS)
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Learning C with the Amiga
« Reply #95 on: February 08, 2007, 11:26:35 AM »
Quote

CannonFodder wrote:

C++ is the Shia to Islam´s C? ;-)


/me runs very very fast!!


No. C++ was the final revelation that perfected the language. C itself is more like your Torah/Gospel :-P

/surreal
int p; // A
 

Offline CannonFodder

  • Hero Member
  • *****
  • Join Date: Sep 2003
  • Posts: 1115
    • Show only replies by CannonFodder
Re: Learning C with the Amiga
« Reply #96 on: February 08, 2007, 11:29:36 AM »
Quote

Karlos wrote:
Quote

CannonFodder wrote:

C++ is the Shia to Islam´s C? ;-)


/me runs very very fast!!


No. C++ was the final revelation that perfected the language. C itself is more like your Torah/Gospel :-P

/surreal


Touche!

So Objective-C is more the Shia then?  Or would that be AmigaE? ;-)
People are hostile to what they do not understand - Imam Ali ibn Abi Talib(AS)
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Learning C with the Amiga
« Reply #97 on: February 08, 2007, 11:39:08 AM »
Quote
I've heard people describe C as a better assembler, but that doesn't make it a poor language to learn.


Quite the opposite. This is why it is an excellent language to learn as you gain true insight into the low level behaviour of the machine that higher level abstractions deny you.

I've never met a skilled C/C++ developer yet that writes inefficient or sloppy code regardless of the language they are using. In my experience, the same cannot be said for those that come purely from higher level language backgrounds.

Languages that require you as the developer to take ownership of efficiency and resource management tend to be the best to learn. Languages that take over resource management are good once you understand how said management works.

I regularly see things like this in java code:

Code: [Select]

while (isNotDone()) {
  Something blah = new Something();
  // ...
  blah.doSomeOperationThatDoesntAlterObjectItself();
  // ...
}


in places where

Code: [Select]

Something blah = new Something();
while (isNotDone()) {
  // ...
  blah.doSomeOperationThatDoesntAlterObjectItself();
  // ...
}


would perform the exactly the same job. The developer is utterly oblivious to the cost of repeatedly constructing an object that gets used in a non-destructive way once. Instead, all they know is "best to keep variables as local as possible" because they have not learned anything about resource management since they have never used a language where they are required to manage resources themselves.

From a high level, their code is well structured, very OOP, properly implementing known patterns where they apply but the physical implementation of their code is full of inefficient resource clobbering examples like those above.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Learning C with the Amiga
« Reply #98 on: February 08, 2007, 11:41:32 AM »
Objective-C is more like Sikhism, where two syntactically unrelated languages were merged to create a new one...
int p; // A
 

Offline Louis Dias

Re: Learning C with the Amiga
« Reply #99 on: February 08, 2007, 12:06:00 PM »
Quote

Karlos wrote:
Quote

CannonFodder wrote:

C++ is the Shia to Islam´s C? ;-)


/me runs very very fast!!


No. C++ was the final revelation that perfected the language. C itself is more like your Torah/Gospel :-P

/surreal


That's funny, I learned JAVA for a class and I would say that JAVA is the final revelation that perfected C++.

@koaftdr
JAVA offers data serialization built-in.

PS,
We are way off topic for Mel.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Learning C with the Amiga
« Reply #100 on: February 08, 2007, 12:52:38 PM »
Quote
I would say that JAVA is the final revelation that perfected C++.


Complete and utter bilge. Some java shortcomings from the POV of a C++ developer:

Efficient concrete types cannot be realistically implemented as all calls are virtual, all objects are polymorphic.

Inheritence is singular and public level only.

No real control over object destruction.

No operator overloading. Except for the inbuilt StringBuffer which has an implementation of "+", thus destroying their own argument against allowing it.

I used to say "full support for generic programming (templates)" but Java has added generics, which use something very similar to C++ template syntax. Which they used to criticise very heavily ;-)
int p; // A
 

Offline AJCopland

Re: Learning C with the Amiga
« Reply #101 on: February 08, 2007, 02:01:45 PM »
@Karlos
AArgh, yes I saw something just like this the other day in a render loop of all places :crazy: I was helping out a friend who's at Uni' with her group project trying to figure out why it ran so slow. The other problem is that because they're so used to Java they expect everything to be garbage collected auto-magically and were leaking almost a megabyte a frame!

That's not a comment against Java which is fine in my book, but does quite nicely demonstrate what I meant about going from a higher level language which has taught you one thing to a lower level language which doesn't support it :-D

Andy
Be Positive towards the Amiga community!
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Learning C with the Amiga
« Reply #102 on: February 08, 2007, 05:49:23 PM »
lou_dias:

"We are way off topic for Mel."

Yes, it seemed to start with talk of ".net" :-P

"Here we have a new student to programming and you give her the loaded gun right away. That can/will lead to frustration. Bad descision. What is her "need" to learn C? Certainly, other languages could speed up her "learning to program" process. Learning these other languages could then speed up her subsequent "Learning To Program In C" process."

So far the only frustration is the language-war sideshow ;-) Im not finding C itself particularly difficult to comprehend for now. Why should I learn something else in order to qualify for learning C?

I dont mind the C++ chatter though I dont plan on looking into that for some time yet.
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Learning C with the Amiga
« Reply #103 on: February 08, 2007, 08:42:40 PM »
lou_dias:

"It's these quirks that make it not a good language for beginners. Maybe if she ever learns a second language (C++ doesn't count), then she'll see the light at the end of the tunnel."

Hmmm.

You seem to think that I am lost in a dark tunnel. Im not - C seems quite straightforward so far. Whats this "light" am I supposed to C? :-P

" C is a language with few rules. How do you write structured code when the language has no uniform structure within it's design. "

It seems quite structured to me. So far I have learned:

C provides very simple "types" that correspond to those typically used by the CPU directly. Anything more complicated requires you to define a structure that is composed of these types (and maybe other structures). I can already see how this provides a good "building up" principle for dealing with data in a program.

C code is structured into blocks that you surround in braces. Any variables you define inside a block can only be seen in that block and any blocks inside it and so on.

The highest level block of code is a function. You cant just write code anywhere. Therefore (unless I got this very wrong) all code in C lives only in functions wether they are built into a library or you have written them yourself.

The first function in your program is main(). This is what the system calls when your program is run and the value returned goes back to the system as an indicator of what happened. It was quite interesting to see what happened when I returned 5, 10 and so on and checked the shell's return code - you can actually see it.

My first program that used the full "main()" definition was this:

/* set the returncode for the amiga shell */

#include
#include

int main(int argn, char** argv)
{
  int r = 0;
  if (argn>1) {
    r = atoi(argv[1]);
  }
  printf("Setting return code to %d...\n",r);
  return r;
}

Ok, it isnt exactly the most useful thing but you can actually see how the shell and program interact which I thought was educational :-)

C is not very "wordy" and relies more on an equation-like written form. Which is good as far as Im concerned as it is easier to see at a glance what a block of code does when it isnt cluttered up with lots of keywords that distract you from what the code itself is actually is saying.


"C is a language designed for low-memory machines because that's all they had when it was designed. All these "quirks" are just hacks someone added to the compiler at the time because of memory constraints and over time "became part of the language". C is a hack to not have to write assembly."

According to the K&R book C was created for and on unix systems. I dont think they were regarded as "low-memory" in their day - after all the compiler itself uses quite a lot just to compile a program!

All the "low-memory" systems (home computers typically) I can remember from childhood used BASIC of some sort or other.
I love my MX5!
Please pay a visit
 

Offline ethierbach

  • Newbie
  • *
  • Join Date: Nov 2006
  • Posts: 35
    • Show only replies by ethierbach
Re: Learning C with the Amiga
« Reply #104 from previous page: February 08, 2007, 09:41:14 PM »
Pardon me for jumping in here...

Don't mind too much about the "language wars"...but I hope you can take away one point from it all.  Once you have C and C++ well in hand, take some time to learn a completely different sort of language, one that pushes you to think in a different direction than C does.  Maybe one with strict typing like Pascal, or an interpreted one like Perl.  That will help you to separate specific language quirks from sound general programming principles.

Your take on C seems a lot like my wife's -- she regards the code as self-documenting, and considers comments to be a distraction.  I have a different view, probably colored by my experience with IBM System/370 Assembler.  I'd much rather read comments, to know what the programmer meant to do, than play computer and try to execute the code in my head.

Interestingly enough, one of my lame justifications for getting an Amiga was to get more comfortable with C, as I hope to get involved with some Linux or other kernel programming.  Hacking around with Amiga programming seemed much more interesting than the many other options I have.

-Ed-