Scope/EndScope keywords
-
- Enthusiast
- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Scope/EndScope keywords
I'd like to see Scope and EndScope keywords added -- should be easy! What they do is: the Scope one takes a single text parameter, and that text is (internally) added to the start of all variable names, procedure names, etc, from that point, until EndScope is reached.
What this means, is that you can copy and paste a snippet from these forums into your own app, wrap them with Scope/EndScope, and you are guaranteed that the variable names, procedure names, etc, from the snippet will NOT clash with your existing code at all (assuming you use a unique Scope name).
What this means, is that you can copy and paste a snippet from these forums into your own app, wrap them with Scope/EndScope, and you are guaranteed that the variable names, procedure names, etc, from the snippet will NOT clash with your existing code at all (assuming you use a unique Scope name).
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
-
- Enthusiast
- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
In the same way. A global var named Joey in the snippet, with a scope parameter of Big, would just become a global var named BigJoey instead, meaning that it wouldn't clash with a main app global var named Joey. The snippet and main app would compile together without problem.akj wrote:How would global [and shared] variables be treated?
Couldn't have been said any better. And that's the crux of the matter.Kaeru Gaman wrote:[...]copying code from the forums into your own project without adjusting it is no deed of glory.
For the life of me, i just can't think of a single situation when you'd want to do that.
If you want to test a snippet, you copy it into a new code window.
If you want to integrate the snippet into your code, you adjust and adapt it.
But to compile a snippet, as is, right into your existing code ? My good grief...
Why ?
PB Forums : Proof positive that 2 heads (or more...) are better than one 

-
- Enthusiast
- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
You can't use "Protected" with procedure names.Kaeru Gaman wrote:it's strongly recommended to use Protected inside of Procedures
There are plenty of good standalone snippets in these forums by respected coders who write clean, efficient code for us to use. These such examples need no adaptions, and for you to say "good grief" about it means that you're basically trashing those good contributions by top coders here. I'm sure they appreciate being told that their efforts in the "Tricks N Tips" section are nothing more than crap.Blue wrote:to compile a snippet, as is, right into your existing code ? My good grief.
I see no problem with allowing a drag-and-drop of such code into our apps. With Scope/EndScope, it just means we don't need to worry about adapting their code, or our code: just drop it in, and it's ready to run. No need to waste time picking the code apart and checking for clashing variable names and procedure names.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
/me shakes headUserOfPure wrote:You can't use "Protected" with procedure names.
There are plenty of good standalone snippets in these forums by respected coders who write clean, efficient code for us to use. These such examples need no adaptions, and for you to say "good grief" about it means that you're basically trashing those good contributions by top coders here. I'm sure they appreciate being told that their efforts in the "Tricks N Tips" section are nothing more than crap.
I see no problem with allowing a drag-and-drop of such code into our apps. With Scope/EndScope, it just means we don't need to worry about adapting their code, or our code: just drop it in, and it's ready to run. No need to waste time picking the code apart and checking for clashing variable names and procedure names.
if you want to include codesnippets into your project, put it into an include and do a Find/Replace with
"Procedure " -> "Procedure Prefix_"
even with scope/endscope there is no guarantee that dragged-dropped code will work flawlessly.
you will have to check it over anyways.
if you want to code, put work into it.
if you don't want to put work into it, buy a click-together-kit and drop programming.
we did not say, you should not appreciate code from the forums, we just said
if you copy/paste it without investing the minimal work to put prefixes into it you do not appreciate it at all!

oh... and have a nice day.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
... which all has nothing to do with the request 
+1
Although this sounds amazingly similar to the concept (and associated discussion) on modules and workspaces

+1
Although this sounds amazingly similar to the concept (and associated discussion) on modules and workspaces

( 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... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Forgetting code posted in the forums for a moment, it would be useful to have a feature similar to this to make it easier to reuse my own code in other programs.
Prefixing every global variable and procedure and structure works but it has the failing that you can't improve a portion of code that is used in several different programs without the need to rename everything before it can be re-included in different codes. Choosing a great prefix from the start works well for code that is then included in different projects so that re-prefix everything is unnecessary, but it has the failing that it can make code much harder to read.
The reuse of code increases as the size of a project increases. If prefixing the names of variables, procedures, and structures is the common solution than why not turn all that repetitive action into a simple solution with a new keyword or two.
I am anxious for this to be implemented in some way, and Fred has said that it was something he would consider (look in the second link below from 2005). I am waiting for that item to advance on his ToDo list.
Note: this topic is simply a variation of namespaces and modules discussed in other threads and feature requests. Here are some links to those discussions.
http://www.purebasic.fr/english/viewtopic.php?t=36485
http://www.purebasic.fr/english/viewtopic.php?t=16224
http://www.purebasic.fr/english/viewtopic.php?t=32954
http://www.purebasic.fr/english/viewtopic.php?t=30163
http://www.purebasic.fr/english/viewtopic.php?t=25478
Prefixing every global variable and procedure and structure works but it has the failing that you can't improve a portion of code that is used in several different programs without the need to rename everything before it can be re-included in different codes. Choosing a great prefix from the start works well for code that is then included in different projects so that re-prefix everything is unnecessary, but it has the failing that it can make code much harder to read.
The reuse of code increases as the size of a project increases. If prefixing the names of variables, procedures, and structures is the common solution than why not turn all that repetitive action into a simple solution with a new keyword or two.
I am anxious for this to be implemented in some way, and Fred has said that it was something he would consider (look in the second link below from 2005). I am waiting for that item to advance on his ToDo list.

Note: this topic is simply a variation of namespaces and modules discussed in other threads and feature requests. Here are some links to those discussions.
http://www.purebasic.fr/english/viewtopic.php?t=36485
http://www.purebasic.fr/english/viewtopic.php?t=16224
http://www.purebasic.fr/english/viewtopic.php?t=32954
http://www.purebasic.fr/english/viewtopic.php?t=30163
http://www.purebasic.fr/english/viewtopic.php?t=25478