IMPORT Modules: why does order matter?
> Or is the programmer forced to study the import diagrams from the book to arrange the > lists by hand in the correct way? Just build the list *once*, e.g. for FPGA Oberon: Kernel, FileDir, Files, Modules, Input, Display, Viewers, Fonts, Texts, Oberon, MenuViewers, TextFrames, System, Edit, Tools ORS, ORB, ORG, ORP, ORTool Graphics, GraphicFrames, Draw, GraphTool, MacroTool, Curves, Sierpinski, Hilbert, Stars, Rectangles, Checkers ...
Andreas: imagine I write my own module Acquire which is reading some FPGA registers with direct addressing the FPGA, and writes the number to the system log via Out.Int(value). The only import would be Out. Do I need to import all the other stuff which you listed below? In previous Oberons, as well as in BlackBox, the complete import list was not needed. Is it needed now? If so, can this new feature be fixed as it does not seem friendly? Wojtek ________________________________________ From: Oberon [oberon-bounces@lists.inf.ethz.ch] on behalf of Andreas Pirklbauer [andreas_pirklbauer@yahoo.com] Sent: Saturday, March 2, 2019 1:41 PM To: ETH Oberon and related systems Subject: [Oberon] IMPORT Modules: why does order matter? > Or is the programmer forced to study the import diagrams from the book to arrange the > lists by hand in the correct way? Just build the list *once*, e.g. for FPGA Oberon: Kernel, FileDir, Files, Modules, Input, Display, Viewers, Fonts, Texts, Oberon, MenuViewers, TextFrames, System, Edit, Tools ORS, ORB, ORG, ORP, ORTool Graphics, GraphicFrames, Draw, GraphTool, MacroTool, Curves, Sierpinski, Hilbert, Stars, Rectangles, Checkers ... -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=DwICAg&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=CBGseygccK22G5EVW_cVQMxoTScL1oMi5by75dp_wuA&s=0rJum3W4lLtpwfOqasMOhrlzJjyQQVBZmqDsfGbfj8M&e=
Am 02.03.2019 um 19:50 schrieb Skulski, Wojciech <skulski@pas.rochester.edu>:
Andreas:
imagine I write my own module Acquire which is reading some FPGA registers with direct addressing the FPGA, and writes the number to the system log via Out.Int(value). The only import would be Out. Do I need to import all the other stuff which you listed below?
In previous Oberons, as well as in BlackBox, the complete import list was not needed. Is it needed now? If so, can this new feature be fixed as it does not seem friendly?
I can answer this :) No, you just need to import the modules which your modules directly uses, nothing more. But if you import several modules, say Display and Oberon, then Display needs (apparently newly) to come before Oberon, as the module directly or indirectly imports Display - according to the module hierarchy. To be clear: I am using „Oberon Core“, as available in the Mac App Store. For all I know that is based on Project Oberon 2013, and running on some RISC emulator (the RISC CPU designed for the FPGA mentioned in Niklaus Wirth‘s revised Oberon book). At least my version of Oberon is missing now the Out module. That‘s because „Oberon Core“ is a „bare minimum“ distribution (the company offering it also has a commercial offering), or the module Out has really been deemed redundant and hence been removed in „Project Oberon 2013“ (as you can use a Texts writer and append the Text to Oberon.Log - which is what I think module Out was doing in the end.) I am only mentioning this because if your „FPGA Oberon“ still has module Out then you might have a different compiler, too, and the import order might not even matter there. For example the „Oberon Core“ / Project Oberon 2013 (?) compiler I use does not even have the „numerical case“ statement implemented (which is defined for the language „Oberon 07“). So it might as well be that the compiler that I am using is not „fully feature complete“, and maybe someone took a „shortcut“ in validating the IMPORTs (because from a compiler point of view it might be easier to parse/validate „if they are in order“ - unfortunately I have not yet read Wirth‘s compiler book, shame on me ;)). So the question I still have (out of pure curiosity): * Do others actually confirm that they get the same „wrong import order“ compiler error (really at the line of the IMPORT, as soon as the first „out of order“ module is found)? * Is there a real technical (compiler) reason behind this, e.g. does it speed up compilation, greatly simplifies parsing or otherwise is just advanteous? * Or is it really to „force“ the developer in the sense of „Hey! Know your modules!“ Because if the later I don‘t think that such a „validation“ helps to write better code. As it would not „scale“. Think of importing 3rd party modules. Think of if there would be dozens - well, hundreds ;) - of modules to choose from. And you are supposed to know all their dependencies? Don‘t get me wrong, I am not trying to critisise, I am genuinely interested in the design decision here. In all simplifications done in Oberon07/2013 I do see the beauty - but not so much here yet. Cheers, Oliver
Hello Till, Am 02.03.2019 um 22:18 schrieb Till Oliver Knoll:
At least my version of Oberon is missing now the Out module. That‘s because „Oberon Core“ is a „bare minimum“ distribution (the company offering it also has a commercial offering),
I believe the differences in the commercial offering are only the supported features of the emulator (like different virtual RAM sizes or network support or HostFS support (to access files on the host from within the VM)), not in the source of the Oberon system that is running inside. But since I do not own a Mac and have therefore neither used "Oberon Core" nor "Oberon Workstation", I cannot tell for sure.
or the module Out has really been deemed redundant and hence been removed in „Project Oberon 2013“ (as you can use a Texts writer and append the Text to Oberon.Log - which is what I think module Out was doing in the end.)
There is no Module "Out" in Project Oberon 2013. See <www.projectoberon.com> or <https://www.inf.ethz.ch/personal/wirth/ProjectOberon/index.html> for all included modules. I have made a webpage with syntax highlighted annotated HTML files for the Project Oberon 2013 source files, at <https://schierlm.github.io/OberonXref/ProjectOberon2013/>. There you can also see that there is no "Out" module.
So the question I still have (out of pure curiosity):
* Do others actually confirm that they get the same „wrong import order“ compiler error (really at the line of the IMPORT, as soon as the first „out of order“ module is found)?
The error message is "invalid import order", but it does exist in Project Oberon 2013: <https://schierlm.github.io/OberonXref/ProjectOberon2013/ORB.html#L_142> Numerical case statements are not implemented there either: <https://schierlm.github.io/OberonXref/ProjectOberon2013/ORP.html#L_579>
* Is there a real technical (compiler) reason behind this, e.g. does it speed up compilation, greatly simplifies parsing or otherwise is just advanteous?
Not 100% sure, but I assume it just makes the compiler slightly simpler as it can (explicitly) import a module and (implicitly) all its dependencies while parsing the actual IMPORT statement instead of having to check the dependencies against the modules stated later to make sure that the dependencies get imported as explicit imports in the right order.
And you are supposed to know all their dependencies?
In my experience, trial and error is "fast enough", especially since when you get the error, the cursor is on the module that is imported too late, so you just successively move it further to the beginning of the line until it is accepted. But I am only toying with the Oberon system, and do not use it for anything critical (and the number of compile errors because of a missing colon in := is vastly above the number of import order errors), so your mileage may vary.
I am only mentioning this because if your „FPGA Oberon“ still has module Out then you might have a different compiler, too, and the import order might not even matter there.
I believe that in Experimental Oberon, import order does not matter, and it also supports both Numerical case statements and the Out module (as well as procedure forward declarations and some other goodies that make your life easier at the cost of making the system more complex). But Andreas can comment on that one better than me. Regards, Michael
Am 02.03.19 um 23:23 schrieb Michael Schierl:
Hello Till,
Am 02.03.2019 um 22:18 schrieb Till Oliver Knoll:
At least my version of Oberon is missing now the Out module. ...
I believe the differences in the commercial offering are only the supported features of the emulator (like different virtual RAM sizes or network support or HostFS support (to access files on the host from within the VM)),..
Yes, that is my understanding so far, too. And the actual Oberon modules shipped with "Oberon Core" are the ones as described in the 2013 revised edition of the book "Project Oberon", which I am now eagerly reading :) Available here: https://www.inf.ethz.ch/personal/wirth/ProjectOberon/index.html (and that site also lists all available modules - without module Out).
I have made a webpage with syntax highlighted annotated HTML
As an aside: don't tell anyone else, but I am mostly using Visual Studio Code to refactor my own "student's exercise source code" ("GigaDraw"). And there is an "Oberon Language Support" plugin with syntax highlighting and - beware - even code completion. Which I guess is based on some "built in heuristics and assumptions" - e.g every then and when I am still seeing procedures from Oberon 1990 when accessing some module like "Display" (e.g. the "clipped" variants are still suggested, I believe). But that's okay and is fully made up by supporting the arrow keys on the keyboard ;) (Well, probably everybody here already knew about this "Oberon Language Support" plugin - but it's nice to see that Oberon - somehow - is kept alive over all those years still :))
The error message is "invalid import order", but it does exist in Project Oberon 2013:
Yes, that's exactly the message (sorry, I was writing from my mobile phone yesterday).
* Is there a real technical (compiler) reason behind this... Not 100% sure, but I assume it just makes the compiler slightly simpler as it can (explicitly) import a module and (implicitly) all its dependencies while parsing the actual IMPORT statement ...
Then that is probably the reason. At least such a reason would be "in line" with other simplifications done in PO2013, so I'll take this as an answer then :)
And you are supposed to know all their dependencies?
In my experience, trial and error is "fast enough", especially since when you get the error, the cursor is on the module that is imported too late, so you just successively move it further to the beginning of the line until it is accepted.
Well, sure, it is not the end of the world, and once you know it you can start adding modules (and luckily Oberon is small enough to know about them still ;)) in the right order from the very beginning.
But I am only toying with the Oberon system, and do not use it for anything critical (and the number of compile errors because of a missing colon in := is vastly above the number of import order errors), so your mileage may vary.
I am in the same position, well, maybe more in the "archaeological department", trying to unearth my student's exercises ;) But I can tell you from my professional experience (which includes C/C++) that a simple = in an IF condition goes undetected far more in practise than you will do the = vs := mistake. Well, nowadays most C++ compilers spit out at least a warning when they see you doing if (a = b) {...}, but you are still free to ignore it. If you're lucky you'll notice right away in your test run. If not... well, such errors can live for a looong time ;) Anyway, I am sure the above discussion has been held here a lot already, and we all know that Oberon has a far superior syntax than most other languages ;) But still: the times that I keep adding a "superfluous" ; at the end of the "last statement" (and where the compiler is furiously bitching at me with a short "no end" compiler error) also far exceed the number that I'd wish for ;)
I believe that in Experimental Oberon, import order does not matter, and it also supports both Numerical case statements and the Out module (as well as procedure forward declarations
Well, personally I've seen people doing forward declarations, but it was almost never the case where you could not simply move the implemementation up to the "correct place" and then do without a forward declaration. In fact, people claiming that forward declarations are a good thing are mostly those that freely mix "private" and "public" methods, without any kind of (visible) sorting. They just keep adding their implementations where they see fit (mostly right in front of the other procedure/method/whatever which uses it initially, and once they realise that another procedure "up there" also requires to call it, they simply add a forward declaration out of pure lazyness). That is my experience anyway. Maybe there *are* good use cases for forward declarations. So I am just saying that I have never seen such cases yet. But yes, smooth scrolling :) I will definitively check out "Experimental Oberon" just for this alone. And the numerical case statement certainly is also useful (especially since it has been "approved" by Niklaus Wirth even, in his Oberon-07 report). Thanks a lot! Oliver
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Till Oliver Knoll Sent: Sunday, 3 March 2019 7:31 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] IMPORT Modules: why does order matter?
But still: the times that I keep adding a "superfluous" ; at the end of the "last statement" (and where the compiler is furiously bitching at me with a short "no end" compiler error) also far exceed the number that I'd wish for ;)
Using semicolon as a null *statement* after the last statement in a statement sequence *is* allowed. Pascal programmers might also be surprised to know that they can now include a semicolon as a null statement before an ELSE. What I suspect you might be trying to do is insert a semicolon before the END following a RETURN? Oberon's RETURN *statement* that could be inserted anywhere in a statement sequence was (thankfully) eliminated in Oberon-07. The RETURN clause is now bound to the end of a procedure and is followed by an *expression*. Once you understand the difference, you should be no more tempted to write RETURN a = b; than you would be tempted to write IF a = b; Regards, Chris Chris Burrows CFB Software http://www.astrobe.com
Am 03.03.19 um 11:38 schrieb Chris Burrows:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Till Oliver Knoll Sent: Sunday, 3 March 2019 7:31 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] IMPORT Modules: why does order matter?
But still: the times that I keep adding a "superfluous" ; at the end of the "last statement" (and where the compiler is furiously bitching at me with a short "no end" compiler error) also far exceed the number that I'd wish for ;)
Using semicolon as a null *statement* after the last statement in a statement sequence *is* allowed. Pascal programmers might also be surprised to know that they can now include a semicolon as a null statement before an ELSE. What I suspect you might be trying to do is insert a semicolon before the END following a RETURN?
Oberon's RETURN *statement* that could be inserted anywhere in a statement sequence was (thankfully) eliminated in Oberon-07.
Yes, I meant exactly that. Whereas it was always possible to skip the ; after the last statement, as e.g. in IF something THEN someStatement (* no ; here *) END (and was probably even considered "good style", because the compiler might even insert a "null statement" after the someStatement otherwise), the compiler now really bit me after some randomly left (back in the days) ; after the last return "statement", which is now - as you say - newly an expression (as there is no such thing as "return statements" anymore). And yes, I consider return statements in the middle of (usually also too long) functions an anti-pattern, something which I always intuitively avoided (well, not in my "GigaDraw" student exercise ;)) during my engineering career so far. And you usually have a hard time explaining to your colleagues why to avoid such "bail out in the middle of nowhere" statements. The occasional "bail out early"-return statement might be okay, at the very beginning of some function, as it might help increas code readability (by avoiding an additional nesting level). But even that I usually avoid by still going for this additional IF ... THEN nesting level. Cheers, Oliver
Am 03.03.2019 um 10:00 schrieb Till Oliver Knoll:
But I can tell you from my professional experience (which includes C/C++) that a simple = in an IF condition goes undetected far more in practise than you will do the = vs := mistake.
I can agree from JavaScript point of view. In Java it is usually an error: if statements have to be a boolean expression and "x=y" is only a boolean expression if the type of x is boolean itself; and you rarely have to compare booleans with each other (comparing a boolean with literal true or false is a warning so you tend not to write that), but in JavaScript it happens too often for me too to miss one equals sign and have weird errors (and no warning at all).
Well, personally I've seen people doing forward declarations, but it was almost never the case where you could not simply move the implemementation up to the "correct place" and then do without a forward declaration.
Doing compilers/parsers with Recursive Descent often requires mutually recursive functions. Also Sierpinski.Mod is an academic example that could benefit from forward declarations. Regards, Michael
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Till Oliver Knoll Sent: Sunday, 3 March 2019 7:48 AM To: ETH Oberon and related systems Subject: Re: [Oberon] IMPORT Modules: why does order matter?
For example the Oberon Core / Project Oberon 2013 (?) compiler I use does not even have the numerical case statement implemented (which is defined for the language Oberon 07 ).
That is consistent with Wirth's Project Oberon compiler. We have added numeric case in our Oberon-07 implementation (Astrobe for RISC5). To do this efficiently it was necessary to implement a variant of the Branch Conditional instruction in the RISC5 processor. For more information see: "Numeric CASE vs IF THEN ELSE performance" http://www.astrobe.com/forum/viewtopic.php?f=13&t=552
So it might as well be that the compiler that I am using is not fully feature complete , and maybe someone took a shortcut in validating the IMPORTs (because from a compiler point of view it might be easier to parse/validate if they are in order - unfortunately I have not yet read Wirth s compiler book, shame on me ;)).
So the question I still have (out of pure curiosity):
* Do others actually confirm that they get the same wrong import order compiler error (really at the line of the IMPORT, as soon as the first out of order module is found)?
* Is there a real technical (compiler) reason behind this, e.g. does it speed up compilation, greatly simplifies parsing or otherwise is just advanteous?
* Or is it really to force the developer in the sense of Hey! Know your modules!
Yes - I believe there are elements in all of the above that led to this implementation restriction.
From the technical point of view we have only just introduced this restriction ourselves in v7.0 of the Atrobe ARM Cortex-Mx compilers to help resolve some obscure problems reported by a user which were related to direct / indirect imports. When aliased imports are involved as well it can get very tricky.
The question of forcing the developer to 'know your modules' is more subjective. As a devil's advocate I would ask the question: Ideally, in what order should the modules be listed on an IMPORT list? 1. Alphabetic? - useful if they are long lists and you want to know if you've missed one. 2. Bottom-up? - useful if you want to know in what order you should recompile them if necessary. Also useful to get an idea what you might break if you modify any of the interfaces (you only need to potentially worry about the modules that come after the one you are modifying). 3. Random? - Useful if you are a contract programmer and ongoing maintenance of your code wasn't specified in your contract later. Also useful if you don't have a clue about what you are doing. ;-) 4. Something else? Having spent much time over many decades maintaining code bases with the source code of thousands of modules not written by me I would have been really grateful if the development system had encouraged explicit module references and some sort of ordering of imports rather than leaving it up to the programmer. A development manager should always keep in mind that in the life-cycle of software typically 10-20% of the costs are incurred by the original development whereas 80-90% of the costs are incurred maintaining it. When choosing development tools they would be wise to consider how well the tool helps to encourage good programming practices and lessen the need for themselves to 'herd cats'. Having said all that, I can see this restriction might cause some head-scratching if you are trying to port a large application from an older version of Oberon. However, (shameless plug coming) it is less of a problem in Astrobe because it includes a build tool to ensure that all imported modules are recompiled in the correct order. The output log of this makes it very obvious how to order the modules on an import list if the error should arise. And to answer your next question - no we don't have a version that runs on Apple devices :( Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
Am 03.03.19 um 00:07 schrieb Chris Burrows:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Till Oliver Knoll Sent: Sunday, 3 March 2019 7:48 AM To: ETH Oberon and related systems Subject: Re: [Oberon] IMPORT Modules: why does order matter?
For example the Oberon Core / Project Oberon 2013 (?) compiler I use does not even have the numerical case statement implemented (which is defined for the language Oberon 07 ).
That is consistent with Wirth's Project Oberon compiler. We have added numeric case in our Oberon-07 implementation (Astrobe for RISC5). To do this efficiently it was necessary to implement a variant of the Branch Conditional instruction in the RISC5 processor. For more information see:
"Numeric CASE vs IF THEN ELSE performance"
Thanks. I already knew that others had already implemented the numerical case statement. For completeness sake I also found those: https://github.com/andreaspirklbauer/Oberon-numeric-case-statement That maybe even the one that you are referring to. And it is apparently also implemented (one of the 3 proposed solutions) in "Experimental Oberon", here: https://github.com/andreaspirklbauer/Oberon-experimental
.... * Do others actually confirm that they get the same wrong import ... * Is there a real technical (compiler) reason behind this, ... * Or is it really to force the developer ... Yes - I believe there are elements in all of the above that led to this implementation restriction.
From the technical point of view we have only just introduced this restriction ourselves in v7.0 of the Atrobe ARM Cortex-Mx compilers to help resolve some obscure problems reported by a user which were related to direct / indirect imports. When aliased imports are involved as well it can get very tricky.
Okay, that falls in line with a previous reply that it may indeed greatly simplify the compiler and the validations it has to do, possibly even helping in detecting otherwise subtle missing dependencies otherse. I'll take that as an answer :)
The question of forcing the developer to 'know your modules' is more subjective. As a devil's advocate I would ask the question:
Ideally, in what order should the modules be listed on an IMPORT list?
Well, ideally there should not be any restriction at all. I am not aware of any other language/compiler which imposes such a restriction in the order of imports, including previous Oberon compilers that I know. So the decision should ultimatively be with the developer (team). I tend to import "system libraries" first, then 3rd party libraries, then my own ("what is closer to my own sources is imported last, to be closer to my code in that very source file"). But within each those blocks so far I tend to order them "per use", so if I first use module Texts, then that would be importend before Display (for example), in case I only use the Display module later in my source.
2. Bottom-up? - useful if you want to know in what order you should recompile them if necessary. Also useful to get an idea what you might break if you modify any of the interfaces (you only need to potentially worry about the modules that come after the one you are modifying).
Well, this is a valid point, too! Having the import "in the order of dependencies" indeed helps you to quickly determine the correct order in which you'd have to (re-)compile your (own) modules, too! So there is indeed a little "usability gain" for the developer when reading the code. And yes, I have seen in some Java development that they had a style guide to sort the includes alphabetically (but still kind of sorted by "JDK imports first"). But you better have an "auto-formatter" for this, or else :) (Unfortunatelly the style guide applied to loca sources was slightly different than the one on the integration server, so you'd still get rejects from integration, because of a different opinion on what would go first, e.g. "javax before java" imports or the other way round - or so I remember...
Having spent much time over many decades maintaining code bases with the source code of thousands of modules not written by me I would have been really grateful if the development system had encouraged explicit module references and some sort of ordering of imports rather than leaving it up to the programmer.
Well, in my experience the ordering was never a problem at all. In fact the import section you'd have "collapsed" anyway and not even look at it during reviews. Because if the developer forgot about some import then that's the job of the compiler to tell. So you'd focus on the actual code, and that is where it gets very quickly way more ugly than some "funny import order". ;)
no we don't have a version that runs on Apple devices :(
No worries :) That's just the computer I happen to use these days at home. But it has various "virtual machines" installed, too (including Solaris and FreeBSD), so I am not very "religious" in this aspect ;) This answers my initial question. Thanks a lot to all who contributed. Cheers, Oliver
Oliver
At least my version of Oberon is missing now the Out module
I have an Out.Mod and compiled it on FPGA. I can send it if you want. I added a simple printf() to it with support of \n, \t, %d and %x
For example the „Oberon Core“ / Project Oberon 2013 (?) compiler I use does not even have the „numerical case“ statement implemented (which is defined for the language „Oberon 07“).
I added nunerical case to the compiler without adapting the RISC-5 instruction set (in contrast to Chris‘ approach)
So the question I still have (out of pure curiosity):
* Do others actually confirm that they get the same „wrong import order“ compiler error (really at the line of the IMPORT, as soon as the first „out of order“ module is found)
Yes, I get this error as well. Fixing that would need some code. ORB.Import and ORB.ThisModule have to be adapted. Jörg
Am 03.03.19 um 01:08 schrieb Jörg Straube:
Oliver
At least my version of Oberon is missing now the Out module
I have an Out.Mod and compiled it on FPGA. I can send it if you want. I added a simple printf() to it with support of \n, \t, %d and %x
Well, my point was not so much about "how to get an Out module" (it was pretty straight forward in my case to replace the few Out calls with module Texts and Oberon.Log), but more to hightlight that it may be due to different variants of Oberon that people are using these days, and that the "invalid import order" error could hence be specific to my variant ("Oberon Core"). But as others have pointed out there is no module Out anymore in "Project Oberon 2013". But thank you anyway for the offer :)
Yes, I get this error as well. Fixing that would need some code. ORB.Import and ORB.ThisModule have to be adapted.
I don't think it is a matter of "fixing": the Oberon compiler had this "feature" already to import "in any order". So this must have been a concious design decision, and I was wondering about the "why". But yes, apparently in e.g. "Experimental Oberon" that feature is back. Thanks, Oliver
participants (6)
-
Andreas Pirklbauer -
Chris Burrows -
Jörg Straube -
Michael Schierl -
Skulski, Wojciech -
Till Oliver Knoll