Declaration of structures in the module

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Declaration of structures in the module

Post by luis »

freak wrote:The rule that things must be declared before they are used has existed since the beginning (even before the Declare keyword even existed).
I understand declaring solve problems and make for a simpler compiler, and sometimes easier to follow code.
But this isn't a rule. It's a necessity. Maybe a necessity you happen to like. In fact there is not a rule in PB stating I must declare every procedure before I define it.
There is not.
It's just a necessity because forward referencing a procedure before its definition pose a problem for the compiler, since it's a single pass compiler.
freak wrote: And it is a useful one too: While it forces you to write a little more it makes the code easier to understand by humans.
In case of the declare for procedure it makes also for redundancy and the need to keep the same information updated in two places.
I for one I would do happily without it, since I don't go to examine the declare if I want to know what a forward referenced procedure does.
I jump to its body (sound like a pervert).

freak wrote: Hard to understand compiler behavior leads to more coding errors. I prefer a little more typing in this case.
This is something I understand, I can relate to and I mentioned often in my posts. Even if I would prefer to strike for balance.

Anyway all this doesn't answer my question:

Are you telling me you added the requirement of declaring procedures (and not always, mind you) because you wanted to and not because the compiler is single pass ?

And if the answer is yes, how could you have avoid it ?
"Have you tried turning it off and on again ?"
A little PureBasic review
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Declaration of structures in the module

Post by freak »

luis wrote:
freak wrote:The rule that things must be declared before they are used has existed since the beginning (even before the Declare keyword even existed).
I understand declaring solve problems and make for a simpler compiler, and sometimes easier to follow code.
But this isn't a rule. It's a necessity. In fact there is not a rule in PB stating I must declare every procedure before I define it.
There is not.
It's just a necessity because forward referencing a procedure before its definition pose a problem for the compiler, since it's a single pass compiler.
It is a syntax rule. Without it, compiler functions like Defined() or Macros become a lot more complex.
luis wrote:Are you telling me you added the requirement of declaring procedures (and not always, mind you) because you wanted to and not because the compiler is single pass ?

And if the answer is yes, how could you have avoid it ?
Maybe originally it was to keep the compiler simple. What i am trying to tell you though is that i would not change it anymore, even if the compiler was rewritten from scratch. It is essential as a syntax rule now, not as a compiler limitation. So the whole discussion about one-pass/two-pass is moot.
quidquid Latine dictum sit altum videtur
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Declaration of structures in the module

Post by luis »

freak wrote: Maybe originally it was to keep the compiler simple.
I will read this as: because the compiler was single pass :)
freak wrote: What i am trying to tell you though is that i would not change it anymore, even if the compiler was rewritten from scratch. It is essential as a syntax rule now, not as a compiler limitation. So the whole discussion about one-pass/two-pass is moot.
OK, it's something I can understand.

Thank you
"Have you tried turning it off and on again ?"
A little PureBasic review
User_Russian
Addict
Addict
Posts: 1518
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Declaration of structures in the module

Post by User_Russian »

freak wrote:And no, we will not add a way to have a structure with half hidden and not hidden elements. That is just messy.
In my opinion, messy is the presence of a separate module, only to hide the structures (as in your example), or the public announcement multiple of structures that should not be visible (accessible) from the outside of the module.
This artificial restriction, which can easily be avoided by adding the keyword Public.
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Declaration of structures in the module

Post by BorisTheOld »

freak wrote:The rule that things must be declared before they are used........And it is a useful one too: While it forces you to write a little more it makes the code easier to understand by humans........I for one find this rule very useful.
I'm afraid I don't find this feature useful at all.

We write well structured, well documented code -- we don't need 20,000 unnecessary statements cluttering our code, as is the case for one of our larger applications. By the clever use of programming standards we know where everything is in our code. We don't need declare statements to "assist" us.

One reason that I don't plan to use modules is the requirement that we use DeclareModule for identifying "public" procedures. A simple "Public" attribute on the procedure statement would be much better. The requirement to use DeclareModule just creates more duplicate code to maintain. I estimate that we already dedicate about 3-5% of our code to procedure declare statements. We don't need even more.

Having to duplicate declarations is a relic from the dark ages of programming.

By the way, another major Basic compiler recently did away with the need to declare procedures and life suddenly became much more simple.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Declaration of structures in the module

Post by luis »

@boristheold

As I said above I certainly agree with you about the declares, but as freak explained they are probably so much relied upon by the compiler now they could not easily removed anymore. Anyway I don't want to beat a dead horse again as I understand his point of view. I was only contesting a certain statement :)

About the modules, I quote myself from another thread:
...
the interface is part of the module concept. It's somewhat similar to prototype or declares, and it's useful when your code must interface with the module, so you just need to have the interface "handy" and you can write your code without even seeing the module implementation. The module can be 10000 lines, the interface maybe 50. If one module need to connect to another, again including the interface give to the former all the info it needs to use the latter. Moreover the compiler has a lot less work to do since it doesn't need to "build" the interface from the scope qualifiers buried in the code. And if in a remote future PB would ever permit to generate binary code for the modules (unlikely) again the interface would be absolutely necessary.
So while I agree the procedure's declares are just a pain on the ass (something that will not change), I'm not so quick to judge the declaremodule section the same way.
Last edited by luis on Thu Jul 04, 2013 5:43 pm, edited 1 time in total.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Declaration of structures in the module

Post by skywalk »

Purebasic is not more elegant with even more Declares! :cry:
The single pass compiler could build the module interface automatically checking for a 'Public' keyword.

I don't understand the "next step" for modules in a binary format other than dll or exe?
And if I am mistaken, when I create a dll, PB creates a lib file which I can import.
When would I ever need a text based interface of declares for my modules?
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: Declaration of structures in the module

Post by c4s »

Regarding the discussed DeclareModule I'm with luis (and the PB implementation) : The "interface" helps separating the publicly available procedures etc. from the actual implementation - which is great!
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Declaration of structures in the module

Post by luis »

skywalk wrote: I don't understand the "next step" for modules in a binary format other than dll or exe?
For example an object file -> http://en.wikipedia.org/wiki/Object_file, or something similar.
This is probably a purely academic talk however in case of PB.
skywalk wrote: And if I am mistaken, when I create a dll, PB creates a lib file which I can import.
When would I ever need a text based interface of declares for my modules?
Exactly. You can IMPORT from it, and how do you do it ? By typing some text specifying the prototype of the procedures you want to import from the import library.

OK, this is my last post here about this topic since we are diluting the original issue by user_russian.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply