Declare for Arrays, Lists, Variables, Structures

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Declare for Arrays, Lists, Variables, Structures

Post by c4s »

Maybe I missed something obvious that dismisses my feature request but I don't see why Declare only works for procedures. I think it's equally important for structures, arrays, lists etc.

Code: Select all

Structure AA
	AA.a
EndStructure

Structure AABB
	v1.AA
	v2.BB
EndStructure

Structure BB
	BB.b
EndStructure
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Declare for Arrays, Lists, Variables, Structures

Post by STARGÅTE »

Why?
Procedures can call each other, structures not!
So why?

Use this, where is the problem?

Code: Select all

Structure AA
   AA.a
EndStructure

Structure BB
   BB.b
EndStructure 

Structure AABB
   v1.AA
   v2.BB
EndStructure
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
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Declare for Arrays, Lists, Variables, Structures

Post by skywalk »

STARGÅTE wrote:Why?
Procedures can call each other, structures not!
umm, ts-soft shows otherwise :wink:
http://www.purebasic.fr/english/viewtop ... 25#p344825
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Declare for Arrays, Lists, Variables, Structures

Post by c4s »

Damnit why not? Why do we have Declare anyway? It makes coding easier!

I came across this when trying to seperate my main code file into several ones. Now I have this issue that I declare some structures in an include but want to define it in the main code file before including it because there are also variables used in the seperate file that are defined before it and so on... you don't have to understand the logic I'm trying to explain. It's just that declaring structures etc. could be handy in this case and I don't see a reason why it isn't possible.

When things are getting larger you want to have a certain code structure... In my small example I don't want reorder it because I want it like that, you know?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Declare for Arrays, Lists, Variables, Structures

Post by STARGÅTE »

Damnit why not? Why do we have Declare anyway? It makes coding easier!
No!, Declare for procedures make it run!

Struktur never locks like:

Code: Select all

Structure AA
  A.BB
EndStructure
Structure BB
  B.AA
EndStructure
Procedure can it, so here we need a Declare!


PS: for structures in PB a use my extension *.pbh so i declare all structures before

i think it is not easier to write some like:

Code: Select all

DeclareStructure BB

Structure AA
  A.BB
EndStructure
  
Structure BB
  B.i
EndStructure
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
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Declare for Arrays, Lists, Variables, Structures

Post by luis »

To answer your question: "Why do we have Declare anyway?"

It's to make code possible, not easier unfortunately.

Mutually recursive code: how can you write that without declares with a single pass compiler ?

Code: Select all

Declare 	a()
Declare 	b()

Procedure a()
 Debug "a"
 If Random(1)
  b()
 EndIf
EndProcedure

Procedure b()
 Debug "b"
 If Random(1)
  a()
 EndIf
EndProcedure

a()
The same it's not needed for data, afaik.

Anyway, even assuming they can be useful, I shudder at the idea of maintain declares for procedures AND linked list, structures, arrays. Having redundant declarations in my code it's not something I'm looking forward to, but for procedures this is a needed evil. Well, just an opinion :)
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Demivec
Addict
Addict
Posts: 4257
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Declare for Arrays, Lists, Variables, Structures

Post by Demivec »

c4s wrote:Maybe I missed something obvious that dismisses my feature request but I don't see why Declare only works for procedures. I think it's equally important for structures, arrays, lists etc.
For structures it can be done via pointers. It can cause some headaches, but it is how it can currently be accomplished.

Code: Select all

Structure AABB
  *v1.AA
  *v2.BB
EndStructure

Structure AA
  AA.a
EndStructure

Structure BB
  BB.b
EndStructure
Post Reply