[Implemented] Nice to have...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

[Implemented] Nice to have...

Post by RichardL »

Just to save typing
============

Global Myvariable.l = 123 ; Assign variable as global and initial value

and...

Protected LocalVariable.l = 456 ; For locals


Useful when the string length is not known... common in other BASICS
===========================

k$ = Mid(Mystring$,N) ; k$ gets all the string starting at character N


To aid clarity...
==========
Sub gets ignored, but maybe we can then get the nice guys at jaPBe to fold Sub.... Return. That would really tidy things up. Folding is so nice I have given up subroutines and use Procedures because editing is so much easier. GFA folded both.

Sub SubroutineName():
.
.
Return
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Re: Nice to have...

Post by thefool »

ok the Global myvar.l = 123
I agree.
But it should be optional, so old sources will work, and so those who
might not need a specific value to the variable just write the usual.


But:
RichardL wrote: Sub gets ignored, but maybe we can then get the nice guys at jaPBe to fold Sub.... Return. That would really tidy things up. Folding is so nice I have given up subroutines and use Procedures because editing is so much easier. GFA folded both.

Sub SubroutineName():
.
.
Return
subs?

after some looking i cant see how to make subs in purebasic using Sub routin() The only sub thing is Gosub, and gosub uses labels.

Since labels are used for more than subroutines, such as goto and adressing of variables and procedures, and include binarie's.
So you want to fold every labels, wich i would not recommend :P
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

"Sub" or "Subroutine"
==============

The current syntax for calling a subroutine is

Gosub MyLabel

The subroutine is identified by the label

Mylabel:
Code goes here
Return

What I am proposing is that the call remains the same, so no compatibility issues and that the word Sub is optional in front of the label.

Sub Mylabel:
Code goes here
Return

The compiler disregards the word "Sub" and uses the label that follows; it treats existing code the same way, so no backward compatibility issues here.

Intelligent editors can fold from the word Sub until and including the word Return, just like they fold from Procedure to EndProcedure.

My pet topic... (Rant warning ON)
=========
The editor is the tool that makes you creative, you use it more than any other tool so I am in favour of any item that simplifies editing, reduces screen clutter and catches errors. jaPBe has started taking this route and I hope it continues that way. Also, have a look at Power Basic's SED, it is also a community developed editor that runs rings around the "official" editor... it shares a lot with jaBPe, is ahead in some places and behind in others (very specifically auto unindent, which jaPBe has in a basic form)

Have a look at the GFA editor (free to try at GFA.net, BUT is only 16 bit and shows its age) Eight years of almost solid use tells me good folding improves productivity. F11 folds and unfolds routines (Functions AND Procedures) at the cursor, F12 folds and unfolds the current routine and all subsequent. It is perfectly practical to acheive a listing that has a comment or two and everyting folded thereafter.

Rant warning OFF.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

so you want to make subroutines like procedures (as you do in a lot of other basics)?

example:

sub Mysub()

return

instead of the gosub method?
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

I see nothing wrong with having distinct methods for a section of code that performs some work and a section of code that performs some work and return a value. In GFA (16 bit) they were called "procedures" and "functions", respectively. I used them both. In Pure Basic they are "subroutines" and "procedures". (Even the terminology is inconsisten, but I doubt it matters.)

The case I am making is that editing is vastly easier when you can fold finished code sections so you are able to concentrate on new things. This becomes much easier if the editor can fold procedures AND subroutines; and that currently there is no reserved word to identify the start of a subroutine; thus the editor has difficulty identifying the start of a subroutine and commence folding.

Placing the word "Sub" (or anything else you choose) before a subroutine clearly identifies its purpose and would make no difference to the overall philosophy of Pure Basic. It is benign, it clarifies the purpose of the section of code that follows and could be usefully exploited by editors.

In the past I wrote editors that used #Fold and #EndFold. On slow scrolling, small screens this cut down the amount of time to scroll around the source file. Nowdays the screens are bigger and faster but the files have also grown!
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

In GFA (16 bit) they were called "procedures" and "functions", respectively. I used them both. In Pure Basic they are "subroutines" and "procedures". (Even the terminology is inconsisten, but I doubt it matters.)
In PB the GFA "procedures" and "functions" is replaced with just 'procedure'.
Coming from GFA you should check out the survival guide from a former GFA programmer:
http://www.xs4all.nl/~bluez/datatalk/purebasic.htm#top
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

I guess that GFA's syntax of GOSUB name, [parameters] and the named routine terminating with RETURN qualifies it as a subroutine call.

Also GFA's FUNCTION uses syntax like Bottles = @CountBottles()

FUNCTION CountBottles()
Code here............
RETURN NumberOf Bottles
ENDFUNC

... qualifies as a FUNCTION.

Regardless of the details of Subroutine / Procedure / Function syntax my point about putting SUB at the front of a SUBROUTINE in PB still stands.

"It is benign, it clarifies the purpose of the section of code that follows and could be usefully exploited by editors."

Enough.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

i did not complain about your idea, i just said that the only way to specify
a subroutine is by a label, gosub and return.

And folding labels is not good, as they are used for much more than that only.

But as pupil said, procedures replaced the function.

But i see what you mean.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i'm a former gfa user as well, may i ask why you'd like to use sub's instead of procedures?

(i assume you're using japbe, as any gfa programmer is wont to do, i suppose :-) )
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

OK... I'm a happy bunny :D
Thanks to caos.kin I have a solution that works with jaPBe

There are some folding instructions that can fold any section of code. In this simple example I want to fold a subroutine, so ;{ and ;} are placed as shown and the subroutine labelled Total: gets folded.

BRILLIANT... andother jaPBe gem!


Total: ;{- Subroutine to total Items
Total = 0
For n=1 To 10
Total+Item(n)
Next
Return ;}


Here is a snip from caos...

;{ custom fold
;}
;{- Custom Fold+Bookmark
;}
;/Headline
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

nice trick. Actually i didnt know that.
we really need an english manual for jabpe, or else these very nice
trics wont be discowered.

thanks for sharing :D
Post Reply