C, and data structures, and.. stuff

Page 3 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

lordex

Member
Feb 7, 2002
133
0
0
Originally posted by: BingBongWongFooey
I think the issue is not specific to C and C++, but programming in general; "should I learn low-level stuff first, or high-level stuff first?" I honestly don't think it makes a *huge* difference, it probably is much more dependant on the individual.
...

IMHO, the "technical level" of a language is a completely different thing from its "level on the learning curve". C is a great language, there is no doubt about that, but I would start learning programming with some language that enforces more displines.
 

ProviaFan

Lifer
Mar 17, 2001
14,993
1
0
Originally posted by: lordex
C is a great language, there is no doubt about that, but I would start learning programming with some language that enforces more displines.
Such as...?

Well, I started with BASICA, went to QuickBASIC, then Visual Basic, since my options were limited (both by money and by hardware - or lack thereof). Now, I'm learning C++, which I thought was somewhat Object Oriented (though definitely not totally so), because I thought it would be a good and useful language to learn.

Certainly you won't suggest Java, will you? Because I'm sorry, but I want to learn a language that is used in the real world to solve real world problems that might face the "average person" (yes, I know Java is used for some server-side stuff, but that's not what I'm interested in). If you have suggestions that are more practical, I'd be open to hear them. :)
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: jliechty
Originally posted by: lordex
C is a great language, there is no doubt about that, but I would start learning programming with some language that enforces more displines.
Such as...?

Well, I started with BASICA, went to QuickBASIC, then Visual Basic, since my options were limited (both by money and by hardware - or lack thereof). Now, I'm learning C++, which I thought was somewhat Object Oriented (though definitely not totally so), because I thought it would be a good and useful language to learn.

Certainly you won't suggest Java, will you? Because I'm sorry, but I want to learn a language that is used in the real world to solve real world problems that might face the "average person" (yes, I know Java is used for some server-side stuff, but that's not what I'm interested in). If you have suggestions that are more practical, I'd be open to hear them. :)

Python :D
 

lordex

Member
Feb 7, 2002
133
0
0
Originally posted by: jliechty
Such as...?

Well, I started with BASICA, went to QuickBASIC, then Visual Basic, since my options were limited (both by money and by hardware - or lack thereof). Now, I'm learning C++, which I thought was somewhat Object Oriented (though definitely not totally so), because I thought it would be a good and useful language to learn.

Certainly you won't suggest Java, will you? Because I'm sorry, but I want to learn a language that is used in the real world to solve real world problems that might face the "average person" (yes, I know Java is used for some server-side stuff, but that's not what I'm interested in). If you have suggestions that are more practical, I'd be open to hear them. :)

When I was writing down "some language that enforces more displines", I did have exactly Java in my mind. :) Here again is the issue that the best language to start learning programming isn't necessarily the best one in reality, but such one does do a better jon in helping a beginner gain the necessary concepts, displines, and patterns. C isn't a good start point, because it's got a lot of pitfalls for beginners - one well-known example, can you quickly tell me what "i=1,(++i)+(i++)" evaluates to? Visual Basic isn't, either, because you don't see the "whole thing".

On a side note, Java *is* "a language that is used in the real world to solve real world problems that might face the 'average person'". As you have realized, it's being widely used on the server side, and on desktop it's also starting to gain popularity because of its portability and much more improved performance.
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Originally posted by: lordex
Originally posted by: Mucman
Yes O(1) is similar to O(c). By saying O(1) though you are saying that you gaurantee every hash table lookup will involve 1 comparison and you are
done. This is usually not practical because of memory limitations, and doesn't address possible collisions.

Just double checked my analysis book, :) Seems you can prove by definition that O(1) equals O(c), where c is a constant. I think there isn't a theoretical term to differentiate a strict no-miss hash from a may-have-a-couple-retries one. There probably isn't any practical reason for us to differentiate them, either, since the performance difference is trivial.

ok, I don't think I explained myself properly though. Yes O(1) is O(c). O(1) implies absolute unique hashing and no collisions. If you made a table with
one bucket, and you insert n elements into that table, you will have O(n) selection. So I believe what I am trying to spew here is what is the O(1) of tables
in python refering to? Best case, worst case, or average case? O(1) defintely seems to be the best case, while I would believe that the average case is
O(1 + c) where c = (percentage of overflows x average overflow length). I would bring out my algorithms book, but it's too darn heavy to lift :p

 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Oh, and I find Java a great language to work with. It is used for internal tool use in many companies.
 

ProviaFan

Lifer
Mar 17, 2001
14,993
1
0
Originally posted by: lordex
When I was writing down "some language that enforces more displines", I did have exactly Java in my mind. :) Here again is the issue that the best language to start learning programming isn't necessarily the best one in reality, but such one does do a better jon in helping a beginner gain the necessary concepts, displines, and patterns.
I could see that... Perhaps I shall try Java after I finish learning C++. :)

BTW, I picked up "Core JAVA 1.1" (Volumes I and II) for US$0.50 at a used book sale at a local library. I'm sure the volumes are slightly dated, but I'd like to know if I could learn anything (even just the basics) with them. Or, will I need to spend more $$$ on a new, up-to-date book when I'm ready to begin that project?
C isn't a good start point, because it's got a lot of pitfalls for beginners - one well-known example, can you quickly tell me what "i=1,(++i)+(i++)" evaluates to? Visual Basic isn't, either, because you don't see the "whole thing".
I'm learning C++ - not C - but I'm not sure if that makes much difference in relation to what you are saying here.

Oh, and I'm still a n00b to C++, so I haven't studied the , yet, but wouldn't "(++i)+(i++)", given i = 1, produce 4, with i being 3 after the expression evaluates? How the comma relates to that, and what i finally ends up being, I'm not sure. Heck, I'm not even sure of what I just said. :eek:
On a side note, Java *is* "a language that is used in the real world to solve real world problems that might face the 'average person'". As you have realized, it's being widely used on the server side, and on desktop it's also starting to gain popularity because of its portability and much more improved performance.
I still wouldn't write the next open-source Photoshop killer in it, but I guess it would be fine for less demanding situations. In my experience, application startup time still seems to be a very big issue, but I suppose if I was just wanting to write a small to medium sized application that needed to be very cross-platform compatible and didn't need any low-level access to anything, Java would be fine. Hey, I guess you've got me convinced. I'm still going to finish what I've started, but barring an unforseen change of plans, Java shall come next after C++. :)
 

randumb

Platinum Member
Mar 27, 2003
2,324
0
0
Originally posted by: jliechty
Originally posted by: lordex
When I was writing down "some language that enforces more displines", I did have exactly Java in my mind. :) Here again is the issue that the best language to start learning programming isn't necessarily the best one in reality, but such one does do a better jon in helping a beginner gain the necessary concepts, displines, and patterns.
I could see that... Perhaps I shall try Java after I finish learning C++. :)

BTW, I picked up "Core JAVA 1.1" (Volumes I and II) for US$0.50 at a used book sale at a local library. I'm sure the volumes are slightly dated, but I'd like to know if I could learn anything (even just the basics) with them. Or, will I need to spend more $$$ on a new, up-to-date book when I'm ready to begin that project?
C isn't a good start point, because it's got a lot of pitfalls for beginners - one well-known example, can you quickly tell me what "i=1,(++i)+(i++)" evaluates to? Visual Basic isn't, either, because you don't see the "whole thing".
I'm learning C++ - not C - but I'm not sure if that makes much difference in relation to what you are saying here.

Oh, and I'm still a n00b to C++, so I haven't studied the , yet, but wouldn't "(++i)+(i++)", given i = 1, produce 4, with i being 3 after the expression evaluates? How the comma relates to that, and what i finally ends up being, I'm not sure. Heck, I'm not even sure of what I just said. :eek:
On a side note, Java *is* "a language that is used in the real world to solve real world problems that might face the 'average person'". As you have realized, it's being widely used on the server side, and on desktop it's also starting to gain popularity because of its portability and much more improved performance.
I still wouldn't write the next open-source Photoshop killer in it, but I guess it would be fine for less demanding situations. In my experience, application startup time still seems to be a very big issue, but I suppose if I was just wanting to write a small to medium sized application that needed to be very cross-platform compatible and didn't need any low-level access to anything, Java would be fine. Hey, I guess you've got me convinced. I'm still going to finish what I've started, but barring an unforseen change of plans, Java shall come next after C++. :)

I would look at C, because it's very closely related to C++. You'll understand C++ better if you read about C first.

Trying Java after 5+ years of C++ was weird for me. I had a lot of trouble adjusting to Java, and was annoyed with the different programming approach and limited capabilities.
 

randumb

Platinum Member
Mar 27, 2003
2,324
0
0
On a side note, Java *is* "a language that is used in the real world to solve real world problems that might face the 'average person'". As you have realized, it's being widely used on the server side, and on desktop it's also starting to gain popularity because of its portability and much more improved performance.

I doubt Java will ever become a good application language. It is much weaker than C++ as an application language - it's slow, doesn't support pointers, operator overloading, or templates, and although it is portable, debugging it on different operating systems can be a pain the ass.

 

Extrarius

Senior member
Jul 8, 2001
259
0
0
Originally posted by: randumb
On a side note, Java *is* "a language that is used in the real world to solve real world problems that might face the 'average person'". As you have realized, it's being widely used on the server side, and on desktop it's also starting to gain popularity because of its portability and much more improved performance.

I doubt Java will ever become a good application language. It is much weaker than C++ as an application language - it's slow, doesn't support pointers, operator overloading, or templates, and although it is portable, debugging it on different operating systems can be a pain the ass.
The US military uses java for some applications (I worked an internship for a company that contracts with them and one of the projects of the other interns was to do some work on a java program they had). I, personally, don't like the language, but it does get used.

Pretty much every language is used in the 'real world', even languages that everybody thinks are entirely academic such as Lisp.
 

lordex

Member
Feb 7, 2002
133
0
0
Originally posted by: Mucman
ok, I don't think I explained myself properly though. Yes O(1) is O(c). O(1) implies absolute unique hashing and no collisions. If you made a table with
one bucket, and you insert n elements into that table, you will have O(n) selection. So I believe what I am trying to spew here is what is the O(1) of tables
in python refering to? Best case, worst case, or average case? O(1) defintely seems to be the best case, while I would believe that the average case is
O(1 + c) where c = (percentage of overflows x average overflow length). I would bring out my algorithms book, but it's too darn heavy to lift :p

I know I'm getting a bit pedantic here, :) but anyway, my point is that it is not mathematically correct to use O(1) and O(c) to differentiate the performance of any algorithms/data structures, because O(1) does not imply anything more or less than O(c) whatsoever, and vice versa. I absolutely agree with your opinion on the collision/overflow characteristics of hash tables, but I'm pretty sure you cannot find in any algorithm book they are described using O(1) and O(c).

The best scenario of a hash table is O(1) (which again does not necessarily imply exactly 1 hashing), and the worst O(n). As matter of fact, there isn't a single one hash table in real life can guarantee exact 1 hashing, but the statement above still holds true, exactly because O(1) includes those scenarios where a constant number of hashings are allowed.
 

lordex

Member
Feb 7, 2002
133
0
0
Originally posted by: jliechty
BTW, I picked up "Core JAVA 1.1" (Volumes I and II) for US$0.50 at a used book sale at a local library. I'm sure the volumes are slightly dated, but I'd like to know if I could learn anything (even just the basics) with them. Or, will I need to spend more $$$ on a new, up-to-date book when I'm ready to begin that project?
Java 1.1 is *very* outdated, I would say. Consider it Sun's "pilot" to the real Java, i.e., Java 2. :)

Oh, and I'm still a n00b to C++, so I haven't studied the , yet, but wouldn't "(++i)+(i++)", given i = 1, produce 4, with i being 3 after the expression evaluates? How the comma relates to that, and what i finally ends up being, I'm not sure. Heck, I'm not even sure of what I just said. :eek:

Actually, the evaluation of that expression is compiler dependent, because C(nor C++ for this case) doesn't have a clear definition on the expression order - one compiler might decide to follow the textual order, another one might optimize to do ++i and i++ together, etc.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: randumb
On a side note, Java *is* "a language that is used in the real world to solve real world problems that might face the 'average person'". As you have realized, it's being widely used on the server side, and on desktop it's also starting to gain popularity because of its portability and much more improved performance.

I doubt Java will ever become a good application language. It is much weaker than C++ as an application language - it's slow, doesn't support pointers, operator overloading, or templates, and although it is portable, debugging it on different operating systems can be a pain the ass.

The perception of "slow" is relative; many times shaving CPU cycles has a far less ROI than saving programmer time. Also, generic (templates) will be available in Java 1.5 "Tiger".
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Originally posted by: lordex
Originally posted by: Mucman
ok, I don't think I explained myself properly though. Yes O(1) is O(c). O(1) implies absolute unique hashing and no collisions. If you made a table with
one bucket, and you insert n elements into that table, you will have O(n) selection. So I believe what I am trying to spew here is what is the O(1) of tables
in python refering to? Best case, worst case, or average case? O(1) defintely seems to be the best case, while I would believe that the average case is
O(1 + c) where c = (percentage of overflows x average overflow length). I would bring out my algorithms book, but it's too darn heavy to lift :p

I know I'm getting a bit pedantic here, :) but anyway, my point is that it is not mathematically correct to use O(1) and O(c) to differentiate the performance of any algorithms/data structures, because O(1) does not imply anything more or less than O(c) whatsoever, and vice versa. I absolutely agree with your opinion on the collision/overflow characteristics of hash tables, but I'm pretty sure you cannot find in any algorithm book they are described using O(1) and O(c).

The best scenario of a hash table is O(1) (which again does not necessarily imply exactly 1 hashing), and the worst O(n). As matter of fact, there isn't a single one hash table in real life can guarantee exact 1 hashing, but the statement above still holds true, exactly because O(1) includes those scenarios where a constant number of hashings are allowed.

ok, I understand what you are saying now :)