Language Syntax Honouring the name BASIC

Everything else that doesn't fall into one of the other PB categories.
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Language Syntax Honouring the name BASIC

Post by Frarth »

Since 2009 I am a fan of PureBasic chiefly because of its multiplatform capabilities, its speed and the small sized executables it generates.

There is one thing though that I would put on the con side, which is the lengthy syntax. Having used languages such as quickbasic, visual basic real basic, and pascal, in my view it would be cleaner and nicer coding when using syntax like this:

Code: Select all

sub.b IsAlignment()
  local.l a, b, c, j, k
  
  a = GetGadgetState(7)
  b = GetGadgetState(8)
  c = GetGadgetState(9)
  
  if b <> a and b <> c and c <> a
    if not ((b > a) and (b > c))
      if a > c
        swap a, c
        SetGadgetState(7, a)
        SetGadgetState(9, c)
      endif
      ; ok
      Alignment\p1 = a
      Alignment\p2 = b
      Alignment\p3 = c
      subreturn #true
    endif
  endif
  
  subreturn #false
endsub
Currently I use macros which allow me to write code like this. SUB, ENDSUB and SUBRETURN is much more preferable than PROCEDURE, ENDPROCEDURE AND PROCEDURERETURN. It was the last keyword especially that made me start using macros because I hate to do this lengthy typing.

I know PureBasic has been around for quite some time and a syntax change or addition will be out of the question. But keeping syntax as short as possible but still understandable would have been a good aim IMHO.

Another example using TYPE instead of STRUCTURE:

Code: Select all

type TAlignmentResult
  d.TDate
  L.d
  lunar.b     ; type flag
  p1name.s
  p2name.s
  p3name.s
endtype
Just a thought. :wink:
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Language Syntax Honouring the name BASIC

Post by Dude »

AutoComplete?
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: Language Syntax Honouring the name BASIC

Post by Frarth »

Sure there is autocomplete, but with keywords like "procedurereturn" you either need the mouse or arrow keys and enter key to select it in the autocomplete list or you type until "procedurer" to get it at the top of the list and then hit enter. In any case "endsub" is much more preferable.
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Language Syntax Honouring the name BASIC

Post by Dude »

Frarth wrote:In any case "endsub" is much more preferable.
For you. ;)
User avatar
Frarth
Enthusiast
Enthusiast
Posts: 241
Joined: Tue Jul 21, 2009 11:11 am
Location: On the planet
Contact:

Re: Language Syntax Honouring the name BASIC

Post by Frarth »

For anyone who wants to do fast and short coding. ;)
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Language Syntax Honouring the name BASIC

Post by davido »

@Frarth,
I am not sure if this helps you but I enter procedures, thus:

pro
press auto-complete key twice to get:

Procedure EndProcedure
This leaves the cursor before the 'E' so I enter the name:

Procedure Main()EndProcedure
Then press 'Return key' to get:

Procedure Main()

EndProcedure
DE AA EB
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Language Syntax Honouring the name BASIC

Post by Demivec »

Frarth wrote:Sure there is autocomplete, but with keywords like "procedurereturn" you either need the mouse or arrow keys and enter key to select it in the autocomplete list or you type until "procedurer" to get it at the top of the list and then hit enter. In any case "endsub" is much more preferable.
Using auto-complete and [Tab] to make a selection, for 'ProcedureReturn' type 'pro' [Tab] 'r' [Tab].

Regarding the long words, I agree they can become long at times. However, as I pointed out above, I don't think it is a problem and auto-complete helps with the typing them for the most part.

Others have suggested macro replacements in the past that accommodate their typing preferences, as you have done. If it works, great.

There really aren't that many keywords to worry about, most everything is a library function. :)
User avatar
ostapas
Enthusiast
Enthusiast
Posts: 192
Joined: Thu Feb 18, 2010 11:10 pm

Re: Language Syntax Honouring the name BASIC

Post by ostapas »

You could create a tool which inserts code snippets on certain shortcuts(which I did for myself), e.g., typing PR+Space inserts ProcedureReturn or typing GGIS+Space inserts GetGadgetItemState().
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Language Syntax Honouring the name BASIC

Post by IdeasVacuum »

.... I see, coding and obfuscation all rolled into one, a great time saver. :shock:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Language Syntax Honouring the name BASIC

Post by Keya »

I'm not fussed at all about honoring basic syntax (just as long as it remains 'basicesque'), but I couldn't agree more because every second quickly adds up and PRODUCTIVITY is an extremely important factor!
Many minutes every day are wasted simply typing long names where abbreviations exist but are not used Procedure instead of Sub, Structure instead of Struct, MessageRequester instead of Msgbox etc (life's too short!), and they dont improve readability over their shorter counterparts either; actually by making the code bigger for no reason it has the opposite effect i think

Ive been interested in a universal macro file for a while now, but
1) having to IncludeFile("fixedpath\mymacros.pbi") every single time i start a new source would get annoying quickly, it would be nice if there was an IDE option for such a file
2) i cant post code using my macros (unless i post my macro file) or nobody will be able to compile my code
However, itd be easy enough to write an Unmacro.pb program to use before posting (well, easy assuming simple wordreplacement style macros), not ideal though

If not a custom universal macro file like above perhaps Fred can add Aliases - effectively a fixed universal macro?
Interesting topic anyway

Would love to see other peoples macro files!
Fred
Administrator
Administrator
Posts: 18396
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Language Syntax Honouring the name BASIC

Post by Fred »

davido's tip is what I use here as well, and it creates a procedure/endprocedure in second (pro - tab - tab - procname - enter).

@Keya: you can put your macro in a resident file (see http://www.purebasic.com/documentation/ ... piler.html for the syntax to create one), it will gets loaded everytime PB loads.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Language Syntax Honouring the name BASIC

Post by davido »

@Frarth,
I forgot to add that I also add ProcedureReturn as:

Pro - tab - tab - backspace - r - tab
DE AA EB
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Language Syntax Honouring the name BASIC

Post by Dude »

Frarth wrote:For anyone who wants to do fast and short coding. ;)
Typing both "ProcedureReturn" and "EndSub" takes less than one single second each. What's the big deal? You're talking like "ProcedureReturn" takes ten seconds or something.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Language Syntax Honouring the name BASIC

Post by Marc56us »

I use too [Tab] x 2 and for the rest, for or many years I used a small free utility, named TyperTask.
It consists of a single EXE (53Ko no install) file and a text.

Config file is on trayicon. It works as INI file (key pair). Don't forget to save after edit.
Sample I use for PB::

Code: Select all

msb=MessageRequester("", ""){left}{left}{left}{left}{left}{left}
In this example, when I type msb, he immediately replaces the text and places the cursor between the first two ""

This program works in any application. (It is very useful for example, to type my email address in web forms or salutations in letters.)

It does not work like PB macro system because it immediately replaces the text and not at compile time, so it may not be used to make code more readable, but only for faster typing.
The only constraint is to remember the abbreviations and do not use existing words

PS. After edit ini file be carefull to do not use close box ico, but only reduce icon!

:)

(English is not my native language, I use an online translator)
User avatar
TI-994A
Addict
Addict
Posts: 2771
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Language Syntax Honouring the name BASIC

Post by TI-994A »

Frarth wrote:...one thing though that I would put on the con side, which is the lengthy syntax ... made me start using macros because I hate to do this lengthy typing.
You've clearly not used Objective-C. :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply