BASIC is not BASIC anymore

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
geofs
Posts: 12
Joined: Apr 14, 2020 13:34

BASIC is not BASIC anymore

Post by geofs »

I consider myself to be a bit of a dinosaur when it comes to programming in BASIC, never had functions in my day :), my code must look so ancient when it is read by others today. Am I not alone that in thinking that todays coding practices are a little harder to follow now, or am I just getting old :)
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: BASIC is not BASIC anymore

Post by badidea »

Everyone is getting older, if you are lucky. FreeBASIC has indeed evolved to a more complex language, but you don't have to use all features. I have been using FreeBASIC for quite a while now (+10 years) and I also don't use all keywords. Proper functions and subroutines exist in BASIC for ~30 years (before that GOSUB and DEF FN). Try to make some programs without using #lang "qb" for some time and see if you like it. Concerning looks: if one does not use ALL CAPS keywords, no $%! symbols, no line numbers, minimal jump structures, and nice indenting, the code will look less scary for others. The more complex features are especially valuable for larger programs.

The biggest disadvantage of #lang "fb" is that you have to type more. Setting an integer to 1 (ignoring number of bits):
In "QB": a% = 1
In "FB": dim as integer a = 1
In "C" : int a = 1;
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: BASIC is not BASIC anymore

Post by Tourist Trap »

badidea wrote: The biggest disadvantage of #lang "fb" is that you have to type more. Setting an integer to 1 (ignoring number of bits):
In "QB": a% = 1
In "FB": dim as integer a = 1
In "C" : int a = 1;
Hi badidea,

you still can be lazy and just type:

Code: Select all

var a = 1
That will do the job.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: BASIC is not BASIC anymore

Post by srvaldez »

I know var can make things easier, but then you have to guess what type a is, I prefer to be explicit and not leave anything to guesswork.
in this case, a could be of any numeric type
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: BASIC is not BASIC anymore

Post by badidea »

Tourist Trap wrote:you still can be lazy and just type:

Code: Select all

var a = 1
That will do the job.
I forgot about that one. Beats C by one character :-)
I prefer the 'verbose' style however. Edit: Agreeing with 'srvaldez' .
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: BASIC is not BASIC anymore

Post by paul doe »

srvaldez wrote:I know var can make things easier, but then you have to guess what type a is, I prefer to be explicit and not leave anything to guesswork.
in this case, a could be of any numeric type
Indeed. Var is most useful in situations where you don't have to guess the context (or read the manual to learn how var infers the type). Say:

Code: Select all

var anInstance => MyClass( "Test" )
ShawnLG
Posts: 142
Joined: Dec 25, 2008 20:21

Re: BASIC is not BASIC anymore

Post by ShawnLG »

There is a workaround using marcros.

Code: Select all

#Undef Int'  Already used in FB' polluted namespace :(

#Macro Int
   Dim As Integer
#EndMacro

Int a = 10' C style define.
Print a
Sleep
Var is implicit and why was it added to FB? It is bad for code readability.
Xusinboy Bekchanov
Posts: 783
Joined: Jul 26, 2018 18:28

Re: BASIC is not BASIC anymore

Post by Xusinboy Bekchanov »

ShawnLG wrote:There is a workaround using marcros.

Code: Select all

#Undef Int'  Already used in FB' polluted namespace :(

#Macro Int
   Dim As Integer
#EndMacro

Int a = 10' C style define.
Print a
Sleep
Var is implicit and why was it added to FB? It is bad for code readability.
Need to create such a bi file with all possible C macro commands. It will be useful to everyone. Who wants to can include this bi file their program
Can call him "ccompat.bi"
bubacxo
Posts: 12
Joined: May 29, 2019 20:02

Re: BASIC is not BASIC anymore

Post by bubacxo »

A little love for var.

var is one of my favorite features.
I think it's elegantly done, it's optional, and it's not that hard to remember:

var isint = 5 ' always integer
var isdbl = 5.0 ' always double
var issngl = cast(Single‚ 4.14) ' explicit
etc...

of course where it really is helpful is with UDT's and pointers to pointers and all the other stuff I'd rather let the compiler figure out.

But it's with more complex types that maybe you could argue that var is too implicit and confusing.

But I say who cares as long as the compiler is happy and keeping track?
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: BASIC is not BASIC anymore

Post by badidea »

BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: BASIC is not BASIC anymore

Post by BasicCoder2 »

BASIC was the first HLL that a novice could use to write programs that would run on different CPU's. Although line numbers and GOSUBS and short variable names were rather low level solutions for reasons of limited memory at the time. Before that I remember looking at Fortran code and thinking how great it was to see things written in a more natural readable language rather than the machine code I learned about when learning how computers worked at the level of logic gates, flip flops, program counter, instruction register, encoder and decoder networks and a master clock.

With FreeBASIC you can write some very C++ like cryptic source code which is compact and fast however I still like to at least write the first version of a program (and often the final version for me) in a very natural human like language first.
Post Reply