Page 2 of 3

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 10:30 am
by Keya
Fred wrote:@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.
Excellent, thanks!!! Permanent macros and boosted productivity here we come!:)

Code: Select all

Cross-platform command switches
    -r, --resident, /RESIDENT "filename": creates a resident file specified by the filename.
    -ir, --ignoreresident, /IGNORERESIDENT "filename": doesn't load the specified resident file when the compiler starts.
           It's mostly useful when updating a resident which already exists, so it won't load it. 
and then i can just link my macro file at pastebin in my sig for others using my code :D

hmmm several downsides of using macro though...
one is structure contents are no longer recognised (by the IDE) :(

Code: Select all

Macro Struct
    Structure
EndMacro
    
Struct MyTest
var1.i
var2.i
EndStructure

Define Test.MyTest
Test\var...    ; <-- Typing "Test\" here normally would suggest var1 and var2 available, but due to macro it doesnt?
so im not sure if i can use that (for structures anyway) because i find that helper invaluable when it comes to complex structures, also saves having to waste time scrolling through source looking for the structure definition.

Likewise, if you do one for say MsgBox = MessageRequester, when you type "MsgBox(" you no longer get the parameter suggestions in the bottom statusbar ("Title.s, Message.s, [flags.i]" etc)

Would be great if the IDE was able to expand the macro and detect, problem would be solved i guess.

The lack of bolding/highlighting is also a bit weird though, looks like ive inserted plaintext amongst the code [edit] can use Custom Keywords for this, nice

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 11:32 am
by Derren
You can add your keywords to the list of "custom" keywords in the preference menu.

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 11:35 am
by Keya
Ahh nice!

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 11:55 am
by Frarth
For anyone who's interested, here is a start off:

Code: Select all

; keyword replacement macros
; --------------------------
macro explicit
  enableexplicit
endmacro

macro subreturn
  procedurereturn
endmacro

; for readibility
macro exitsub
  procedurereturn
endmacro

macro local
  protected
endmacro

macro sub
  procedure
endmacro

macro endsub
  endprocedure
endmacro

macro include
  IncludeFile
endmacro

macro xinclude
  XIncludeFile
endmacro

macro type
  structure
endmacro

macro endtype
  endstructure
endmacro

macro ClearType
  ClearStructure
endmacro

macro CopyType
  CopyStructure
endmacro

macro union
  structureunion
endmacro

macro endunion
  endstructureunion
endmacro

macro enum
  enumeration
endmacro

macro endenum
  endenumeration
endmacro

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 12:16 pm
by Danilo
Do you make a difference between Sub and Function?

I guess we will see very different styles in the future, after nearly 20 years of PB:

Code: Select all

Structure/EndStructure
Struct/EndStruct
Type/EndType
S/ES
T/ET

Procedure/EndProcedure
Sub/EndSub
Function/EndFunction
Proc/EndProc
Func/EndFunc
Fn/EndFn

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 12:23 pm
by sys64802
Danilo wrote: I guess we will see very different styles in the future, after nearly 20 years of PB:

Code: Select all

Structure/EndStructure
Struct/EndStruct
Type/EndType
S/ES
T/ET

Sub/EndSub
Function/EndFunction
Func/EndFunc
Fn/EndFn
Just what the doctor ordered for the code posted in the forum. :wink:
I think that's ok if you don't share anything, else it's just a PITA imo.

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 1:27 pm
by DK_PETER
Danilo wrote:Do you make a difference between Sub and Function?

I guess we will see very different styles in the future, after nearly 20 years of PB:

Code: Select all

Structure/EndStructure
Struct/EndStruct
Type/EndType
S/ES
T/ET

Procedure/EndProcedure
Sub/EndSub
Function/EndFunction
Proc/EndProc
Func/EndFunc
Fn/EndFn
I really don't think so.
The option to use macros has been used frequently in f.ex PurePunch competitions to produce
smaller and very frequently totally unreadable code. :)
My bet is that function renaming is probably only interesting for the very few.

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 1:47 pm
by Frarth
Danilo wrote:Do you make a difference between Sub and Function?

I guess we will see very different styles in the future, after nearly 20 years of PB:

Code: Select all

Structure/EndStructure
Struct/EndStruct
Type/EndType
S/ES
T/ET

Procedure/EndProcedure
Sub/EndSub
Function/EndFunction
Proc/EndProc
Func/EndFunc
Fn/EndFn
SUB and FUNCTION are two different keywords for the same thing. From a programming technical point of view it does not really matter whether or not a routine returns a value. Even a procedure in purebasic without a type indicator returns a value (0) if used as a function and visa versa. So adding a type indicator like SUB.d is sufficient as it already tells me the routine is designed to return a result. So using FUNCTION doesn't improve readability in my opinion and the keyword is already too long.

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 1:56 pm
by Zebuddi123
There is all so the Code Template in the tools panel, set your code up double click all inserted. It would be great if when defining the template the cursor would be repositioned to the same line as when defining the template. It also has folders/treeview .

Zebuddi. :)

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 2:42 pm
by TI-994A
Frarth wrote:

Code: Select all

; keyword replacement macros
; --------------------------
macro explicit
  enableexplicit
endmacro

macro subreturn
  procedurereturn
endmacro

; for readibility
macro exitsub
  procedurereturn
endmacro

macro local
  protected
endmacro

macro sub
  procedure
endmacro

macro endsub
  endprocedure
endmacro

macro include
  IncludeFile
endmacro

macro xinclude
  XIncludeFile
endmacro

macro type
  structure
endmacro

macro endtype
  endstructure
endmacro

macro ClearType
  ClearStructure
endmacro

macro CopyType
  CopyStructure
endmacro

macro union
  structureunion
endmacro

macro endunion
  endstructureunion
endmacro

macro enum
  enumeration
endmacro

macro endenum
  endenumeration
endmacro
These in no way "honour" the original BASIC; most of them weren't even in the original language. :lol:

Moreover, such redundant substitutions would only confuse and impede debugging.

Stop reinventing the wheel and learn the language. :wink:

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 2:53 pm
by Frarth
TI-994A wrote: These in no way "honour" the original BASIC; most of them weren't even in the original language. :lol:

Moreover, such redundant substitutions would only confuse and impede debugging.

Stop reinventing the wheel and learn the language. :wink:
After 7 years PB I should learn the code LOL. Where am I reinventing the wheel? As I said in the original post, first of all it is about preferring shorter keywords. Nothing more nothing less. In addition IMO sub/endsub etc would also fit the name PureBASIC better. But again, it's a matter of opinion. Bu thank you for your advice. :lol:

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 3:35 pm
by srod
I am so used to the verbose syntax now (if it is indeed verbose! :) ) that I would personally seek out anyone responsible for changing the syntax and force feed them a pair of Fangbeast's festering underpants. And that would just be the appetizer before the main course! :)

Of course, I would be left having to explain how a pair of his festering jockies came to be in my possession, but I am sure I can come up with a plausible explanation before tea time! :shock:

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 6:57 pm
by HanPBF
As was written macros work with user defined keywords -> so, autocompletion available.

Or use macro expansion by command line -> still no formatting kept there?

Code: Select all

macro sub
	procedure
		; this is generated by macro 
endmacro	

sub test()
EndProcedure

Procedure test2()
EndProcedure
gets after PREPROCESS

Code: Select all

macro sub
	procedure
		
endmacro	
procedure test()
EndProcedure
Procedure test2()
EndProcedure
comments deleted in macro; all the formatting gone away...

How can I prevent this???
--commented is not an option (does simply comment all original source)

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 11:37 pm
by Tenaja
Just remember, the design intent for BASIC was not to make it easy to type, but to make the code fit into ram-limited systems. As such, short or long commands have nothing to do with "honoring BASIC".

Also, +1 to TI-994a:
These in no way "honour" the original BASIC; most of them weren't even in the original language. :lol:
When I was a newbie to PB, I used numerous macros, myself, to make it more comfortable/familiar for me. Over a few months, however, I grew out of that and started using pure PureBasic. Within a few years, I even forgot those early months, until I went back and looked at my early code...and as I did, I wondered what the heck I was thinking. I know some of the old dogs on the forum are older than the one typing this, but still, embrace it purely, and it will be easier in the long run.

Re: Language Syntax Honouring the name BASIC

Posted: Tue Mar 01, 2016 11:53 pm
by HanPBF
Hello Tenaja,
When I was a newbie to PB, I used numerous macros, myself, to make it more comfortable/familiar for me. Over a few months, however, I grew out of that
What do You mean saying "grew out of that"? Maybe doing more the direct, very verbose PB way? Or using preprocessor?

I also used macros intensively; then I saw that debugging and autocompletion is not supported and PREPROCESS does neither help.
Autocompletion with macros -> o.k. very difficult to implement
Debugging -> steps over the macros; IDE is source code based not AST based, so o.k.

So, the question is why not to use macros (for shortcuts); I think only due to lack in support, either by implementation or by design, nothing else.

At the end, result ist the same: "prevent using macros", I agree with that.