Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Which language?
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
This topic is locked: you cannot edit posts or make replies.    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Emilo
n00b
n00b


Joined: 10 Jul 2002
Posts: 7

PostPosted: Wed Jul 10, 2002 5:32 pm    Post subject: Which language? Reply with quote

Im going to learn my self some programming. So Im curios what languages you programmers think are the best.
Important to me is first how easy the language are to learn, secondly the possibility to make fast and powerfull programs. And third which are common in opensource community.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Wed Jul 10, 2002 5:39 pm    Post subject: Reply with quote

"Which language is best?" is a bad question. I am a developer by day (sysadmin by night ;)) and I find it best to have a wide arsenal of tools at my disposal. Some tasks need the speed and power of C, some tasks work fine in Perl, and some tasks are better suited to a shell script. And yes, there are actually instances where Java can be useful. Gasp! :D (No, the desktop isn't one of them.)

That aside, as any good programmer will tell you, there is no one best language. Each language has its strengths and weaknesses, thus, the answer depends on what you want to do.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Wed Jul 10, 2002 5:41 pm    Post subject: Reply with quote

Oh, if you want a starting place, I would recommend Perl. You can do pretty much anything you can in C with Perl, and Perl has influences from a huge variety of languages (and has influenced a huge variety of languages). And, it has its fair share of nuances. :roll:
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
AnimalMachine
Tux's lil' helper
Tux's lil' helper


Joined: 27 Apr 2002
Posts: 106
Location: Milwaukee, WI USA

PostPosted: Wed Jul 10, 2002 6:31 pm    Post subject: Reply with quote

I can't remember where, but I think I recently seen something saying that a survey of projects in a RedHat distribution showed that ~60% of them were written in C. And C is surely very common - from the Linux kernel to the GTK+ GUI toolkit. It arguably offers the best performance potential without the pain of coding in assembly. But it's not easy [for most people] to learn.

If you want easy to learn, try BASH scripting, or maybe Python or Perl.

If you want to go all out and figure out what people mean when they say Object Oriented, I'd recomend Java (my current language-of-choice outside of my C++ duties at my place of employment), or C++. While Java can be slower, there are also a gigantic amount of benefits to using it.

But like delta407 said, no one language is perfect for every task; it's all about context. If you're looking to learn, I would personally suggest something simple (like BASH scripting) to see if you like programming at all. If you already know that you do, try to pick a language that helps you build good programming habbits: like Python or [if you want a substantially harder target] Java.

But this is all my opinion. I'm sure it's different from most here! :lol:
Back to top
View user's profile Send private message
Codec & Electron
n00b
n00b


Joined: 10 Jul 2002
Posts: 43
Location: Düsseldorf, Germany

PostPosted: Wed Jul 10, 2002 9:56 pm    Post subject: Suggestions ... Reply with quote

Quote:
Important to me is first how easy the language are to learn ...


You may start with Python then. Not only does this language offer a clean syntax and common semantics, but it is also very powerful (eg. portage is (mainly?) written in Python too). Alternatively I recommend C# if you do not mind to be part of a minority in open source circles. C# is nevertheless powerful and gives you a nice library. Of course you should go with Mono rather than with Microsoft :wink:

Quote:
... secondly the possibility to make fast and powerfull programs

Most language implementations generate fast executables and as long as you are not going to write device drivers you could go with nearly everything you want.
The king of speed of course is a perfectly written assembler program (most assembler programs are not perfect).
You may want to consult The Great Computer Language Shootout, but notice that it is somewhat outdated and important languages (eg. Ada) are missing.


Quote:
And third which are common in opensource community.

As far as I see things most common is still C but nevertheless I recommend you should resist it. It is evil and the source of nearly every security problems you can imagine. :wink:
Popular as well are C++ (eg. within KDE), Perl (mostly system administration), Python (general purpose), Ruby, Java, functional languages (eg. OCaml, SML, Haskell).

Finally, I would definetly start with Python -- you get a picture of nearly every paradigm (OOP, procedual, (limited) FP) and early successes. The language scales quite high and if you eventually reach the limit you can extend it easily. Pythons drawback is IMHO the lack of optional static typing (but the dynamic nature of Python pays back at the other end). There are other minor deficiencies but no real showstoppers.
By the time you have mastered Python, the Mono project will have its C# implementation ready and then you could go on with it :wink:

Kind regards,
C&E
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Thu Jul 11, 2002 12:12 am    Post subject: Re: Suggestions ... Reply with quote

Codec & Electron wrote:
As far as I see things most common is still C but nevertheless I recommend you should resist it. It is evil and the source of nearly every security problems you can imagine. :wink:


No, people that write bad C are the source of nearly every security problem you can imagine. C is small, fast, clean, efficient, and flexible -- sufficiently high-level (in most cases) yet low-level enough to give some serious performance. Don't be dissing C, as in the process of typing your message you are undoubtedly executing hundreds of millions of lines of C code both on your computer, on the forum server, and on the routers in between.

C isn't an easy language, but it's very, very capable. Resisting C is a bad idea, because it will be here for a long time, and there are many situations where C is the only option. It is certainly worth your time, if you have the patience.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
dasalvagg
Apprentice
Apprentice


Joined: 26 Jun 2002
Posts: 183
Location: NY

PostPosted: Thu Jul 11, 2002 12:53 am    Post subject: Reply with quote

i would suggest perl then java, in that order. perl is quick and easy to get a hold of and java offers features that no other languages has(i love serialization). furthermore java will show you what object oriented programming is all about. it is an amazing language that doesn't get enough credit(yes speed does suck).


little bonus java can be used cross platform and on websites, so if you write a program and want to share it with a friend on another os...not a problem.


i know i'm java biased....just my opinion.
Back to top
View user's profile Send private message
jtanner
Tux's lil' helper
Tux's lil' helper


Joined: 23 May 2002
Posts: 121
Location: Atlanta, GA

PostPosted: Thu Jul 11, 2002 3:16 am    Post subject: Reply with quote

I would also suggest starting with C. As delta said, it's small and clean which makes it easier to learn. At the same time it exposes you to some of the lower-level concepts (such as pointers) which if you learn up front makes many other languages much easier.

Start with the K&R book on a *nix system. DON'T start in MSDEV--it's overwhelming for a new programmer.

Jim
Back to top
View user's profile Send private message
abhishek
Retired Dev
Retired Dev


Joined: 28 Jun 2002
Posts: 393
Location: Los Angeles, CA

PostPosted: Thu Jul 11, 2002 3:55 am    Post subject: Reply with quote

dasalvagg wrote:
i would suggest perl then java, in that order. perl is quick and easy to get a hold of and java offers features that no other languages has(i love serialization). furthermore java will show you what object oriented programming is all about. it is an amazing language that doesn't get enough credit(yes speed does suck).


little bonus java can be used cross platform and on websites, so if you write a program and want to share it with a friend on another os...not a problem.


i know i'm java biased....just my opinion.

A lot of C is cross platform. Just a little recompilw with cygwin and ur linux app runs on windows. Tuxracer was ported to windows this way. Of coure if u write ur prog in MFC its not going to compile to linux. But it is possible to write portable C.
Back to top
View user's profile Send private message
abhishek
Retired Dev
Retired Dev


Joined: 28 Jun 2002
Posts: 393
Location: Los Angeles, CA

PostPosted: Thu Jul 11, 2002 3:56 am    Post subject: Re: Suggestions ... Reply with quote

Codec & Electron wrote:

You may start with Python then. Not only does this language offer a clean syntax and common semantics, but it is also very powerful (eg. portage is (mainly?) written in Python too). Alternatively I recommend C# if you do not mind to be part of a minority in open source circles. C# is nevertheless powerful and gives you a nice library. Of course you should go with Mono rather than with Microsoft :wink:
C&E

Maybe this is just me, but i find C# pretty similar to java.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Thu Jul 11, 2002 4:42 am    Post subject: Reply with quote

data_the_android wrote:
A lot of C is cross platform. Just a little recompilw with cygwin and ur linux app runs on windows. Tuxracer was ported to windows this way.

Actually, I'm pretty sure Tux Racer does not use Cygwin.

data_the_android wrote:
Of coure if u write ur prog in MFC its not going to compile to linux.

Not so. If you're going to suggest Cygwin, why not also suggest winelib?

data_the_android wrote:
But it is possible to write portable C.

Correct, and you don't need to use either of those libraries to do it.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
abhishek
Retired Dev
Retired Dev


Joined: 28 Jun 2002
Posts: 393
Location: Los Angeles, CA

PostPosted: Thu Jul 11, 2002 5:30 am    Post subject: Reply with quote

delta407 wrote:
data_the_android wrote:
A lot of C is cross platform. Just a little recompilw with cygwin and ur linux app runs on windows. Tuxracer was ported to windows this way.

Actually, I'm pretty sure Tux Racer does not use Cygwin.

data_the_android wrote:
Of coure if u write ur prog in MFC its not going to compile to linux.

Not so. If you're going to suggest Cygwin, why not also suggest winelib?

data_the_android wrote:
But it is possible to write portable C.

Correct, and you don't need to use either of those libraries to do it.

Atually i rake the part about tuxracer back. I seem to rember seing cygwin1.dll in there a while ago, butwhen i look I dont see i. As for winelib, never seen/used it, but if u can cross compile MFC stuff with it, cool. Frim the website it seems like it implemts the win32 api though, not MFC. I prolly missed something. As for the portable C i was refering to guis, but ur point still holds.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Thu Jul 11, 2002 5:40 am    Post subject: Reply with quote

data_the_android wrote:
As for winelib, never seen/used it, but if u can cross compile MFC stuff with it, cool. Frim the website it seems like it implemts the win32 api though, not MFC.

You didn't make it to chapter 4, did you? ;)

data_the_android wrote:
As for the portable C i was refering to guis, but ur point still holds.

There are a number of cross-platform GUI toolkits, such as wxWindows, FOX, Qt, and as these were off the top of my head there is undoubtedly a copious amount of others.
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
abhishek
Retired Dev
Retired Dev


Joined: 28 Jun 2002
Posts: 393
Location: Los Angeles, CA

PostPosted: Thu Jul 11, 2002 5:52 am    Post subject: Reply with quote

Cool. Maybe ill port some of my mfc apps over.
Back to top
View user's profile Send private message
Codec & Electron
n00b
n00b


Joined: 10 Jul 2002
Posts: 43
Location: Düsseldorf, Germany

PostPosted: Thu Jul 11, 2002 6:42 am    Post subject: Reply with quote

Quote:
Maybe this is just me, but i find C# pretty similar to java.


You are right of course, but C# is IMHO slightly better and why not go with something slightly better? :wink:
Anyway there is a nice overview about the similarities and differences betweeen the two.

Kind regards,
C&E
Back to top
View user's profile Send private message
trythil
Tux's lil' helper
Tux's lil' helper


Joined: 06 Jun 2002
Posts: 123
Location: RHIT, Terre Haute, IN, USA

PostPosted: Thu Jul 11, 2002 7:13 am    Post subject: Reply with quote

I'm surprised nobody here mentioned some of the more esoteric, but very enlightening, languages: LISP and PROLOG are two that come to mind. Neither has the market share of C, C++, or Java, but both are very important if you're planning to learn stuff in CS.

That, and PROLOG's programming style is nothing like anything you've seen before, so it's a good learning experience.

But just to start...I'd learn C++ and Java. C++ is NOT as bloated nor as slow nor as insecure nor as... [insert myth here] as people say it is. There's a good article about this in the latest CUJ, and I've got benchmarks to back it up. Besides, you learn C++, you'll know most of C. (The reverse is also true, although templates and template metaprogramming are a whole new world :) )
Back to top
View user's profile Send private message
Codec & Electron
n00b
n00b


Joined: 10 Jul 2002
Posts: 43
Location: Düsseldorf, Germany

PostPosted: Thu Jul 11, 2002 10:39 am    Post subject: Against C Reply with quote

Considering that most programs are written by humans whose capacities are limited, it should not come as a surprise that programs usually contain errors, no matter what language you used. However there are languages which are very close to the von-Neuman-machine semantics and therefore use pointers, sequential and imperative semantics, and there are languages which are close to the problem domain and therefore use abstract entities (eg. objects) or relations (eg. functions (in mathematical sense)).

In terms of the former ("low level") languages you have to think about memory allocation and deallocation, pointer dereferencing and other unimportant things (as far as concerned to the problem you try to solve). In terms of the latter ("high level") languages you focus instead on algorithms and program organization. The complicated details are handled automatically for you.

Don't be tempted to rule out high level languages just because you think it may be too easy with them and you want to be a *real* programmer. Things get complicated anyway ...


Quote:
[...] people that write bad C are the source of nearly every security problem you can imagine.

If you are not considering yourself to be the master of the universe (no insult intended) you will probably think: "Why do all these smart programmers introduce bugs in their programs? Are they stupid?" and then you don't belive that their supposed stupidity explains these mistakes. If you study recent news about buffer overflows and other security problems you will recognize that important (C-) programs are among them and very talented programmers are responsible for those errors. Well, nobody is perfect, right?
There are languages that make it easier to make mistakes and others who don't. C would never stop you -- you have to depend on the OS to kill your program. Free some memory twice and you get a crash without a warning (and this error sounds more stupid than it is).

Quote:
C isn't an easy language, but it's very, very capable.

It's not more capable than any other Turing complete language in terms of computing power. Otherwise I would claim the opposite -- C is quite incapable. Take for instance its poor type checking facilities, its lack of bounds checking, its primitive header files etc. It even compiles something like int main(){free();} even though it contains obvious errors.



Quote:
Resisting C is a bad idea, because it will be here for a long time, and there are many situations where C is the only option.

There is hardly a situation where C is the only option. Maybe you could give me one or two? C will stay as long as people like you try to convince newcomers to learn this old fashioned language even though there are better alternatives available.

For all of you who believe in low level languages such as C I'd suggest to take a closer look at Cyclone that tries to fix some of the worst flaws C has. At least -- if you're a die hard C follower -- consider the use of safe libraries and strict conventions. Read the Secure Programming for Linux and Unix HOWTO.

But above all else try to resist C as much as you can!

Kind regards,
C&E

--------------------------------------------------------------------------------
Quote:
Don't be dissing C, as in the process of typing your message you are undoubtedly executing hundreds of millions of lines of C code both on your computer, on the forum server, and on the routers in between.

It's a miracle, I know. :wink:
Back to top
View user's profile Send private message
praxim
Tux's lil' helper
Tux's lil' helper


Joined: 14 May 2002
Posts: 75
Location: State College, PA

PostPosted: Thu Jul 11, 2002 2:18 pm    Post subject: Reply with quote

I'd actually recommend starting with C, despite what others may say. I certainly wish I had done so all those years back... A properly done C manual/book/tutorial will give you a good introduction to the basic concepts of programming at a fairly low level. After that, using any other language is easy.
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Thu Jul 11, 2002 3:14 pm    Post subject: Re: Against C Reply with quote

Codec & Electron wrote:
Quote:
[...] people that write bad C are the source of nearly every security problem you can imagine.

If you are not considering yourself to be the master of the universe (no insult intended) you will probably think: "Why do all these smart programmers introduce bugs in their programs? Are they stupid?" and then you don't belive that their supposed stupidity explains these mistakes.

I have, as every other programmer has, written buggy code. But, as you stated earlier, bugs are a fact of life, regardless of the language used. With proper security (not running everything as root), programs written in C are no less secure than programs written in, say, Java.

Codec & Electron wrote:
There are languages that make it easier to make mistakes and others who don't. C would never stop you -- you have to depend on the OS to kill your program. Free some memory twice and you get a crash without a warning (and this error sounds more stupid than it is).

Of course freeing the same memory twice will cause a crash. It's handled by glibc, which doesn't do checking for that unless you explicitly tell it to. On other operating systems (*BSD, even Windows) double-free checking is on by default, so if you free() the same block twice it won't do anything bad. It is not C's fault, it is the programmer's fault.

Codec & Electron wrote:
Quote:
C isn't an easy language, but it's very, very capable.

It's not more capable than any other Turing complete language in terms of computing power.

Correct, but some languages are missing things like file I/O, sockets, multicasting, memory-mapped files, dynamic linking, etc. For real-world problems, there are languages that simply cannot do the task at hand, regardless of if they are Turing complete. (Try writing an httpd in GW-BASIC, you'll see what I mean.) And, there are some languages that simply cannot deliver the performance of C, which is a result of being able to access low-level primitives.

Codec & Electron wrote:
Take for instance its poor type checking facilities, its lack of bounds checking, its primitive header files etc.

C doesn't have poor type-checking, your compiler might. For instance, it "int a, void * b; a=*b" would generate an error, but you could say "int a; void * b; a=*(int *)b" to override the type-checking, but by doing so you take the responsibility off the compiler and into your own hands. Lack of bounds checking is only true if you use standard arrays (which is also arguably a good thing); if you prefer, you could use a C++ class to handle the array for you, which would do bounds-checking. Additionally, separating header files from implementation files is not primitive, it's intelligent. (Ask Google.)

Codec & Electron wrote:
It even compiles something like int main(){free();} even though it contains obvious errors.

gcc might, but other compilers (such as M$) won't. gcc2 is lax, try that kind of crap in gcc3 and you'll see what I mean.

Codec & Electron wrote:
There is hardly a situation where C is the only option. Maybe you could give me one or two?

Writing device drivers, for instance? This is true Windows, on Linux, on BSD, and more. (Also, I think it would be amusing to see someone write a VMM in a high-level language.) Write a BIOS in Java and I'll listen.

Codec & Electron wrote:
But above all else try to resist C as much as you can!

Why? C gives you the power and flexibility of assembler (__asm blocks, heh) with all the capabilities of higher-level languages. Want bounds checking? Write it yourself -- with C, you have an option to not check the array length every time you access a member. With C, you have an option not to allocate a length field on a string. With C, you have an option not to use the standard IP stack and talk to the network directly. C has many advantages, don't ignore that. Yes, C does have disadvantages (the danger of assembler, for instance), but it is nonetheless an excellent language. Don't avoid it because it's dangerous, old, or low-level.

Codec & Electron wrote:
Don't be tempted to rule out high level languages just because you think it may be too easy with them and you want to be a *real* programmer.

It's nice to not have to fight the language's safety features. (I don't want my garbage collected, I take it out myself. I don't want my memory zeroed, it's a needless performance hit as it's going to get overwritten in about 20 lines anyway.)
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Thu Jul 11, 2002 3:26 pm    Post subject: Reply with quote

I'm not a "real" programmer, but I do work with them extensively and have quite a bit of experience in the corporate world. So, I can offer the following insights: (for what that's worth. :))

  • Most importantly, regardless of what language you choose, focus on learning good programming style. That means writing tight, clean, fast code -- not just something that "works". This, more than anything else, will serve you well when it comes time to convince someone that they should hire you to write code for the multi-million dollar project they're responsible for. I don't care if you know C, C++, Java, C#, Python, Ruby and whatever else -- if you don't know how to write good, efficient code, you wont do as well in the corporate world. OTOH, if you can prove your coding style is clean and crisp, you'll often get hired by a company even if you don't know the particular language they're looking for. It's easy to train someone on a new language if the person already has a solid grasp of the fundamentals. To put it another way, if you're applying for a job, and can write a sample app in 50 lines when it takes everyone else 500 lines, you're going to get the job.
  • Python, Perl and other open source languages are great to start with, but almost all major companies out there use C, C++ and Java. Period. Knowing one or more of those will be important if you want to break into the corporate world. (maybe you don't -- who knows.)
  • C# -- this is mainly my opinion, but MS hasn't had good luck with gaining traction for their latest baby yet. It's very similar to Java, so most companies don't see the value or need to shift all their existing Java code over to C#. However, historically, Microsoft has thrown money at a problem (prime example: Dell.com used to be based on another language -- Cold Fusion, I believe. Bill & Co. sent a team of programmers down to Austin and rewrote dell.com using ASP, free of charge) so maybe this will change.
My $.02.

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
Codec & Electron
n00b
n00b


Joined: 10 Jul 2002
Posts: 43
Location: Düsseldorf, Germany

PostPosted: Thu Jul 11, 2002 10:00 pm    Post subject: Re: Against C Reply with quote

delta407 wrote:
For real-world problems, there are languages that simply cannot do the task at hand, regardless of if they are Turing complete.

Yes there are those crippled languages, but I'm not pointing to these. I point to languages as capable as C but less error prone (eg. Ada95, C++, SML, Cyclone etc.).

delta407 wrote:
C doesn't have poor type-checking, your compiler might.

Excuse me but C is notoriously known for its poor type checking. It accepts booleans as integers, chars and enums as integers as well. Or take those famous format string attacks through printf. Have you ever heard of similar attacks in Java? Write something like extern char *y; printf(y);. If the user of y can choose the string y she can introduce the %n format directive that causes printf to write the number of charcters printed so far into a location specified by a pointer argument and can thus be used to write an arbitrary value into a arbitrary location chosen by the attacker (compare the bugtraq id 1387).

delta407 wrote:

Codec & Electron wrote:
It even compiles something like int main(){free();} even though it contains obvious errors.

gcc might, but other compilers (such as M$) won't. gcc2 is lax, try that kind of crap in gcc3 and you'll see what I mean.

You raise another point thats bad about C. Although there exists an ISO standard, you will often here something like this. A standard is worthless if you have to depend on specific implementation features. Also note the frequent advise to use splint (fromer lclint) which means that a typical C implementation does not offer you a useful static analysis (or even useful runtime checks).

delta407 wrote:

Codec & Electron wrote:
There is hardly a situation where C is the only option. Maybe you could give me one or two?

Writing device drivers, for instance? This is true Windows, on Linux, on BSD, and more. (Also, I think it would be amusing to see someone write a VMM in a high-level language.) Write a BIOS in Java and I'll listen.

Restrictions like these are not inherent to the C language but rather to programming environments. Nothing stops you from writing a kernel in Ada (and in fact this has been done). Maybe you could even write a device driver for Linux in Ada with a small C-interface to the kernel. Anyway my point was that there is no situation were C is the only option because it lets you do something language-wise that is impossible with other languages. It is a triviality that there are always restricting factors that may force you to pick a certain tool and not the other (budget, available programmers, etc.).

delta407 wrote:
Want bounds checking? Write it yourself [...]

Joe Programmer has neither the time nor the capability to re-invent the wheel every time he tries to do something that he can take for granted in other languages. This is exactly what I tried to express -- with C you have to focus on particularities instead of your problem domain. Instead of implementing an algorithm that needs hash tables you have to sit down first and try to get your hash table implementation right.

My final words -- got to Bugtraq and study the bugs and exploits and you will see what is wrong with C.

Kind regards,
C&E
Back to top
View user's profile Send private message
abhishek
Retired Dev
Retired Dev


Joined: 28 Jun 2002
Posts: 393
Location: Los Angeles, CA

PostPosted: Thu Jul 11, 2002 10:16 pm    Post subject: Re: Against C Reply with quote

Codec & Electron wrote:

Excuse me but C is notoriously known for its poor type checking. It accepts booleans as integers, chars and enums as integers as well. Or take those famous format string attacks through printf. Have you ever heard of similar attacks in Java? Write something like extern char *y; printf(y);. If the user of y can choose the string y she can introduce the %n format directive that causes printf to write the number of charcters printed so far into a location specified by a pointer argument and can thus be used to write an arbitrary value into a arbitrary location chosen by the attacker (compare the bugtraq id

booleans are integers. the language has no type bool by default. If u have bools, u made them. And wahts wrong with that?
Back to top
View user's profile Send private message
trythil
Tux's lil' helper
Tux's lil' helper


Joined: 06 Jun 2002
Posts: 123
Location: RHIT, Terre Haute, IN, USA

PostPosted: Thu Jul 11, 2002 10:45 pm    Post subject: Reply with quote

Quote:

booleans are integers. the language has no type bool by default. If u have bools, u made them. And wahts wrong with that?


That's not the only problem with C's weak type checking, and certainly not the least severe. Take, for example:

Code:

#include <stdio.h>
#include <string.h>

int cb(char *);

int main(int argc, char **argv)
{
        cb(65);
}

int cb(char *c)
{
       printf("%c\n", c);
}




Run that and you'll get "A". That is VERY weak type-checking, and quite dangerous, as C&E pointed out. C++, and some other languages, do NOT allow this kind of implicit conversion.

"Booleans as integers" is not the real problem with weak type-checking. Stuff like what I wrote above is.

Quote:

(I don't want my garbage collected, I take it out myself. I don't want my memory zeroed, it's a needless performance hit as it's going to get overwritten in about 20 lines anyway.)


There are some designs in which manual garbage collection simply is far too complex to efficiently implement. Take, for example, a pointer that is shared among several objects. When do you decide when it is appropriate to free that data? This is the design rationale behind the C++ "smart pointers" -- std::auto_ptr<>, boost::shared_ptr<>, boost::shared_array<>, etc. (I'm sure there's something in, say, Alexandrescu's Loki library that I left out, but I've not used that library yet.)

They still have their faults, but they're a hell of a lot better than malloc()'ing and free()'ing manually.

Also, to whoever said "C is small and easy to learn" -- that's a red herring. The C99 Standard is 550 pages long. "Small and easy to learn"? Yeah, sure, if you mean learning the majority of the language. But then again, C++ is the same way. Java is the same way. You can know the majority of those languages just about as easily as C.

Very few people understand ALL of C, C++, Java, or for that matter any programming language. Thankfully, very few people need to. If you want to learn the majority of a language (which is what most people do anyway) any language works.


Last edited by trythil on Thu Jul 11, 2002 10:57 pm; edited 2 times in total
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20589

PostPosted: Thu Jul 11, 2002 10:53 pm    Post subject: Reply with quote

Codec & Electron wrote:
You are right of course, but C# is IMHO slightly better and why not go with something slightly better?
Because MS is likely going to make it a closed language with extensions that will only work on their products.
Sure they've submitted it to a standards body. Buy into that, and I've got a bridge and a statue I can sell you
for a bargain. Delivery not included.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Thu Jul 11, 2002 11:06 pm    Post subject: Reply with quote

Folks -- let's not let this turn into a language war or I'll have to lock the topic.

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies.    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum