Welcome, Guest. Please login or register.

Author Topic: Beginners 'C' programing group  (Read 13080 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Beginners 'C' programing group
« on: February 13, 2004, 12:05:38 PM »
Quote
BigBenAussie wrote:
Look, guys.. I think its great to learn C and all, but doesn't it really depend on what kind of project you want to work on? [...] However, I would imagine that creating AmigaOS apps using a standard C++ class library would be easier than a bunch of C routines with a zillion parameters.

It was about a learning to code-group. That's not the same as a creating AmigaOS apps-group, which requires much more insight into what can be done and how to do it. And aren't you slightly exxagerating the 'zillions' of parameters? I've rarely used more than 4 parameters to a function; if I need more, the function is too complex and must be split up.

Quote
C++ can actually be simpler to learn than C if one sticks to the simpler aspects. C++ can be a higher level language, and thus easier to learn, than C.
For example a C++ string object with overloaded operators makes text manipulation a zillion times easier than in C. Changing properties and running methods to manipulate a control of some kind, is, I am sure, easier to do utilising OOP than lower level C calls.

Don't forget you can abstract a helluvalot in C as well using a simple link library. Good C-code already implements a lot of the OO-methodology, with C++ offering more advanced and standardised features. Besides, do you really want to explain operator overloading and the confusing and arcane type promotion rules of C++ to a newbie? Otherwise he will blow both feet and parts of his legs away in the time it takes you to blink.

Quote
I would not expect Newbies to build class hierarchies and the like themselves but having them in existence in some sort of toolbox would shortcut development time and lower the threshold for programming in AmigaOS. Everything should be abstracted for the newbies.

Then they're better off with an interpreted scripting language such as Python or Ruby. They don't crash your machine, are very forgiving, and come with tons of 'glue' to link to toolkits, networking libraries, graphics subsystems, and so on. Even C++ looks very primitive and arcane compared to coding setups like these. It is also perfect for rapid prototyping, which can then later on be redone in C++ for speed.

Quote
Remember the whole nature of the new OS rewrite was to keep away from the metal so the rationale for writing in C or assembler and directly hitting the hardware is no longer there.

I'm afraid you got that quite wrong. There was never any need to hit the bare metal. People were just not used to program a multitasking environment and therefore made quite illegal assumptions about how the computer allocated its resources. They also thought that the OS would 'hinder' them in what they wanted done. They saw the Amiga as a C64 on steroids, not as a simple but fully functional Unix-machine. Even in the case of the Pegasos and the AmigaOne, I could hit the hardware if I wanted. Of course the OS doesn't (easily) let me, and quite frankly I have no idea what registers and stuff I need to fiddle with, but...

The rationale about the rewrite is to remove the hardware dependencies of the old AmigaOS, both in terms of the CPU as the old custom hardware. Also lots of bugs will be fixed, as well as implementation of much-needed extensions on a fundamental level, rather than tacking them onto the OS in the form of unstandardised user libraries.

Quote
I think ease of development so that new titles can be written for the platform is far more important that writing a 3d routine that runs milliseconds faster than before. WE NEED NEW SOFTWARE.

And that is very, very true.
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
 

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Beginners 'C' programing group
« Reply #1 on: February 13, 2004, 02:51:38 PM »
Quote
mikeymike wrote:
While he did get that quite wrong, so was your explanation :-). [...] Getting back to the point.  There's a reason why programmers "hit the hardware" directly.  Program performance is a damn sight better, and while Assembly programming is extremely pedantic, it is more flexible.  But you couldn't write a program to run on a modern operating system in Assembly, because the OS handles memory, cache, and hardware resources, it would tell your nasty little program that tries to circumvent it to get stuffed.

If say AmigaOS were completely written in C and then used on stock Amigas, it would be slower.  Most of the performance and responsiveness is derived from hitting the hardware directly.  OS4 is virtually a complete re-write from previous versions partly because of the architecture change, but mainly due to how the previous versions were programmed.

You are right when you say that assembly allows for unprecedented control over the computer. You sometimes have to use it, simply because the things you want done do not have a higher-language equivalent. Program performance isn't as clear-cut, however. Programming in assembly does not automatically make your code fast. You can write incredibly sloppy code in assembly if you want to (or are not careful). 15 to 20 years ago, optimisation algorithms weren't as good as they are now, and people preferred to do things directly in assembly rather than optimise the ever changing output of a C-compiler. 'Slowness' of compiler code had little to do with not being able to directly access custom chip registers or specify addresses by hand: it was almost always a case of unnecessary loop constructs and variable usage. Humans were simply better than the compiler in distinguishing 'good' from 'bad' code, and in some cases could streamline code for global performance. Compilers are still bad at this, as their view is rather localised.

The problem was that many would-be coders did not know how to properly code the Amiga, or looked upon the OS as an enemy instead of their friend. They sought illegal shortcuts mostly because of misguided ideas about 'efficiency'. I doubt that these practices would be the rationale for the rewrite of AmigaOS to version 4; people nowadays understand very well how the Amiga should be programmed and no longer resort to illegal tricks. It's the quickest way to assure that your code won't even run on today's generation of Amigas.

By the way, AmigaOS was largely written in C. Only a few core parts were done in hand-crafted assembly for efficiency. (One ill-fitting part, in BCPL, was hammered and stapled into place, ruining an otherwise elegant design in the process. That part is now completely out of AmigaOS 4.) The responsiveness was not due to the fact that the hardware was hit directly, but simply because the system had relatively lots of computing resources to begin with, while omitting memory protection.
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
 

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Beginners 'C' programing group
« Reply #2 on: February 14, 2004, 02:38:07 PM »
@Fluffy:

Erm... *that* is wrong, and *that* too. This code will segfault a Unix-machine, and crash an Amiga faster than a politician can shift positions. Indeed, pointers are tricky ;-)
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
 

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Beginners 'C' programing group
« Reply #3 on: February 16, 2004, 03:20:23 PM »
Quote
Karlos wrote:
@Cymric
Fluffy isn't wrong, he is saying when you understand pointers properly, you know *why* the code he presented is so screwed up.

Yes, and that's precisely what I had in mind when I wrote my message. I wasn't trying to point out that he had made those mistakes unknowingly, I was trying to tell him (or her) that I saw how many errors he had deliberately introduced without giving away what they were. Plus expressing my consent that it's easy to shoot yourself in the foot with pointers. Hope that clears up some confusion!
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.