alternate SelectElement()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Splunk
User
User
Posts: 36
Joined: Wed Apr 21, 2021 6:53 pm

alternate SelectElement()

Post by Splunk »

It would be nice to be able to address list items directly with the list index, e.g.

Code: Select all

Void$ = List(INDEX)\Period$
and not awkwardly via

Code: Select all

SelectElement(List(), INDEX)
Void$ = List()\Period$
I remember that the file handling in the earlier PureBasic versions still had the cumbersome method like "UseFile()". This was then also rationalized away. SelectElement() probably also falls into this category.

Sorry if I bother you with my suggestions. These are just things I don't like and make programming cumbersome.
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: alternate SelectElement()

Post by NicTheQuick »

+1
That would be a nice addition for syntactic sugar.

But it could also lead to the assumption lists can be handled like arrays while they are both completely different things behind the scenes, in their structure, the memory allocation and speed.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: alternate SelectElement()

Post by STARGÅTE »

Splunk wrote: Fri Mar 10, 2023 2:57 pm It would be nice to be able to address list items directly with the list index
What you describe is an Array !?
Splunk wrote: Fri Mar 10, 2023 2:57 pm I remember that the file handling in the earlier PureBasic versions still had the cumbersome method like "UseFile()". This was then also rationalized away. SelectElement() probably also falls into this category.
No this is a different story.
In earlier PureBasic versions, functions like WriteLong() and ReadLong() had no file specificator. Here is was a huge mess to read and write parallel in different files.
Linked Lists are specified by there name itself. So you can access different list simultaneously.
Adding the syntax List(INDEX) pretends the thought, you had a direct access to the element, which is not the case!
SelectElement() iterates each time through the list to find the specified element, completely different to an array.
Splunk wrote: Fri Mar 10, 2023 2:57 pm These are just things I don't like and make programming cumbersome.
An array is probably a more suitable solution.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Splunk
User
User
Posts: 36
Joined: Wed Apr 21, 2021 6:53 pm

Re: alternate SelectElement()

Post by Splunk »

@Stargate: I cannot accept your argumentation about internal handling and supposed direct access.

An INDEX argument could be handled internally by PB as SelectElement().

yes, in previous versions of PB WriteLong() etc. had no arguments between the (). And now...? 8)
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: alternate SelectElement()

Post by STARGÅTE »

Splunk wrote: Fri Mar 10, 2023 3:40 pm An INDEX argument could be handled internally by PB as SelectElement().
Yes of course. But this is no index in this way, that you have "direct" access to the element.
SelectElement() wrote:Remarks
As lists don't use an index internally, this function will jump compulsory to every element in the list until the target position is reached which will take time if the list is large.
Each time you write List(INDEX) the whole list is iterated until INDEX.
If you have a list of 10000 elements, and you access element 9999, you have 9999 comparisons and iterations.
With your syntax improvement, non-optimal codes are promoted.
I don't know if that would be in interests of the community, but this is only my opinion.

Don't understand it wrong, It is not the syntax improvement I'm against, I would also preserve you to use SelectElement() often, because of the same argumentation. In my opinion there is no need to access a list via an index, because the list can grow and shrink and the index of an element changes.
And if the list is static, then why not using an array and gain time in accessing the elements directly.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Splunk
User
User
Posts: 36
Joined: Wed Apr 21, 2021 6:53 pm

Re: alternate SelectElement()

Post by Splunk »

My dear @Stargate:
I am not concerned with speed or anything else.

Void$ = List(INDEX)\Period$

is neither slower nor faster than

SelectElement(List(), INDEX)
Void$ = List()\Period$

but List(INDEX) is a SIMPLIFICATION. Nothing else. It also does not promote non-optimal code.

If you use a List() and not an Array() (or vice versa), you have reasons to do so. And if you use the SelectElement() command, you have reasons for that too, whether fast or slow. I don't think you've never used the SelectElement() function because it's so "dangerous" or slow. You just have to know what you are doing. :wink:
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: alternate SelectElement()

Post by NicTheQuick »

It's called syntactic sugar. That's all.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Splunk
User
User
Posts: 36
Joined: Wed Apr 21, 2021 6:53 pm

Re: alternate SelectElement()

Post by Splunk »

NicTheQuick wrote: Fri Mar 10, 2023 5:55 pm It's called syntactic sugar. That's all.
Exactly
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: alternate SelectElement()

Post by STARGÅTE »

Splunk wrote: Fri Mar 10, 2023 6:08 pm
NicTheQuick wrote: Fri Mar 10, 2023 5:55 pm It's called syntactic sugar. That's all.
Exactly
Ok, I'm fine with this. We both made our point of view clear.
Splunk wrote: Fri Mar 10, 2023 5:20 pm I don't think you've never used the SelectElement() function because it's so "dangerous" or slow.
Of course I did, I would lie otherwise.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply