Author Topic: Too dumb to get started?  (Read 17578 times)

Offline marfig

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Too dumb to get started?
« Reply #30 on: August 01, 2006, 07:17:50 pm »
I don't think you are really listening to what everyone is trying to tell you from the very beginning of this thread. And that is simply, you need to understand the language before you can hope code for windows. It is really simple as that.

Just, please, learn C++. In the console. Learn about variables, types, functions, references, pointers, the STL library, classes, templates, exceptions,....

Only when you do this, only when you have learnt the fundamentals of the language, only when you have done this in the console and feel somewhat secure you know what there is to know of C++, only then, only at this point, only here... will you be able to make any sense of Win32 books and tutorials. Only then will you realize why some choices were made concerning the order by which things are being taught to you, and only then will you actually learn anything valuable.

Quote
As my first project, to learn by doing, Ive picked the idea, I want to write a simple chatserver where clients can connect to exchange messages,

Wrong. Bad, bad choice. You will not learn anything. You will quit learning C++ if you try to do this because you will feel frustrated. You use the word simple to describe this project, but I can tell you right here and now it will not be simple. If you think this is the best way to learn C++, I'm sorry to say in 1 or two months you will be looking back at this post and wondering I was right. You will quit, my friend. Mark my words.

Concentrate instead on the language features. Concentrate on learning how to program in C++. Not on how to do things with C++.

Remember your objectives:

Right now your objective is to learn C++, not to code a chatserver.

Offline Newbie0815

  • Multiple posting newcomer
  • *
  • Posts: 59
Re: Too dumb to get started?
« Reply #31 on: August 01, 2006, 08:09:44 pm »
well, on this part i might be a bit different from everyone else
first of all, reading a book or tutorial without an actual project to realize is THAT boring for me, i never get past page 2 (or i skip through 90% of the text)

beginning with the C64 in 1985 Ive ALWAYS learned by doing, my very first program was an assembler code for C64 which was capable to copy ANY file from disk to tape
In PHP I learned the basics over night, took a complete multiplayer strategy browser game as my FIRST goal, realized the first beta within 3 months and a functional version within 6 months, containing some 4MB of php code in over 300 (object oriented) scripts and some 60MB graphics

Object oriented programming isnt new to me, one of the first things Ive done while collecting the pieces for my project was to put every piece into a new function and mess around with them until they were perfectly interacting, Ive already overloaded it with so many functions, separating even the smallest pieces of repeated code, just to understand perfectly how a functions works
I still dont like the idea of global and local variables, but I do understand the concept
I dont like the concept of define before first use, making protofunctions and other stuff neccessary, but I understand the concept
And if youve seen what Ive written above, I HAVE the client and server ready already, the only thing missing is the connection
When I say "Im stuck" there, that means no more than Ive spent 2 hours or so and havent had success yet, but you may bet, I will solve it on my own if I have to, asking around in here is just ment to be a shortcut to save me some time

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5179
Re: Too dumb to get started?
« Reply #32 on: August 01, 2006, 08:32:07 pm »
@Newbie0815

Well I agree with all the others learn first, but on the other hand you are no plain newbie ;-)

Let me ask you a few questions :
1) did you use inheritance ?

if so :
  2) is the destructor of your base class virtual ?
  3) why inheritance ?


4) hopefully no public variables ?
5) did you use RAII ?

Just a few simple questions ;-)

Cheers.

Offline Newbie0815

  • Multiple posting newcomer
  • *
  • Posts: 59
Re: Too dumb to get started?
« Reply #33 on: August 01, 2006, 11:50:19 pm »
well, I sure am a newbie, maybe not that bloody anymore, still I wouldnt dare to publish any of my products, Im by far not out of a stage of messing around with it, just to learn

now let me see whether I can pass your test

1 and 3) I ran into inheritance in a few of the tutorials, I even coded an example from one tutorial just to see how it works
So I know what it is about, I know specially in win32 applications theres a LOT of inherited stuff from the libraries, but other than that Im not using it in my current project (yet) because while learning I like to see what Im doing within every function, without I have to lookup from where it came, Im busy enough to remember (or look up) the unavoidable ones
I know it would give a faster application, but with this mini program speed is my last concern

2) More by chance I was using virtual destructors from start, by the time when I discovered the reason in a sidenote of a tutorial I was already used to it

4) should I rather use 100s of gets? From php Im so much used to have all variables available at all times throughout a complete script, I like my little notepad file aside where I write down all variables Im using
5) no, I think Ive seen something about it, something about easy cleanup, but I guess cleaning up I can do after Im done messing up

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5179
Re: Too dumb to get started?
« Reply #34 on: August 02, 2006, 12:05:10 am »
2) More by chance I was using virtual destructors from start, by the time when I discovered the reason in a sidenote of a tutorial I was already used to it

cool

4) should I rather use 100s of gets? From php Im so much used to have all variables available at all times throughout a complete script, I like my little notepad file aside where I write down all variables Im using

yes !!  Information hiding/maintenance/reusability : interfaces are the things you work with and exchange with other parts of the code
Note : a class should have not to many members, if it does this hints your class it doing to much things.

sethjackson

  • Guest
Re: Too dumb to get started?
« Reply #35 on: August 02, 2006, 12:07:36 am »
4) should I rather use 100s of gets? From php Im so much used to have all variables available at all times throughout a complete script, I like my little notepad file aside where I write down all variables Im using

yes !!  Information hiding/maintenance/reusability : interfaces are the things you work with and exchange with other parts of the code
Note : a class should have not to many members, if it does this hints your class it doing to much things.

Yes yes yes yes, and yes. :)

Offline marfig

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Too dumb to get started?
« Reply #36 on: August 02, 2006, 12:14:09 am »
So, at the light of this... I really suggest you consider learning the programming language first. Least you want to come back in a moth or two complaining you can't learn C++ from the tutorials

Offline Newbie0815

  • Multiple posting newcomer
  • *
  • Posts: 59
Re: Too dumb to get started?
« Reply #37 on: August 02, 2006, 12:22:54 am »
@killerbot
okok, Ill take that advice about private variables
so I dont get an A in your test, but did I pass?  :D

@marfig
isnt that what Im doing? with the only difference that I have a concrete project to work on, rather than dry studying the theory?

@all
and what about my actual question? how to "translate" code from other compilers? Theres not THAT much different between borland and gcc, I just think since this must be a pretty common problem for those who use prewitten libraries and classes to speed up their development, there should be an easier way than go through the code line by line

sethjackson

  • Guest
Re: Too dumb to get started?
« Reply #38 on: August 02, 2006, 12:55:08 am »
@killerbot
okok, Ill take that advice about private variables
so I dont get an A in your test, but did I pass?  :D

@marfig
isnt that what Im doing? with the only difference that I have a concrete project to work on, rather than dry studying the theory?

@all
and what about my actual question? how to "translate" code from other compilers? Theres not THAT much different between borland and gcc, I just think since this must be a pretty common problem for those who use prewitten libraries and classes to speed up their development, there should be an easier way than go through the code line by line

Well if the code you are looking at uses STL not much at all should be different. The code from other libraries may be different, but the code shouldn't be that much difference syntax wise.... Or maybe I misunderstood you.

Offline Auria

  • Almost regular
  • **
  • Posts: 152
Re: Too dumb to get started?
« Reply #39 on: August 02, 2006, 12:59:59 am »
Quote
and what about my actual question? how to "translate" code from other compilers? Theres not THAT much different between borland and gcc, I just think since this must be a pretty common problem for those who use prewitten libraries and classes to speed up their development, there should be an easier way than go through the code line by line

If you had learned the programming language before trying to do an actual project you would maybe know (!) there is no magic way to fix small errors between compilers, you need to know the language, and read the given error messages. If everyone keeps telling you to learn the language it must be for some reason :D

Also, it' s possible (and rather probable) that you didn't link against the right libraries

Offline mdelfede

  • Multiple posting newcomer
  • *
  • Posts: 84
Re: Too dumb to get started?
« Reply #40 on: August 02, 2006, 01:14:15 am »
isnt that what Im doing? with the only difference that I have a concrete project to work on, rather than dry studying the theory?
Here I agree, for me too it's easier learning doing something that makes me happy when I see it does something useful, instead of coding only small samples. But... keep in mind 2 points :
1- without the theory (which you can learn while doing your test project) you'll not go too far.
2- your result has many, many and many chances to become something horrible and impossible to mantain. so, take it as-is, something to practice on and NOT something beautiful and bug-free. You'll notice it at the end when you'll think "why have I coded it like this ?" That happens to me when I'm in a hurry to see it working; when it's done, I start correcting again and again, up to I give up and rewrite from scratch.

and what about my actual question? how to "translate" code from other compilers? Theres not THAT much different between borland and gcc, I just think since this must be a pretty common problem for those who use prewitten libraries and classes to speed up their development, there should be an easier way than go through the code line by line

As I told you, Borland has some non-standard constructs that you simply can't translate to pure C++, at least for C++Builder 6 which I know.
For example, in C++Builder you can do such a thing :

Code: [Select]
class Test
{
  private :
    int anInteger;

    void setInteger(int i) { if (i >= 0) anInteger = i ; }

  public :
    __property IntProp = {read = anInteger, write = setInteger} ;
};

Test test ;

test.IntProp = 2 ;
int j = test.IntProp ;

Even if I find it a beautiful construct (wondering why it's not included in Ansi C++....), that's NOT standard. In pure C++ you write :

Code: [Select]
class Test
{
  private :
    int anInteger;

  public :
    void setInteger(int i) { if (i >= 0) anInteger = i ; }
    int getInteger(void) { return anInteger ; }

};

Test test ;

test.setInteger(2) ;
int j = test.getInteger() ;

As you see, even with this small code sample, you must change a lot. In C++ builder the __property construct is used widely, as are other non standard constructs. When you use the IDE to make an app skeleton, it gives you code full of such nonstandard constructs. Believe me, takes LOOOONG to convert to pure ansi C++.

Ciao

Max

Offline kagerato

  • Multiple posting newcomer
  • *
  • Posts: 56
    • kagerato.net
Re: Too dumb to get started?
« Reply #41 on: August 02, 2006, 01:17:49 am »
Quote from: Der Meister
Just to be precise: C is *NOT* a functional programming language. It's an imperative (or procedural, if you like this word more) language. Functional programming languages are languages like Haskell or Lisp.

Correct.  C is sometimes mistakenly referred to as a functional language because the basic unit your imperative statements are organized into is called a function.  Many people (including myself) fail to make the proper distinction.

Semantics regarding this usually do not come into play because there are hardly any functional languages in widespread use outside the academic world.

Quote from: kidmosey
And as for the rest of your article... Well said!
Quote from: PDEE
Wow kagerato, great post. I learnt something from that. Thanks

I simply give my best -- there's no point in saying anything if you don't say something meaningful, I feel.

Quote from: Newbie0815
I got lost almost right away, mostly because there are no 2 tutorials for the same compiler, from videos at MSN how to write applications in visual C++ to plain C++ code I can use in CodeBlocks, they are not compatible, CodeBlocks allows me to import almost any format, but mixing them doesnt work

Absolutely no clue what you're trying to say.  "Formats"?  Source code is normally stored as ASCII text (or occasionally, using an ANSI codepage or UTF-8 instead).  As for C++ "dialects", read further.

Quote from: Newbie0815
Ive noticed, most of them are written in VB or VC, Ive even downloaded and installed Visual Studio Express, but for one the code is so way different from gcc, almost an entirely new language and the options are pretty much limited to what the compiler offers

The standard method of GUI programming using Visual C++ is MFC, the Microsoft Foundation Classes.  As the name suggests, they are an object-oriented wrapper around the win32 API.

That doesn't have much, if anything, to do with the kind of code and samples you appear to be dealing with.  I'm not sure where you picked up the idea that every compiler has its own C++ dialect, completely incompatible with another's.  To a very limited degree, that was true ten years ago.  It's not a matter of concern these days, as C++ has gradually become more and more standardized.

Visual Basic 6 is not in any way compatible with C or C++ code.  It's an entirely different language, one that I would recommend newcomers stay away from.

Visual Basic .NET doesn't have nearly as many glaring problems as VB6.  However, using it ties you to the .NET platform.  (C# has alternate implementations and uses.)  Since the changes made to Visual Basic for the purpose of transforming it into a .NET-compatible language have eliminated several of the original benefits of the language and platform, C# has seen much greater adoption.

By "Visual Studio Express", I believe you mean "Visual C++ Express".  Upon last examination, the entire Visual Studio suite was not available for free as a single entity.  Rather, there are separate packages for each language.

I don't recommend using Visual Studio -- it's huge and it provides little that a free IDE like CodeBlocks does not (assuming we're working with C++).  Furthermore, the Express editions are, in essence, a marketing lure for the .NET platform and other Microsoft-dominated technologies.

Quote from: Newbie0815
Thats where Im stuck now, I found just ONE tutorial that explains it short and easy at http://www.c-worker.ch/tuts/wstut_op.html (in german) but that one is written for borland and my attempts to translate it to gcc have failed so far, meaning I cant even start implementing it into my project

Maybe someone here can help me out? How to mix code written for different compilers or how to translate it?

The source for both, is direct available on the page

Client: http://www.c-worker.ch/tuts/sock.c
Server: http://www.c-worker.ch/tuts/socksrv.c

This code is not "written for borland".  It's win32 C, specifically using the winsock library.  It will build using any C compiler, so long as 1.) the win32 headers are available and 2.) there are no syntax or linking errors.

I successfully compiled "sock.c" using gcc and this command:

Code: [Select]
gcc sock.c -o sock.exe -lws2_32
The linker command must go on the end there.  (Took me a few minutes to remember this.  Had it specified before the source file and was wondering why linker errors were appearing.  The GCC man page warns you about this -- always a good idea to read the documentation.)

The fact that you have to explicitly link (using the -l switch, for GCC) to particular libraries is simply a part of C/C++ programming.  This little winsock example fails just as spectacularly in Visual C++ if you fail to specify the library correctly.

This example is simple because it's a console application using winsock to provide basic networking facilities.  Nevermind that it hardly does anything, let alone provide a "simple chatserver".  Don't deceive yourself into thinking it's a simple matter to scale basic examples into production-quality complete applications.

Quote from: Newbie0815
Object oriented programming isnt new to me (...)
Quote from: Newbie0815
So I know what it is about, I know specially in win32 applications theres a LOT of inherited stuff from the libraries

Oh? You don't seem to know what inheritance is.  Inheritance does not mean "included from header files".  Inheritance is basing a sub-class on the methods and fields of its parent.  Using the win32 API does not involve inheritance.  You missed the part about win32 being written in C, and hence lacking any object-orientation.

Quote from: Newbie0815
I still don't like the idea of global and local variables, but I do understand the concept (...)

In C, minimizing global variables is essential to preventing name conflicts and increasing the overall readability of the code.  It's a core concept.

In C++, you don't use global variables, period.  Furthermore, encapsulating classes effectively by minimizing the number of public fields and methods is a critical part of writing good code.  Strong usage of encapsulation leads to easy isolation of bugs, among other benefits.

Quote from: Newbie0815
and what about my actual question? how to "translate" code from other compilers? Theres not THAT much different between borland and gcc (...)

Concerning the referenced code, there is no difference.  No compiler-specific feature has been used.  Indeed, it's rare to find an instance of it in C code to begin with.

Your problem is simple.  Either you do not have your compiler installed correctly, or you do not know how to use it (or the IDE, whichever is relevant).

Offline marfig

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Too dumb to get started?
« Reply #42 on: August 02, 2006, 02:08:29 am »
I quit. This is a clear case of "you will see" :)

Offline kidmosey

  • Multiple posting newcomer
  • *
  • Posts: 95
    • MUSITU International
Re: Too dumb to get started?
« Reply #43 on: August 02, 2006, 07:32:17 am »
A few quick comments on encapsulation that were missed earlier.

1. It prevents arbitrary setting of variables.  Instead of the user/programmer setting a member "weight" to a negative value, you just add a constraint to the SetWeight method.  You can make it throw an exception, return an error value, or automatically set the value to zero.

2. You may want certain values to be read-only.

3. (this one was mentioned) You may want to change something later without changing the interface.  Say you have a member m_total.  If you set this as public, you will never be able to do things like returning "width * height" to optimize the size of your class (this also works the other way around).

4. Last I checked, you cannot set class members as virtual.

I'm sure I missed several more, but reading this thread made me tired :D
3 years until google knows more than god.

Offline mdelfede

  • Multiple posting newcomer
  • *
  • Posts: 84
Re: Too dumb to get started?
« Reply #44 on: August 02, 2006, 10:36:06 am »
A few quick comments on encapsulation that were missed earlier.

1. It prevents arbitrary setting of variables.  Instead of the user/programmer setting a member "weight" to a negative value, you just add a constraint to the SetWeight method.  You can make it throw an exception, return an error value, or automatically set the value to zero.

2. You may want certain values to be read-only.

3. (this one was mentioned) You may want to change something later without changing the interface.  Say you have a member m_total.  If you set this as public, you will never be able to do things like returning "width * height" to optimize the size of your class (this also works the other way around).


A little comment about... I think that Borland with his language extensions made encapsulation better with properties, taking the advantages of both member variables (simpler use in expressions, clearer code) and getters/setters (good encapsulation, optimizations and calculations on-the-fly).
I'd really like such a construct in future c++ standard.

Ciao

Max