Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
using System;class ExampleClass{ static void Main() { System.Console.WriteLine("Hello, world!"); }}
#include <stdio.h>void main(){ printf("Hello, World");}
C has always been the language for pedal to the metal performance. It's one step away from assembly, yet it's also considered a high level language.C is easy to read - I would argue that it's one of the easiest languages to read, due to its limited set of keywords. I would also argue that it compiles to some of the fastest machine code out there.
Linux is written in C. The Apache web server, which dishes out most of the world's websites, is written in C. The original Unix operating system and just about all subsequent ones were/are written in C.
The compilers or interpreters of other computer languages are often written in C.
I mostly agree with you bryan922, just wanted to make it clear that C is grate for low level programming but it also stops there: it's not an effective language for other kinds of applications.
// In C:if( intersect_ray_tri( ray, tri, &t )) { ...}if( intersect_ray_sphere( ray, sphere, &t )) { ...}// In C++ without OOP:if( intersect( ray, tri, &t )) { ...}if( intersect( ray, sphere, &t )) { ...}// In C++ with OOP:if( ray->intersect( sphere, &t )) { ...}if( ray->intersect( tri, &t )) { ...}
intersect(ray,tri)
calling ray->intersect(sphere)
TGeometricEngine_Intersect(shpere,Self)
OOP languages like java are called performance languages (where previously languages like C were thought of as research style langauges).
What would be left if you ditched OOP from C++? How can you possibly implement operator overloading or function overloading without an object? What is it that you don't like about the "->" operator? Are you sure you're not confusing overloading methods with overriding methods?
Just because you ca do it with C or ASM doesn't mean you should do it!
Just for reference, does anybody know what the java virtual machine or intermediary platform is programmed in?
I have read everyone's replys and have another question. For robotics, is C fine or should I switch to C++?
True, you need to use what C++ terms an object to do function overloading, but that's a semantic issue that boils down to use of terminology. There is nothing about the conceptual components of function overloading within the realm of computer science that require one to adopt an OOP paradigm with regard to creating function overloading in a language. Function overloading, in its essence, boils down to a compiler detecting the argument types. It is C++'s choice to entangle that with OOP, which outside of C++, conceptually refers to objects which have methods and can inherit.
int func1(int x) { return x;};int func1(double x) { return 0;}
No, because you can't. You would need a C++ compiler for the processor, and they mostly don't exist.
Assuming that, like most of us, you are using the FREE avr gnu compiler -then it also copes with C++ - see my Members Tutorial
Please help me understand. By function overloading you mean something like this:Code: [Select]int func1(int x) { return x;};int func1(double x) { return 0;}... and then have the compiler choose between the two based on the type of the RVALUE you're actually passing. Well I've got good news for you, that code up there is perfectly correct C++ code that used overloading for global functions (not part of an object). It compiles without warnings and produces the expected results. When you were talking about method overloading I honestly thought you were confusing overloading with overriding as overriding is what's interesting about OOP, not overloading.
As an aside, I think C++ applications and C++ APIs would be cleaner, easier to read, easier to code in, and the code would be more terse and elegant if OOP was ditched, but leaving in operator overloading and function overloading.
I also believe you're comparing Apples to Oranges when you're comparing C++ to Lisp - Lisp is an interpreted language and that's where all the interesting sintax comes from. I know there are compilers for Lisp but apparently you loose most of what makes Lisp by writing code that's compileable (ex: You need to use type declaration for everything you use!).
There's an other issue: You apparently don't like Perl because of it's inconsistent syntactical rules but you like Lisp because you can define your own syntactical rules (by creating your own domain-specific programming language).
I've said it and I repeat it. I've got no problem with all the other programming paradigms and - in fact - I enjoy learning about new programming languages and ideas. I believe that every single one of those programming languages has it's own place. If you insist on bashing C++ do it with the right arguments! Example: C++ is annoying because it's an type-checked language that limits one's creativity for the sake of noobs (that's one of the arguments used by Ruby people)
Quote from: Webbot on January 01, 2009, 03:20:32 PMAssuming that, like most of us, you are using the FREE avr gnu compiler -then it also copes with C++ - see my Members TutorialCan you put a link to your tutorial here? I'm trying to locate it in this list but can't find it:http://www.societyofrobots.com/member_tutorials/taxonomy/term/1?sort=asc&order=AuthorThanks.
That isn't true. Lisp by definition is not interpreted, and Lisp incarnations which compile do not give up features of Lisp. In fact, by definition, Lisp contains a function called 'compile', which will compile any piece of Lisp code, assuming the Lisp implementation has implemented the function to its fullest potential.
Surprisingly, Lisp benchmarks at often only about half the speed of C, which an interpreted language could never do.
The Corman Lisp kernel is written in C/C++/x86 assembler
a sophisticated native-code compiler which is capable of powerful type inferences, and generates code competitive in speed with C compilers.
For those of you who wish to continue to 'diss' C++ then don't forget that early C++ compilers would turn the code into C (using struct contructs) and then compile the C program. So if you think C++ is rubbish then, by implication, you think C is rubbish.
In every case I can think of, intersect returns a boolean. Every single case. The 3d point (or 2d point), or ray's parameter value t, or anything else, is, in every single case I have ever seen, an additional argument pointer. Such code is always written:if( intersect( ... )) { ....}Considering I wrote my first ray tracer in 1987 (on an Amiga) and have studied 3d graphics on and off ever since, I am not unfamiliar with said territory.
Please, I have been quite clear in what I have been saying, and I have made mistakes, but not generally with regard to where my statements are being attacked.
Re-writing everything from oop 'shape1->intersects(shape2)' into 'intersects(shape1,shape2)', when there are many different shapes, is surely just replacing virtual methods with operator overloading and makes the code harder to read and debug as you end up with one monolithic lump of source code. Of course, if you insist on doing this, then you can still do it in C++ anyway if you choose to do so.
Quote from: geek1 on January 01, 2009, 07:58:49 AMI have read everyone's replys and have another question. For robotics, is C fine or should I switch to C++?If it means anything to you, Admin started with basic, moved on to C++ for more advanced features, then finally settled on C as my preferred language for microcontrollers.If I were to program for a PC I'd probably use C++ or Visual Basic. It really depends on the task - use the language best for the task at hand. All languages have their advantages and disadvantages. I prefer languages simple to use with a lot of source code and community support, I don't care for 'optimal' as all of them will work fine for my limited apps.As for which language is fastest or takes up the least memory or whatever, that's more of a compiler issue. Hypothetically a compiler, that's good enough, can turn C++ to be as efficient as assembly code when compiled. Hypothetically . . .Anyway, this is a friendly forum, try to be sensitive in your comments. Proving you're an awesome programmer should be limited to the amazing robots you upload on youtube