Old 19th July 2005, 15:12   #1
k_rock923
\m/
(Forum King)
 
k_rock923's Avatar
 
Join Date: Jul 2003
Location: /bin/bash
Posts: 7,850
Send a message via AIM to k_rock923
Programming Ideas

I've been reading a few programming books, working on learning C++. Sams Teach Yourself C++ in 24 hours and Accelerated C++, practical programming by example. The last thing I covered was classes and pointers.

The thing I don't like about the sams book is that it doesn't give you exercises to try out on your own to reinforce the conceopts. I was wondering if anyone here had any that would be possible with my level of knowledge.

Another thing that I'd like a programmer to answer, if possible, is what is the point of a class? The way I see it, when you get right down to it, you're still dealing with letters and numbers anyway so why not just use local variables?

Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway.
k_rock923 is offline   Reply With Quote
Old 19th July 2005, 15:51   #2
mikm
Major Dude
 
mikm's Avatar
 
Join Date: May 2001
Location: somewhere else
Posts: 1,255
Classes are the blueprints for objects, which easily lets you manipulate data. For example, you could use a Map class to easily access data by using a certain key (like a dictionary).

In many cases, classes are portable - you can reuse them in almost any program.

If you haven't done much in C++ yet, I'd recommend trying some non object-oriented (OO) exercises to get a feel for the language before you start working with multiple classes and such.

Exercises that you could try might be
* Print out the fibbonaci sequence
* Run a simulation (with random and user-supplied factors), such as a simple gambling game.

For OO practice, you could try creating a Dictionary program.
Make a class that allows a program to add words and definitions and retrieve them. In your "main" class, write a simple test program (add a few definitions, look them up, try "breaking" the program)

powered by C₂H₅OH
mikm is offline   Reply With Quote
Old 19th July 2005, 16:35   #3
Jaak
Major Dude
 
Jaak's Avatar
 
Join Date: Jan 2003
Location: Estonia.
Posts: 851
Re: Programming Ideas

Quote:
Originally posted by k_rock923
Another thing that I'd like a programmer to answer, if possible, is what is the point of a class? The way I see it, when you get right down to it, you're still dealing with letters and numbers anyway so why not just use local variables?
Classes are to make programmers life simpler (and harder aswell ). It's perfectly possible to do oop with pure C, but it just requires lots of hacks (gobjects anyone?).
Real benefits of classes are where oop is (inheritance, polymorphism, hiding implementation etc.)

Phi = (1+sqrt(5))/2
Jaak is offline   Reply With Quote
Old 20th July 2005, 03:20   #4
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,917
Easy life :)
code:

#include <iostream>

class NUM
{
public:
NUM(); // default constructor
NUM(int); // constructor with integer param
NUM(const NUM&); // constructor with class type as param
friend NUM operator+(const NUM&, const NUM&); //
friend NUM operator-(const NUM&, const NUM&);
NUM& operator++(int); // pre-increment
NUM operator++(); // post-increment
NUM& operator--(int);
NUM operator--();
operator int() const;
NUM& operator=(const NUM&);
friend std::ostream& operator<<(std::ostream&, const NUM&);
friend std::istream& operator>>(std::istream&, NUM&);
~NUM(); // default destructor
protected:
int num; // class variable
};

inline NUM::NUM() : num(0) {}
inline NUM::NUM(int n) : num(n) {}
inline NUM::NUM(const NUM& n) : num(n.num) {}
inline NUM operator+(const NUM& a, const NUM& b)
{
return a.num+b.num;
}
inline NUM operator-(const NUM& a, const NUM& b)
{
return a.num-b.num;
}
inline NUM& NUM::operator++(int)
{
++num; return *this;
}
inline NUM NUM::operator++()
{
NUM n = *this;
++num;
return n;
}
inline NUM& NUM::operator--(int)
{
--num; return *this;
}
inline NUM NUM::operator--()
{
NUM n = *this;
--num;
return n;
}
inline NUM& NUM::operator=(const NUM& a)
{
num = a.num;
return *this;
}
inline NUM::operator int() const
{
return num;
}
inline std::ostream& operator<<(std::ostream& o, const NUM& a)
{
o << a.num;
return o;
}
inline std::istream& operator>>(std::istream& i, NUM& a)
{
i >> a.num;
return i;
}
inline NUM::~NUM()
{
num = 0;
}
int main()
{
using namespace std;
NUM a,b,c;
b = 1;
c = 2;
cout << a << ", " << b << ", " << c << endl;
a = b+c;
cout << a << endl;
cout << "Give me another value for b: "; cin >> b;
a = b+c;
cout << a << endl;
system("pause"); // not portable
return 0;
}




* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with MATE.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with MATE.
Joel is offline   Reply With Quote
Old 20th July 2005, 05:07   #5
k_rock923
\m/
(Forum King)
 
k_rock923's Avatar
 
Join Date: Jul 2003
Location: /bin/bash
Posts: 7,850
Send a message via AIM to k_rock923
Since I've been learning about classes, I have a question. . .I've tried to separate my class definition into a header file and the member functions into it's own file. however, the member functions require iostream. so, when i write a simple program for trying out my class, iostream is included in the main program file, and it is also included in the file that holds the class member functions. is there a way around this? or is this just how it is done? or is it right? I'm a bit confused. I've attached my three files if what I wrote made no sense. . . class.C is the one with the main function
Attached Files
File Type: zip program.zip (900 Bytes, 178 views)

Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway.
k_rock923 is offline   Reply With Quote
Old 20th July 2005, 07:52   #6
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
put this around youe header file

[code]
#idndef CAR
#define CAR


</stuf goes here>


#endif

then it'll only ever get included once

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Old 20th July 2005, 10:55   #7
Jaak
Major Dude
 
Jaak's Avatar
 
Join Date: Jan 2003
Location: Estonia.
Posts: 851
Quote:
Originally posted by k_rock923
Since I've been learning about classes, I have a question. . .I've tried to separate my class definition into a header file and the member functions into it's own file. however, the member functions require iostream. so, when i write a simple program for trying out my class, iostream is included in the main program file, and it is also included in the file that holds the class member functions. is there a way around this? or is this just how it is done? or is it right? I'm a bit confused. I've attached my three files if what I wrote made no sense. . . class.C is the one with the main function
You don't need to include iostream in .h file, just include iostream in .cpp file before including your own header.

Also, its no biggy to include headers twise (as in once in .h and second time .cpp file), it will get included only once, unless the author of header is really stupid.

Phi = (1+sqrt(5))/2
Jaak is offline   Reply With Quote
Old 20th July 2005, 12:56   #8
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,917
some rules...
1. Do not include *.c or *.cpp -_-
2. You include inline functions in the same header where is the class. That will help you with less files to handle.
3. Need to work more with constructor and destructor.
4. using namespace std can help you in same way ;)
5. Almost forgot... since you are using C++ and not C, try using *.cpp files :p
code:

// header file cat.h
class Cat
{
private:
int itsage;
std::string itsname;
public:
void setage(int age);
int getage();
void meow();
void setname(std::string name);
std::string getname();
Cat(); // <-- Default constructor!!!!
Cat(std::string name);
~Cat();
};

// My default constructor
inline Cat::Cat()
{
itsage = 0;
itsname = "";
}

// constructor with a param
Cat::Cat(std::string name)
{
itsname = name;
}

//setage sets the cat's age
inline void Cat::setage(int age)
{
itsage = age;
}

//returns the cat's age
inline int Cat::getage()
{
return itsage;
}

//meow has the cat meow
inline void Cat::meow()
{
std::cout << "Meow\n";
}

//setname sets the cat's name
inline void Cat::setname(std::string name)
{
itsname = name;
}

//getname returns the cat's name
inline std::string Cat::getname()
{
return itsname;
}

//destructor, we should clean all the stuff of the class
inline Cat::~Cat()
{
itsage = 0;
itsname.clear();
}


main.cpp
code:

// main.cpp
#include <iostream>
#include <string>
#include "cat.h"

int main()
{
using namespace std;
cout << "What is the cat's name? ";
string name;
cin >> name;
Cat buck(name);
cout << "How old is " << buck.getname() << "? ";
int catage;
cin >> catage;
buck.setage(catage);
buck.meow();
cout << buck.getname() << " is " << buck.getage() << " year(s) old.\n";
buck.meow();
system("pause"); // this is not portable in most C++ compilers
return 0;
}



* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with MATE.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with MATE.
Joel is offline   Reply With Quote
Old 20th July 2005, 16:42   #9
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
inlining everything is a bad idea!

When you inline the compiler doesn't make a functin call because it just places the code of that function wherever you have the function!

Don't do it unless you know why you need to do it.

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Old 20th July 2005, 16:44   #10
k_rock923
\m/
(Forum King)
 
k_rock923's Avatar
 
Join Date: Jul 2003
Location: /bin/bash
Posts: 7,850
Send a message via AIM to k_rock923
Thank you very much everyone. Can someone explain though why you would make a function inline?

Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway.
k_rock923 is offline   Reply With Quote
Old 20th July 2005, 17:18   #11
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
In cases of performance bottlenecks. Really, you don't have to worry about it unless you have to, and by have to I mean can prove that it's the problem and actually have a problem with performace.

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Old 20th July 2005, 19:21   #12
k_rock923
\m/
(Forum King)
 
k_rock923's Avatar
 
Join Date: Jul 2003
Location: /bin/bash
Posts: 7,850
Send a message via AIM to k_rock923
*sigh*. I spent all morning trying to come up with a way to validate a users input and it wasn't working all morning and it turns out the missing piece was resetting the input stream. damnit. I have a question though. One of the things i tried was having a member function of the cat class throw an exception. is it bad to have member functions throw exceptions. I ask because, well not in this simple case, but in a more complex one, i might forget that it throws the exception and not catch it anywhere.

Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway.
k_rock923 is offline   Reply With Quote
Old 21st July 2005, 07:23   #13
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
If you throw an exception I don't think you actually HAVE to catch it. so no it's not that bad. However if you have allocated memory on the heap using new() then you must remember to delete it, otherwise you have a memory leak.

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Old 21st July 2005, 12:34   #14
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
I just wanted to pipe in to say that C++ is a terrible language.

zootm is offline   Reply With Quote
Old 21st July 2005, 14:09   #15
Jaak
Major Dude
 
Jaak's Avatar
 
Join Date: Jan 2003
Location: Estonia.
Posts: 851
got something better yet same fast in mind?

Phi = (1+sqrt(5))/2
Jaak is offline   Reply With Quote
Old 21st July 2005, 15:39   #16
xzxzzx
Forum King
 
xzxzzx's Avatar
 
Join Date: Aug 2002
Posts: 7,254
Quote:
Originally posted by zootm
I just wanted to pipe in to say that C++ is a terrible language.
It's not a terrible language. It's just a very, very, very, very hard one to learn, use, or design in (correctly). Once you've got it down, though...

Freedom of speech is the basic freedom of humanity. When you've lost that, you've lost everything.
1\/\/4y 34|<$p4y 1gp4y 33714y, 0d4y 0uy4y? | Roses are #FF0000; Violets are #0000FF; chown -R ${YOU} ~/base
The DMCA. It really is that bad. : Count for your life.
xzxzzx is offline   Reply With Quote
Old 21st July 2005, 17:18   #17
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
less than 3 http://www.parashift.com/c++-faq-lite/index.html

I can't really complain about it, I do make my living from it. Plus I do happen to like it.

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Old 22nd July 2005, 09:34   #18
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
Quote:
Originally posted by xzxzzx
It's not a terrible language. It's just a very, very, very, very hard one to learn, use, or design in (correctly). Once you've got it down, though...
Hahahahaha, surely that makes it a terrible language?

I dislike it, its design has been superceded and its type system is quite shocking (as with C). It's useful-ish for system programming (although C is probably better), and other languages do the OO paradigm better. I'd be very skeptical of any choice to start a new project in C++, it's theoretically useful for some things but in many (most?) applications it's just not a good choice.

zootm is offline   Reply With Quote
Old 22nd July 2005, 14:44   #19
xzxzzx
Forum King
 
xzxzzx's Avatar
 
Join Date: Aug 2002
Posts: 7,254
Quote:
Originally posted by zootm
Hahahahaha, surely that makes it a terrible language?
That was kind of the point, though I probably should've included a <0.5 wink> to make it clear.

Quote:
Originally posted by zootm
I dislike it, its design has been superceded and its type system is quite shocking (as with C). It's useful-ish for system programming (although C is probably better), and other languages do the OO paradigm better. I'd be very skeptical of any choice to start a new project in C++, it's theoretically useful for some things but in many (most?) applications it's just not a good choice.
I actually don't think C++ is a terrible language, it's just a low level one. The thing about C++ is that it's really more like a "build-your-own" programming language than it is a language in and of itself. I can't imagine game coding without C++, but at the same time, I can't imagine building a game soley in C++, either.

C++ is as fast as, and often faster than, C, not because the language is inherantly faster, but because it's easier to make a fast design in C++.

At this point in computational history (as it has yet to be written), it's an advantage to realize that languages do have significantly different levels of "power". If I had the time, I'd be learning Lisp right now (you should see an experianced Lisp hacker in action), but I'm settling for Python because it has a significantly lower learning curve from most other langauges, and there are a lot of similarities between Lisp and Python.

Freedom of speech is the basic freedom of humanity. When you've lost that, you've lost everything.
1\/\/4y 34|<$p4y 1gp4y 33714y, 0d4y 0uy4y? | Roses are #FF0000; Violets are #0000FF; chown -R ${YOU} ~/base
The DMCA. It really is that bad. : Count for your life.
xzxzzx is offline   Reply With Quote
Old 22nd July 2005, 17:04   #20
k_rock923
\m/
(Forum King)
 
k_rock923's Avatar
 
Join Date: Jul 2003
Location: /bin/bash
Posts: 7,850
Send a message via AIM to k_rock923
zootm, stop making me feel like I'm wasting my time learning C++

Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway.
k_rock923 is offline   Reply With Quote
Old 22nd July 2005, 17:16   #21
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
Maybe you are . Nah, you'll probably learn a lot. Just be careful -- C++ makes it incredibly easy to be hackish and do things in "bad" ways.

Quote:
Originally posted by xzxzzx
At this point in computational history (as it has yet to be written), it's an advantage to realize that languages do have significantly different levels of "power". If I had the time, I'd be learning Lisp right now (you should see an experianced Lisp hacker in action), but I'm settling for Python because it has a significantly lower learning curve from most other langauges, and there are a lot of similarities between Lisp and Python.
Lisp is almost-functional, is it not? There's a lot of similarities between Python and many other languages simply because it's multi-paradigm. I personally love it, but the indented codeblocks aren't for everyone!

Now, C++ is fast, we know this. But C is faster (RAD is not the same as execution speed, and lumping both into "fast" is not really an option). Most places where people use C++ right now, speed is not important. Desktop applications in general are a good example. Games, yes. I can see it there. I'd still prefer having a C/C++ backend with a higher-level language on top though. Less to test. I'm sure I read that the new Civilisation (or something similar) game will be scriptable through Python, which would be amazing (not really a very good example of a game which requires blistering speed, but still).

Using C/C++ where not warranted can bring you memory leaks, security problems, buffer overruns... all of these fun, difficult-to-detect and predict, things and more. In more modern languages, although you lose "low level control", you'll develop quicker and it's not even possible to make many of the common mistakes in C and C++. "Coding standards", even assuming you follow them (which you won't, completely), can only help so far.

zootm is offline   Reply With Quote
Old 22nd July 2005, 17:46   #22
mikm
Major Dude
 
mikm's Avatar
 
Join Date: May 2001
Location: somewhere else
Posts: 1,255
How not to program in C/C++

powered by C₂H₅OH
mikm is offline   Reply With Quote
Old 22nd July 2005, 19:41   #23
xzxzzx
Forum King
 
xzxzzx's Avatar
 
Join Date: Aug 2002
Posts: 7,254
Quote:
Originally posted by zootm
Lisp is almost-functional, is it not? There's a lot of similarities between Python and many other languages simply because it's multi-paradigm. I personally love it, but the indented codeblocks aren't for everyone!

Now, C++ is fast, we know this. But C is faster (RAD is not the same as execution speed, and lumping both into "fast" is not really an option). Most places where people use C++ right now, speed is not important. Desktop applications in general are a good example. Games, yes. I can see it there. I'd still prefer having a C/C++ backend with a higher-level language on top though. Less to test. I'm sure I read that the new Civilisation (or something similar) game will be scriptable through Python, which would be amazing (not really a very good example of a game which requires blistering speed, but still).
I don't think C is really inherantly any faster than C++, other than how it compiles with today's compilers. But a language is its compilers, isn't it?

Anyway, I really can't see how indentioned codeblocks could be a dealbreaker...

I do love Python, though, particularly its Lispish features.

How I long for map()/filter()/[::] in Foxpro...

code:
# Python:
def IndentLines(text, indent = 1):
return u"".join(map(lambda line: (u"\t" * indent) + line, text.splitlines(True)))

vs.

* Foxpro:
Function IndentLines(text, indent)
If Vartype(indent) != "N"
indent = 1
Endif
Local retVal, Lines[1]
lineCount = Alines(lines, text)
retVal = ""
If lineCount > 0
For Each line In lines FoxObject
retVal = retVal + Replicate(Chr(9), indent) + line + Chr(13)
endfor
retVal = Left(retVal, Len(retVal) - 1)
EndIf
Return retval
EndFunc

# Even the verbose/similar Python program is so much easier to read (and write!):
def IndentLines(text, indent = 1):
retval = ""
lines = text.splitlines()
if len(lines) > 0:
for line in lines:
retval += (u"\t" * indent) + line + u"\n"
retval = retval[:-1]
return retval


Freedom of speech is the basic freedom of humanity. When you've lost that, you've lost everything.
1\/\/4y 34|<$p4y 1gp4y 33714y, 0d4y 0uy4y? | Roses are #FF0000; Violets are #0000FF; chown -R ${YOU} ~/base
The DMCA. It really is that bad. : Count for your life.
xzxzzx is offline   Reply With Quote
Old 22nd July 2005, 20:22   #24
Jaak
Major Dude
 
Jaak's Avatar
 
Join Date: Jan 2003
Location: Estonia.
Posts: 851
actually, pure C is much faster than C++, thats why very speed critical stuff (kenrel? ) are coded in C (if not assembler). Stuff that makes C++ slow are all those OOP goodies, which are VERY difficult to optimise for compilers (anyone cared to see assembler output for templates?).

Tho' the difference in speed is not that noticable, epsecially for coding gui, or even game (because games tend to wait for gfx card, not cpu. modern games already are coded in C++; doom 3, ut engines, i dunno about hl2 tho').

If you want to study a langauge to make living, study C/C++, Java or C#. Oh yeah, python is a scripting language, not a real programming language. But It is nice language to write pseudo code in... because its so simple .

Phi = (1+sqrt(5))/2
Jaak is offline   Reply With Quote
Old 25th July 2005, 16:13   #25
xzxzzx
Forum King
 
xzxzzx's Avatar
 
Join Date: Aug 2002
Posts: 7,254
Quote:
Originally posted by Jaak
actually, pure C is much faster than C++, thats why very speed critical stuff (kenrel? ) are coded in C (if not assembler). Stuff that makes C++ slow are all those OOP goodies, which are VERY difficult to optimise for compilers (anyone cared to see assembler output for templates?).
Sounds like a case of premature optimization to me.

Quote:
Originally posted by Jaak
Tho' the difference in speed is not that noticable, epsecially for coding gui, or even game (because games tend to wait for gfx card, not cpu. modern games already are coded in C++; doom 3, ut engines, i dunno about hl2 tho').


Quote:
Originally posted by Jaak
If you want to study a langauge to make living, study C/C++, Java or C#. Oh yeah, python is a scripting language, not a real programming language. But It is nice language to write pseudo code in... because its so simple .
Python's as much of a programming language as Java is. Or C#. A much better one than either of those, I might add.

Freedom of speech is the basic freedom of humanity. When you've lost that, you've lost everything.
1\/\/4y 34|<$p4y 1gp4y 33714y, 0d4y 0uy4y? | Roses are #FF0000; Violets are #0000FF; chown -R ${YOU} ~/base
The DMCA. It really is that bad. : Count for your life.
xzxzzx is offline   Reply With Quote
Old 26th July 2005, 08:41   #26
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
Python is also used quite heavily in a number of industries. C# and Java have different applications to Python though.

But yes, calling Python a "scripting language", and then dismissing it due to that, is a gross misrepresentation. There are full production webservers written in Python. It's a dynamic language -- that's not necessarily a bad thing.

Also, modern kernels (the NT kernel for example) are often written in C++, rather than C, it's better organised and not considerably slower. Linux is written in C since it's been around for so long, rather than a real efficiency concern.

C++ optimisation is also getting a lot more efficient at present, I believe that the new GCC is making great progress with this.

zootm is offline   Reply With Quote
Old 26th July 2005, 10:46   #27
Jaak
Major Dude
 
Jaak's Avatar
 
Join Date: Jan 2003
Location: Estonia.
Posts: 851
I know python isn't scripting language, it in fact is real programming language, what I don't like is its syntax. It feels like mix of perl and C, secondly I don't like python because its afully slow, slower than java infact. IMO, python is great for being "pseodo language", to quickly write idea down and later convert it to C/C++.

GCC 4.0.1 is doing great job for speeding up C++ compile times, but the optimisation framework isn't even nearly complete yet. Now gcc 4.0.x compiled C++ apps just tend to be a lot smaller, but might not be faster at all (if not slower) than gcc 3.x compiled code.


I hope this thread won't become programming language bashing fest...

Phi = (1+sqrt(5))/2
Jaak is offline   Reply With Quote
Old 26th July 2005, 13:22   #28
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
Hah, I wouldn't worry about it.

Python's extensive C utility library make most Python systems comparable to C systems in their runtime, in practice. Also, its syntax is very unlike Perl in my experience, and I much prefer it over C, but that's just me.

You need to remember that 99.99999% of programming projects don't require the speed of C(++). And programs that don't need that speed, shouldn't use it, because it comes with a huge cost in terms of correctness, typing and security.

edit:

Quote:
"In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.

"The fact is, C++ compilers are not trustworthy. They were even worse in
1992, but some fundamental facts haven't changed: 1) the whole C++ exception handling thing is fundamentally broken. It's _especially_ broken for kernels. 2) any compiler or language that likes to hide things like memory allocations behind your back just isn't a good choice for a kernel. 3) you can write object-oriented code (useful for filesystems etc) in C, _without_ the crap that is C++."
(linus torvalds)

And that's why they don't use C++ in the Linux kernel. Probably conflicts at least a little with what I wrote earlier.


Last edited by zootm; 26th July 2005 at 14:27.
zootm is offline   Reply With Quote
Old 26th July 2005, 16:30   #29
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
Well C++ is slightly less well defined, well at lest less easily understood, when it comes to the way it manages memory etc. So C is a good choice for kernal code. It's well defined which is exactly what you want. You don't want more than one possible interpretation between compilers. Besides you can do a lot of C++ things in C with structs and void*'s etc to almost emulate dynamic binding.

As I've said before if you're going to make your living writing code you should understand that language decisions are 99% political rather than technical. Each language has its use. ONE SIZE DOES NOT FIT ALL. ONE SIZE DOES NOT FIT ALL. ONE SIZE DOES NOT FIT ALL.

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Old 26th July 2005, 19:26   #30
xzxzzx
Forum King
 
xzxzzx's Avatar
 
Join Date: Aug 2002
Posts: 7,254
Quote:
Originally posted by Jaak
I know python isn't scripting language, it in fact is real programming language, what I don't like is its syntax. It feels like mix of perl and C, secondly I don't like python because its afully slow, slower than java infact. IMO, python is great for being "pseodo language", to quickly write idea down and later convert it to C/C++.
Slow? Slow for what, exactly? Exactly how fast do most programs need to be? And what parts? How fast do you need a piece of code that displays a messagebox to be?

Python isn't fast for tight inner loops, no. It would be a mistake to try and write a kernel in it. But, with few exceptions, not everything in a program needs to be fast - as a rule, everything can be pretty slow, with the exception of the very tightest inner loops (usually less than 1/10th of %1 of the code) - and it usually comes down to a question of design to fix those anyway.

Here's the thing, though: Python can easily be made to use C/C++ based modules for those few loops where speed really does count, not to mention Pysco optimzations, which often bring Python ahead of Java in terms of performance...

Freedom of speech is the basic freedom of humanity. When you've lost that, you've lost everything.
1\/\/4y 34|<$p4y 1gp4y 33714y, 0d4y 0uy4y? | Roses are #FF0000; Violets are #0000FF; chown -R ${YOU} ~/base
The DMCA. It really is that bad. : Count for your life.
xzxzzx is offline   Reply With Quote
Old 26th July 2005, 20:25   #31
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
Quote:
Originally posted by Phily Baby
As I've said before if you're going to make your living writing code you should understand that language decisions are 99% political rather than technical. Each language has its use. ONE SIZE DOES NOT FIT ALL. ONE SIZE DOES NOT FIT ALL. ONE SIZE DOES NOT FIT ALL.
That is true. But a lot of people are still trying to squeeze the square peg of C++ into any round hole they can find around, which is a real pity. The consequences are low-quality software, and that's not really a good price to be paying.

zootm is offline   Reply With Quote
Old 26th July 2005, 22:31   #32
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
If all your IP is in C++ then it's what you almost certaily going to use. There's nothing wrong with C++, you can create very good designs with it and do things you probably can't do in other languages. It is easy however to make bad ones, but I'm sure this is true of every language.

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Old 27th July 2005, 09:28   #33
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
It's quantifiably more true of C++, though. This is why people research language design.

zootm is offline   Reply With Quote
Old 27th July 2005, 09:34   #34
LawnGnome2005
Major Dude
 
LawnGnome2005's Avatar
 
Join Date: Mar 2002
Posts: 598
i know BASIC.

*hides*

I have no time for a real language.

LawnGnome2005 is offline   Reply With Quote
Old 27th July 2005, 10:30   #35
will
Nullsoft Newbie (Moderator)
 
will's Avatar
 
Join Date: Mar 2001
Location: Sheffield, England
Posts: 5,569
Quote:
Originally posted by zootm
Quote:
In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.
Wills 2nd fact for the day: Most of Symbian OS, the operating system used on many mobile phones is written in C++. It has a microkernel written in assembler, but the rest is C++. However, it should be noted that Symbian imposes some pretty strict coding standards on the C++ that is written.

DO NOT PM ME WITH TECH SUPPORT QUESTIONS
will is offline   Reply With Quote
Old 27th July 2005, 12:00   #36
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
Quote:
Originally posted by LawnGnome2005
i know BASIC.

*hides*

I have no time for a real language.
You should learn Python. It's about as easy to learn as BASIC and does Actually Useful Things.

On your stuff about Symbian, will, coding standards can help avoid common problems in unsafe languages, yeah. They're very subject to the "one broken window" problem though, and if they were checkable systematically they'd be part of the language specification. Where you need the power afforded to you by lower-level languages, though, they're a good way of admitting and planning against the fallacies of a language, though.

zootm is offline   Reply With Quote
Old 27th July 2005, 16:45   #37
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
Quote:
Originally posted by zootm
and if they were checkable systematically they'd be part of the language specification
Wrong. The philosophy of C/C++ is to be as close to the machine as possible so it's intended to allow you to do "silly" things. It doesn't claim to know best, if you know you want to do that cast then fair enough. *cough*lint*cough*.

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Old 27th July 2005, 17:29   #38
saivert
Banned
 
saivert's Avatar
 
Join Date: Jan 2001
Location: Norway
Posts: 927
I actually think Object Pascal is one of the best programming languages designed for Win32 programming. And there is also an open version of it (Free Pascal or something). Instead of the dull concept of a header file and a code file you just have one unit file with an interface section and an implementation section. This avoids much of the trouble. The only catch about using Delphi (the most popular framework using Object Pascal) is it's huge Visual Component Library (a set of components that wrap regular window controls like Editbox, listbox and so on). This imposes a big hit on filesize of EXEs and DLLs. But if you have no concerns for diskspace the speed of the programs are pretty good. But as always, you will stumble upon conflicts when trying to put Object Pascal code and C++ code together. You can't call methods in C++ classes from Pascal code altough Object Pascal supports classes it does not support C++ classes. The only way to go here is using COM programming. But Winamp don't use COM in it's plug-in architecture altough Microsoft uses COM for all of it's extensibility (Shell Extentions, Windows Media Player plug-ins and all other places you can extend Windows in some way except Control panel applets).
saivert is offline   Reply With Quote
Old 28th July 2005, 10:47   #39
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,375
Quote:
Originally posted by Phily Baby
Wrong. The philosophy of C/C++ is to be as close to the machine as possible so it's intended to allow you to do "silly" things. It doesn't claim to know best, if you know you want to do that cast then fair enough.
That was kinda my point. They can't be checked systematically because of the gung-ho approach of the language.

C is like driving a sportscar with no seatbelts -- if you know how to handle it, you'll be fine. C++ is the same but much more difficult to drive...

zootm is offline   Reply With Quote
Old 28th July 2005, 18:16   #40
fwgx
Rudolf the Red.
(Forum King)
 
fwgx's Avatar
 
Join Date: Nov 2000
Posts: 9,314
Quote:
Originally posted by Phily Baby
*cough*lint*cough*.
does syntatic sanity checks to make sure you follow some good rules. Plus I'm sure there are some free ones available too.

"We think science is interesting and if you disagree, you can fuck off."
fwgx is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Community Center > General Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump