Jump to content
  • Announcements

    • alpenwasser

      Please Use CODE Tags   31 Jan 2016

      Welcome to the Programming and Software Design Section,

      When asking for help with programming issues, please use the code tags to enclose your code, it makes things much more easily readable for the people trying to help you, thus improving your chances of actually getting help.
        To add code tags, click the <> button on the editor toolbar, then enter your code in the code editor that appears. If you are on a mobile device, or prefer to use BBCode, you can use [code] // Your code here // It will be syntax highlighted, though not necessarily corectly. [/code] (but the code editor is more consistent and less buggy).
Br3tt96

C Programming

Recommended Posts

4 hours ago, M.Yurizaki said:

does it matter if the computer is RISC or CISC? Is Von Nuemann or Harvard? If you're speaking to Intel or ARM?

Design your software soundly first before worrying about the implementation.

There is, off course, more then your typical PC platform. You'll often find a Harvard architecture on microcontrollers simply because those platforms tend to have different memories for program and data anyway. Some form of permanent storage, such as flash, for program memory and SRAM for RAM.

 

On some of these platforms, such as Atmel AVR, this fact is not abstracted away for you by the available compilers. Reading data from program memory (a string literal, for example) requires explicitly coding program memory access, otherwise you'll be accessing the RAM address the pointer happens to hold. It's up to the programmer to keep track and access the right memory.

 

Even on your typical PC platform there are issues you'll run into with any language, simply because no matter the amount of abstraction, eventually the program has to run on a real machine:

  • Why is my multi-threaded code slower then a single threaded solution, even tough the problem is perfectly divisible and there is nothing wrong with my code ? (false sharing)
  • Why is my linked list solution slower then a simple array, even tough the array solution has to move a million elements when inserting in the middle ? And why does this behavior totally reverse on a different architecture machine ? (linked list traversal cache miss frenzy vs cacheless machine)

...and many others.

 

One could, off course, simply accept the existence of such issues, and their solutions without ever knowing the how or why, but I've found simply doing things without understanding why is not a recipe for success. Some such issues have to be considered from the initial design because not everything can be simply refactored (read: at low cost) when the behavior of the real machine clashes with the theoretical model. False sharing, for example, can require serious redesign in how the data is layed out in order to solve (and by extension, possible redesign of a large section of the class hierarchy).

 

I also find that, if you're one the ppl who have learned things the hard way, by muddling trough the assembler and/or some low level languages, it's a bit too simplistic to look back and say: "What a mistake that was, this whole ordeal would've been so much simpler if only I chose one of these new simple languages". Perhaps the fact that you climbed that mountain by hand and are now standing on the top is what gives you this clear view in the first place ?

 

I learned everything the hard way, there simply wasn't anything else back then. You had terribly slow basic or assembler on your commodore, compilers where a unaffordable commercial product. And given the choice, I'd do it all again. It's the journey that shapes you, not the result (a pile of mostly useless programs, written in order to learn, that probably could've been written much faster with one of these newer languages).

 

5 hours ago, Sebivor said:

I'm glad to see you're coming to terms with this... :)

 

I've not come to terms with anything. I simply gave up debating the matter.

Link to post
Share on other sites
Quote

I also find that, if you're one the ppl who have learned things the hard way, by muddling trough the assembler and/or some low level languages, it's a bit too simplistic to look back and say: "What a mistake that was, this whole ordeal would've been so much simpler if only I chose one of these new simple languages". Perhaps the fact that you climbed that mountain by hand and are now standing on the top is what gives you this clear view in the first place ?

I also find that, if you're one of the people who spells "people" incorrectly, you're unlikely to be able to stand on the peak of the person who's done both and can thus criticise both.

Additionally, he who reinvents his own language may reinvent all of the mistakes; perhaps children adopting this language don't get the benefit of reading the warning labels, which were never translated...

I'd just like to point out that your technology has warning labels, and they're in the manuals. You should familiarise yourself, so that you know how to correctly operate your machinery. The C programming language also has warning labels, and they're in the manuals referred to as "the C standards".

Relating this back to the initial discussion: I discourage C as a programming languages for students who haven't yet experienced another form of procedural programming, as the only tried and tested ways to learn C which exist today seem to assume this minimum entry level of knowledge. That alone should suffice to say, but there are always going to be people who argue that their home-grown or tutorial extremely outdated book taught them, as though their interpretation of the world restricted by the experiences they've lived is absolute. I've seen plenty of those, but none have taught C.

Moving on, why would I recommend JS or Python instead of Scheme or C?

  • Both JS and Python are procedural enough that they'll learn core requirements for C later on.
  • Neither JS nor Python have undefined behaviour.
Quote

Why is my multi-threaded code slower then a single threaded solution, even tough the problem is perfectly divisible and there is nothing wrong with my code ? (false sharing)

Alternatively, why is your multithreaded code slower than a single-threaded solution on your system but faster on someone elses system?


I don't know... what does your profiler say [on both computers]?

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.


×