Qbasicnews.com

General => General Programming => Topic started by: fox on February 12, 2003, 11:11:25 AM



Title: Straying to C++
Post by: fox on February 12, 2003, 11:11:25 AM
Hi all.  It's been awhile since I've posted here because I've forayed into the world of C++ programming (sacrilige!).
To all those QB programmers out there who are, like I was, terrified of the thought of having to learn a new programming language, fear not.  C++ is unbelievably easy to learn.
I also used to say that C++ is long and tedious to program in, but there isn't really all that much more code to enter.
When I only knew QB, a smooth pixel*pixel scroller with flickerless animation and a 60FPS framerate was a thing of my dreams (being a purist and not liking libraries).  I have only been learning C++ for a MONTH and have already accomplished this.  

But to the point....  Who else here has found that a solid beginning in QBasic has aided their ability to move on to C++?

Try it!  I urge you all.  But never forget where you came from.


Title: Straying to C++
Post by: SJ Zero on February 12, 2003, 12:21:57 PM
I started off in C, couldn't get a damn sample program to compile, and gave up programming altogether until I started playing with QB.


(as for your dreams, check out Quest for a King at http://powerusr.sphosting.com/ for my engine. It gets 60FPS on a 233. Perhaps not the greatest feat ever achieved by human hands, but it *is* pure QB.)

I stick with QB because it's fun and easy to program in. C-alikes can't really say that about themselves. In spite of everything, I can still pick up code from 2 or 3 years ago in QB and understand it,  but the same code in C usually has me scratching my head. Just the nature of the syntax.


Title: Re: Straying to C++
Post by: Piptol on February 12, 2003, 02:52:54 PM
Quote from: "fox"
But to the point....  Who else here has found that a solid beginning in QBasic has aided their ability to move on to C++?

Try it!  I urge you all.  But never forget where you came from.


Yup, I'm working on my 1st C++ game. Or at least, I will be soon ;) Once you can program in any lang, the same basic principles apply. The main diff between these langs is OOP, and once you learn that, Bob's your mothers brother :) Very useful it is too.


Title: Straying to C++
Post by: Agamemnus on February 12, 2003, 08:22:11 PM
YOU FOX! (Er, Piptol AND fox) All I need is some decent string handling routines and a pset, and a PRINT. THEN I'll use C++.

(sorry, your avatar is quite comical)


Title: Pset, print is easy!!
Post by: fox on February 12, 2003, 09:19:37 PM
If you include the header file "IOSTREAM.H" you can use this for print:

cout<<"Text Here";    same as print "Text Here";

cout<<"Text Here"<<endl;  same as print "Text Here"

The pset routine is quite easy (especially if you are using an offscreen buffer) and there is a graphics header call graphics.h which allows you to program in "SCREEN 12". I wrote my own drawing functions for screen 13.

If you need any help email me at:

makk@iprimus.com.au.

I'd be happy to send you a copy of my header files.

You will need somthing like Borland Turbo C++ 3.0 (not MS Visual C++, becasue they don't allow DOS".

As for string functions.  I assume you want LEN, INSTR, RIGHT$, LEFT$ etc.

They are all supported in a different way.  Some of them you have to write small SUBS for.  I have an excellent C++ tutorial I would be happy to send you.


Title: Straying to C++
Post by: Hexadecimal Disaster on February 13, 2003, 12:31:07 AM
So you're proposing that "If you include the header file "IOSTREAM.H" and "and there is a graphics header call graphics.h", but you also mentioned this jewel on your first post: "(being a purist and not liking libraries)"

So... are you still a purist? (http://www.handykult.de/plaudersmilies.de/smoke.gif)


Title: hmm....
Post by: fox on February 13, 2003, 01:21:36 AM
You having a go mate?

NO I am not a "purist" anymore, and have been grateful to learn the lesson that most lib's are something that you could probably write yourself, but why waste the time when other's have done the work and are so good as to share it with others.  

I was on the other side of the fence before, when I didn't think that using libraries in QBASIC code was really kosher.  It seemed to me that if you wanted more power you should use a more powerful language, and just accept QBasic for what it is.  Now I see the bigger picture.  

I'll always be proud of the fact the I can program in QBasic.  As we all should be.  Peace.


Title: Straying to C++
Post by: Hexadecimal Disaster on February 13, 2003, 01:48:43 AM
Peace, bruddah. Nothing personal, I just asked 'cuz I noted that incongruence. And...

"I'll always be proud of the fact the I can program in QBasic. As we all should be."

Feel free to carve that on bronze. (http://www.handykult.de/plaudersmilies.de/beerchug.gif)


Title: Straying to C++
Post by: relsoft on February 14, 2003, 02:57:28 AM
;*)


Title: Straying to C++
Post by: LooseCaboose on February 15, 2003, 02:28:31 AM
Quote

To all those QB programmers out there who are, like I was, terrified of the thought of having to learn a new programming language, fear not. C++ is unbelievably easy to learn.
I also used to say that C++ is long and tedious to program in, but there isn't really all that much more code to enter.


Glad to hear people branching out and getting into new languages (the more you know the better). A couple of things strike me as odd in the above quote however. Learning any language (procedural anyway) after you know one already is easy, its a matter of learning the new syntax. eg from QB to C:
Code:

FUNCTION myFunc%(x as INTEGER)
  IF x > 0 THEN
    myFunc% = 1
    EXIT FUNCTION
  ELSE
    myFunc% = 2
    EXIT FUNCTION
  END IF
END FUNCTION

Easily translates into C/C++ as:
Code:

int myFunc(int x) {
  if(x > 0) {
    return 1;
  else
    return 2;
  }
}

However, with a language such as C/C++ there is far more to know than meets the eye at first glance, for instance check out the piece of code I posted in the general section ("A List" thread), its perfectly valid ANSI C code, but its not easy to understand. C has many, many tricks and underlying concepts that can be very difficult to grasp (and no Im not just talking about pointers).

The other thing I find interesting is that you say you find you dont have to do much extra coding in C/C++. This can of course vary depending on how robust your code is. For example.
Code:

typedef struct {
  int a;
  int b;
  char c;
} mem_t;

mem_t *x;

/* Allocate some memory for the mem_t struct */
x = malloc(5);

/* Stuff goes here */

exit(0);

Thats valid working C code, its not too long either, but its not good C code. C and C++ dont do anything you dont ask them too, good stable C code is often longer. The memory allocation above should be replaced as follows:
Code:

if((x = malloc(sizeof(mem_t))) == NULL) {
  fprintf(stderr, "Couldnt allocate memory for mem_t struct\n");
  exit(1);
}

/* Stuff goes here */

free(x);
exit(0);


Note that for portability reasons errors should use fprintf(stderr, "") and memory should be explicitly freed (even though its not always necessary). These things are what makes C code longer than code from other languages such as QB and Java which provide either compiler or runtime protection against many things which C/C++ dont.

That said, C/C++ often allow to code things in very short form also, take the myFunc function above which can be coded in C as:
Code:

#define myFunc(x) ((x > 0) ? 1 : 2)

Of course, writing an entire C program in such terse form can get you into trouble, check out http://www.ioccc.org/ for examples.

Get a good book on C/C++ from your local library (not an internet tutorial) and read it from cover to cover. C and C++ are /very/ powerful languages, but they do take a bit more learning effort than many other languages if you want to use them effectively and correctyly. Happy coding  :lol:


Title: Straying to C++
Post by: na_th_an on February 15, 2003, 11:18:19 AM
If I was asked about who would I rate the 'C' language, I would say it is just a genius work. It is the best language out there (opposed to C++ which is such a BAD O.O. hack). The way it is conceived allows you to perform almost anything.

Someone complained about the string handling funcions. At the very beginning, I also was puzzled about how C handled strings, but once you learn how memory is allocated and how pointers work, working with strings is a children's game. I am writing a "Japanese Graphic Adventure-like" interpreter in C and I had to write tons of string routines... I haven't had any problems.

C is for real programming ;)


Title: Straying to C++
Post by: Piptol on February 15, 2003, 12:32:22 PM
Quote from: "na_th_an"
If I was asked about who would I rate the 'C' language, I would say it is just a genius work. It is the best language out there (opposed to C++ which is such a BAD O.O. hack). The way it is conceived allows you to perform almost anything.


Why is C++ 'bad'? It provides a lot of useful additions to the powerful C language.. and you can still do everything with C++ you can do with C anyway, but you have the option of structuring your code better using classes & objects. The only thing I don't like is multiple inheritence, as it makes things confusing for a sloppy coder like me :)


Title: Straying to C++
Post by: toonski84 on February 15, 2003, 01:02:34 PM
the "c" language (an update to 'b', a language created by bell labs i think) is just another syntax.  it isnt the "language" that's "genius" it's the compilers made for it.  the fact that there isnt a fast basic compiler doesnt mean the language itself is slow, it's just a way of representing clumps of machine code in a readable form.

and if you ask me, c++ gives you a lot more control than c does, but, then again, that's just me again.


Title: Straying to C++
Post by: na_th_an on February 15, 2003, 01:43:48 PM
Well, C++ is a hack in my opinion, as it is some kind of patch to C. When you have to write a OO language, you better start from scratch rather than adding features to an existing one.

I am saying this 'cause C++ is not a true OO language 'cause it allows non-OO techniques, and that could be cheesy. IMHO.

Java is better conceived as an OO language. Yeah, it is interpreted and slower and such, but I am talking about design. If Java had a good compiler like C++ has, it would kick ass.

Anyhow, I am very acustomed with structural and procedural programming, OO makes my life harder so I avoid it. C by itself provides enough functionality, IMHO.


Title: Straying to C++
Post by: Agamemnus on February 15, 2003, 02:53:24 PM
You can do OOP in Qbasic.

However OOP with Java "classes" having each sub and main class in a separate file is just a bad idea. It's hard to test and it's hard to debug, IMHO. But professors don't care, so they teach you Java.

 :barf:


Title: Straying to C++
Post by: na_th_an on February 15, 2003, 04:14:36 PM
You can't do OO in QBasic, just strutured programming. It is different. Bot OO and SP have types and sets of SUBs with related functionality, but only OO leaves you to have pieces of executable code embedded in those objects, and things like hierarchy and software abstraction, things impossible to achieve in SP (you can use any FUNCTION anywhere, and this could be dangerous when working on a large project where many people is involved). Also QB lacks pointers, and that feature makes it very lame, IMHO.

The Java feature of having each class in a separate file is not a problem as long as you use a good IDE. With such a facility, your project will look like *exactly* as your QB program in the QB IDE where you have each SUB/FUNCTION in a separate "screen" or section.

I like storing each object definition in a separate file, just to be tidy. It is easy to copy some files to the new folder where you are gonna start your new project rather than having to do hours of copy and paste skimming thru' a bunch of untidy files full of both code and declarations.


Title: Straying to C++
Post by: LooseCaboose on February 17, 2003, 08:09:42 PM
Qbasic cannot do OOP period. OOP isnt just having classes and methods, it also includes features such as inheritance, polymorphism, abstract classes, class and method protection, templates and more. When used effectively, OOP is a very powerful way of programming (very suitable for large groups engineering large projects). Of course not everything lends itself to OOP, which is why other forms of languages exist (structural, functional, etc).

C++ is a terrible hack as Na_th_an said, it has ambiguous syntax problems ( << operators cause problems), multiple inheritance can be a nightmare, its attempts to remain backward compatible with C have destroyed its potential as a good OO language (and it isnt even fully backward compatible either). Unfortunately it seems to have ammased quite a following in the software engineering world, although Java and some of the .NET languages are now challenging this.

C is as Toonski said the successor to the language B (written by Kerrigan) which was  the succesor to BCPL. B was a pretty terrible language and with the help of Dennis Richie, Bell labs produced the first C compiler which they used to reimplement UNIX portably.

Its not just the compiler that makes a language, but also the design. C was designed as a portable language that lends itself very well to system programming. Java was designed as a cross platform true OO language (and succeeds very well), QB is designed as a simple, fast language to learn. You wouldnt use QB or Java to write a hardware driver, nor would you use C to write an internet applet, regardless of the compiler. Language design is very important. Poor design is the reason languages such as PL/I dont exist anymore.


Title: Straying to C++
Post by: na_th_an on February 18, 2003, 01:05:21 AM
Reading loosecaboose is just music :)


Title: Straying to C++
Post by: Hexadecimal Disaster on February 18, 2003, 01:30:12 AM
Agreed.

But, programming a business application in COBOL, who's a business oriented language (as you can read in the acronym), is still an annoying task. (http://www.handykult.de/plaudersmilies.de/biglaugh.gif)


Title: Straying to C++
Post by: LooseCaboose on February 19, 2003, 08:08:55 PM
Wow, cheers  guys. Now youve got me all embarrassed.  :oops:

Yeah COBOL and Fortran were both disgusting ugly languages, the former having the horid captials everywhere syntax (which basic unfortunately picked up). Interestingly enough, both languages  still have quite a following. You can even get object orrientated COBOL and Fortran if you really want to :o.

I think Java is a very nice language for bussiness applications, its much simpler than C/C++, excellent for software engineering in large groups and is highly web based (Companies can use applets, etc on intranets and global web pages). All this garbage about it being slow is unfounded, you can get JIT compilers if the VM issue bothers you that much and processors are getting sooo fast these days that bussiness application speed isnt even an issue anymore.

A good programmer learns which language is approiate for which task. I recently wrote a six line awk program (scripting language) for parsing data out of a UNIX syslog and creating a spreadsheet from it. I could have written it in bash, C or Java but it would have required far more effort for the same results.


Title: Re: Straying to C++
Post by: fox on May 24, 2009, 10:13:36 PM
Ha ha ha this is just gold.

It's been about six years since I first posted this and so much has changed since then.

That's all, I have nothing to add :-)

Oh ... except that I ditched C++ in favour of C# - more for work than anything :-)

... time to fire up QBasic for a trip down memory lane, I think.


Title: Re: Straying to C++
Post by: Ninkazu on June 25, 2009, 09:24:03 PM
C# is based on great technology, controlled by horrible people. I refuse to use it on the grounds of my belief in free (as in freedom) software. I worked for Microsoft, met Ballmer, and promptly started by boycott. The man is leading the world to an electronic prison.