Page 1 of 3

Language Syntax Honouring the name BASIC

Posted: Mon Feb 29, 2016 10:38 pm
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:

Re: Language Syntax Honouring the name BASIC

Posted: Mon Feb 29, 2016 10:49 pm
by Dude
AutoComplete?

Re: Language Syntax Honouring the name BASIC

Posted: Mon Feb 29, 2016 10:56 pm
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.

Re: Language Syntax Honouring the name BASIC

Posted: Mon Feb 29, 2016 10:58 pm
by Dude
Frarth wrote:In any case "endsub" is much more preferable.
For you. ;)

Re: Language Syntax Honouring the name BASIC

Posted: Mon Feb 29, 2016 11:00 pm
by Frarth
For anyone who wants to do fast and short coding. ;)

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 12:07 am
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

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 12:28 am
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. :)

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 1:05 am
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().

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 1:59 am
by IdeasVacuum
.... I see, coding and obfuscation all rolled into one, a great time saver. :shock:

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 7:01 am
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!

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 8:16 am
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.

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 8:38 am
by davido
@Frarth,
I forgot to add that I also add ProcedureReturn as:

Pro - tab - tab - backspace - r - tab

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 8:53 am
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.

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 8:54 am
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)

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 9:28 am
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: