Crop commands to cut strings short

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I don't see how it can be easier to understand when everyone doesn't speak the same language.. If some use InStr() instead of FindString(), what will happen when he will put his code in trick'n'tips for example ? It won't compile at all and nobody except the writer could understand it quickly. I hope you get my point :wink:
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

every tip(snippet) will work if the Macro is included !
SPAMINATOR NR.1
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Fred wrote:I don't see how it can be easier to understand when everyone doesn't speak the same language.. If some use InStr() instead of FindString(), what will happen when he will put his code in trick'n'tips for example ? It won't compile at all and nobody except the writer could understand it quickly. I hope you get my point :wink:
You misunderstand me a little bit.
Macros should handle like Constants and Structures/Interfaces. So it would be nice, when macros can be added in "res"-Files. So my example above can be included in the Purebasic-Default.res (also a good idea would be to replace the rgb()-function to a macro rgb=Red+Green<<8+blue<<16. Also many API-Macros, like HiWord, and so on, would be nice).

So this PB-Macros are default and all can use it. When a "Tip's and Tricks" is posted with own macros, so this macros must be included in the tip.

GPI
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

PHP started doing this crazy stuff - function aliasing. You'd have 1 function and 15 different names for it and all pointing to the same internal routine. It's REALLY confusing sometimes..

Macros sound great and if people want to stub out functions for some reason then I guess we'll have to let them - sounds like a bad idea to me though.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

Karbon wrote:PHP started doing this crazy stuff - function aliasing. You'd have 1 function and 15 different names for it and all pointing to the same internal routine. It's REALLY confusing sometimes..

Macros sound great and if people want to stub out functions for some reason then I guess we'll have to let them - sounds like a bad idea to me though.
hey, you read my mind :)

I could not say it better, Karbon writes nice English. ;)
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

I could not say it better, Karbon writes nice English.


Now that is funny! :-)

Doot!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

I don't think, that is is usefull, to create to many simple Warp-Macros. Findstring is a little bit special, because the default-name in other languages is INSTR().

(or maybe the compiler should give a special error, when instr() is used without declaration (something like:" INSTR() is not a function, linkedlist or array. Maybe you mean FindString(). Look in the manual".) (Only a crazy idea).

But macros can do more.

Best examples are simple Calculation, or small functions. In some cases it doesn't make sense to use function.

forexample: RGB()
At the moment RGB() call a function, calculate, return a value.

With a Macro it could be something like this:

Code: Select all

MACRO RGB(Red,Green,Blue)=Red+Green<<8+Blue<<16
debug RGB(10,20,30)
Which is identical to

Code: Select all

debug 10+20<<8+30<<16
And when the compiler now also calculate:

Code: Select all

debug $1e140a
In this case, nothing must be calculated on runtime -> Programm is smaller and much faster!


And Again: My primary request for a macro are things like this, NOT many names for one function. (only for ONE double for default-names in other languages, like INSTR; In the manual this macro-warper should only meanted in the findstring()-explaination.)

GPI
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Yea, my point too GPI. Macros are great but I think Fred is right in that people will abuse them. Regardless of potential abuse I'd like to see them included in PB!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Wait, I never said I won't include them and macros are very useful for tons of reasons. I just put a warning on mis-used them. It will be definitely implemented in the compiler very soon.

GPI: your idea of pointing InSTR to findstring isn't bad at all. Do you have a list of 'standard' functions differently named in PB ?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> every tip(snippet) will work if the Macro is included

True, but when people (or newbies) forget to include them, we'll start
having tonnes of replies here saying "Re-post with your macro defs!".
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

PB wrote:> every tip(snippet) will work if the Macro is included

True, but when people (or newbies) forget to include them, we'll start
having tonnes of replies here saying "Re-post with your macro defs!".
You have the same problem, when you use a userlibs in your example...
It is maybe true, that in the first time this post will come, but i think humans can learn! (OK, not all humans, but i think, that nearly all here can)
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

True that will be a problem but it's a price I'd gladly pay for macros. Seems like that's Fred's decision too so macros - here we come!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Fred wrote:GPI: your idea of pointing InSTR to findstring isn't bad at all. Do you have a list of 'standard' functions differently named in PB ?
I found out, that InStr() has a diffrent position of the values, look here:
viewtopic.php?t=8228

other names: SPC() for Space(), RND() for Random().

But at the moment: my main-problem is THIS: viewtopic.php?t=6947

GPI
Post Reply