Qbasicnews.com
July 21, 2018, 06:55:41 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Straying to C++  (Read 22856 times)
fox
New Member

Posts: 24


« 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.
Logged
SJ Zero
Been there, done that
*****
Posts: 1211



WWW
« Reply #1 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.
Logged
Piptol
Ancient QBer
****
Posts: 422



WWW
« Reply #2 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 Wink 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 Smiley Very useful it is too.
Logged

In a world without walls and doors, who needs Windows and Gates?
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #3 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)
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
fox
New Member

Posts: 24


« Reply #4 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.
Logged
Hexadecimal Disaster
Been there, done that
*****
Posts: 1123



« Reply #5 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?
Logged

img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
fox
New Member

Posts: 24


« Reply #6 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.
Logged
Hexadecimal Disaster
Been there, done that
*****
Posts: 1123



« Reply #7 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.
Logged

img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #8 on: February 14, 2003, 02:57:28 AM »

;*)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #9 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:
Logged

esus saves.... Passes to Moses, shoots, he scores!
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #10 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 Wink
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Piptol
Ancient QBer
****
Posts: 422



WWW
« Reply #11 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 Smiley
Logged

In a world without walls and doors, who needs Windows and Gates?
toonski84
__/--\__
*****
Posts: 2567



« Reply #12 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.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #13 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.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #14 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:
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!