Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
On 2016-06-22 18:18, Dennis Poon wrote: > can we do it in descending order without a user defined enumerator? Not as far as I know - I believe it is a one directional iterator (or so the interface suggests). There are tons of limitations with the for..in construct. Years back I implemented an iterator interface (based on Java definition of iterators) with multiple implementations for various container classes I use often. I can iterate forward, backwards, use a regex to filter (skip) what gets iterated etc. And using the factory method I can request an iterator instance with ease, and even register more iterators if needed. So much more flexible [personal opinion]. I've written an article about it some years back: http://geldenhuys.co.uk/articles/ Look for the “Iterator Pattern” article and sample code. Regards, Graeme ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
I saw your document on for x in ListX loop and would like to reconfirm that it is always iterated in ascending order, right? can we do it in descending order without a user defined enumerator? i.e. for simple enumerated type, is there a construct to iterate through it in descending order? Dennis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
Am 2016-06-21 um 17:16 schrieb Sven Barth: > It was decided some time ago when mode Delphi was switched to H+ (due to Delphi compatibility) that mode ObjFPC won't be switched, cause for that mode we value backwards compatibility higher than the user not having to write a switch. This is quite short-sighted: It's not only the work of writing a compiler switch. You also have to *know* (think) about it. There are so many compiler switches and if we end up with the situation that all new users have to spend a day to make their program work as the grandious feature list of some FPC page told them then something is wrong. Those who are already familiar with all the details have much less work to just add a compiler switch to their existing projects (if needed) and it would be necessary only once on a certain FPC version when this default changes. Now we need to tell each new user that he has to change the (default) settings to get a "modern" Pascal compiler because "out of the box" it is a very old one. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
Am 21.06.2016 15:21 schrieb "Michalis Kamburelis": > > 2016-06-21 15:03 GMT+02:00 Sven Barth : > > Am 21.06.2016 12:31 schrieb "Michalis Kamburelis" > > : > >> Current FPC defaults: > >> > >> - Help people who except the {$mode fpc} to be default (so they write > >> code without classes and a lot of other new features), > >> - Or people who expect that string is by default ShortString (limited > >> to 255 chars). > > > > One might argue about changing the default mode, but changing the default > > String type of mode ObjFPC will very likely result in compilation or runtime > > errors (probably even in the compiler itself) which is something we tend to > > avoid without good reasons. At the very least there will be performance > > differences which - depending on the code - might be noticeable as well. > > > > These errors and differences will be only felt by projects that use > {$mode objfpc} but assume that string = ShortString (and they don't > use {$H-} explicitly). I don't think it would apply to too many > projects? Compiler and RTL are two examples. > And if we do it in some major version, with proper release notes, like > Mr Bee proposes, these projects would have plenty of time to adjust > their compilation scripts / config files. They could just add "-Sh-" > or "{$H-}" and be OK, for both past and future FPC versions. It was decided some time ago when mode Delphi was switched to H+ (due to Delphi compatibility) that mode ObjFPC won't be switched, cause for that mode we value backwards compatibility higher than the user not having to write a switch. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
2016-06-21 15:03 GMT+02:00 Sven Barth: > Am 21.06.2016 12:31 schrieb "Michalis Kamburelis" > : >> Current FPC defaults: >> >> - Help people who except the {$mode fpc} to be default (so they write >> code without classes and a lot of other new features), >> - Or people who expect that string is by default ShortString (limited >> to 255 chars). > > One might argue about changing the default mode, but changing the default > String type of mode ObjFPC will very likely result in compilation or runtime > errors (probably even in the compiler itself) which is something we tend to > avoid without good reasons. At the very least there will be performance > differences which - depending on the code - might be noticeable as well. > These errors and differences will be only felt by projects that use {$mode objfpc} but assume that string = ShortString (and they don't use {$H-} explicitly). I don't think it would apply to too many projects? And if we do it in some major version, with proper release notes, like Mr Bee proposes, these projects would have plenty of time to adjust their compilation scripts / config files. They could just add "-Sh-" or "{$H-}" and be OK, for both past and future FPC versions. Regards, Michalis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
Am 21.06.2016 12:31 schrieb "Michalis Kamburelis": > Current FPC defaults: > > - Help people who except the {$mode fpc} to be default (so they write > code without classes and a lot of other new features), > - Or people who expect that string is by default ShortString (limited > to 255 chars). One might argue about changing the default mode, but changing the default String type of mode ObjFPC will very likely result in compilation or runtime errors (probably even in the compiler itself) which is something we tend to avoid without good reasons. At the very least there will be performance differences which - depending on the code - might be noticeable as well. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
>> I even expect a bit further. These {$MODE OBJFPC}, {$H+}, and {$J-} >> directives should be the *default* directives for every new FPC >> programs/units. We're now using Free Pascal compiler on 2016. Why do we need >> to explicitly declare Free Pascal mode in a Free Pascal program? In 21st >> century, our string should not be limited to 255 chars anymore. And what the >> hell is "writable constant"? It's contradictio in terminis. :) > > We have a strong focus on backwards compatibility, so the default mode stays > "fpc" and changing a modes' default settings would also affect backwards > compatibility. > Maintaining compatibility is usually a compromise. I feel that in this case, maintaining such compatibility hurts more than it helps. It is of course my opinion, biased by the kind of code I write, and by the programmers I talk with (many of whom don't know Pascal, but know Java, C# or other OOP languages). Current FPC defaults: - Help people who except the {$mode fpc} to be default (so they write code without classes and a lot of other new features), - Or people who expect that string is by default ShortString (limited to 255 chars). I think that the majority of people use now suitable command-line options, or directives, to change FPC mode to something more modern ({$mode objfpc} or {$mode delphi}, and {$H+}). So changing the defaults will not hurt them. Sure, I don't have any hard data to back it up, I don't know how much is "majority". But this applies at least to all Lazarus users that have these settings "by default". Again, this is just my opinion, but I would say that breaking compatibility in this case is warranted. Making objfpc the default mode, and making $H+ the default in objfpc mode, before the fpc.cfg is read (so it applies to everyone, and can be overridden by fpc.cfg or command-line later) would be a nice thing. (Making {$J-} would be a cool bonus, but I don't dream about it, as it could admittedly break more recent code.) In http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html I decided to just write {$mode objfpc}{$H+}{$J-} // Just use this line in all modern sources at the beginning of a first "hello world" example. And I never explain the reason for this line, I just repeat it in all examples (that are full programs/units). That's an ugly solution, but I just couldn't see a better one. It doesn't sound nice to explain that: - otherwise, they don't have classes ("why are classes disabled?"), - otherwise their stings are limited to 255 ("are you sure this is a modern language?"), - and otherwise their constants are not necessarily constant ("what?") ... It's not a good learning experience, if you have to learn about so many historical things when you learn to write a first Pascal program. And these things are already fixed -- just the defaults are old. Regards, Michalis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
Hi, On Tue, 21 Jun 2016, Mr Bee wrote: > > Maybe a little bit offtopic, but I have a question regarding the > >compiler directives: is there a way to tell Lazarus to use these > >directives in every new unit? No clue about Lazarus, but one can put -mOBJFPC in his compiler config file (same with other modes), and tell Lazarus somehow to use that config file. I'm positive that it's possible and that changes the default. Same with a lot of other modeswitches or default-changers, if you don't wanna pollute all your sources with such switches, put it in your config file. Just don't forget to document these options for your project's build system. (And if you use components which expects other modes (Delphi is pretty common), you might need to add the modeswitch to them instead...) Charlie___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
Am 21.06.2016 08:58 schrieb "Mr Bee": > > > Maybe a little bit offtopic, but I have a question regarding the compiler directives: is there a way to tell Lazarus to use these directives in every new unit? > > I even expect a bit further. These {$MODE OBJFPC}, {$H+}, and {$J-} directives should be the *default* directives for every new FPC programs/units. We're now using Free Pascal compiler on 2016. Why do we need to explicitly declare Free Pascal mode in a Free Pascal program? In 21st century, our string should not be limited to 255 chars anymore. And what the hell is "writable constant"? It's contradictio in terminis. :) We have a strong focus on backwards compatibility, so the default mode stays "fpc" and changing a modes' default settings would also affect backwards compatibility. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
> Maybe a little bit offtopic, but I have a question regarding the compiler >directives: is there a way to tell Lazarus to use these directives in every >new unit? I even expect a bit further. These {$MODE OBJFPC}, {$H+}, and {$J-} >directives should be the *default* directives for every new FPC >programs/units. We're now using Free Pascal compiler on 2016. Why do we need >to explicitly declare Free Pascal mode in a Free Pascal program? In 21st >century, our string should not be limited to 255 chars anymore. And what the >hell is "writable constant"? It's contradictio in terminis. :) If somehow someone want to deals with those things, let them use the appropriate directives explicitly. But for most programs we build today, those things should be the default. –Mr Bee Pada Selasa, 21 Juni 2016 13:15, Marc Hanischmenulis: Thanks Michalis for your excellent work! It's very important to left the early 90s associated with Pascal programming behind us and to encourage new developers to have a look onto the modern aspects of Object Pascal! Maybe a little bit offtopic, but I have a question regarding the compiler directives: is there a way to tell Lazarus to use these directives in every new unit? Best regards,Marc 2016-06-21 7:47 GMT+02:00 Michalis Kamburelis : 2016-06-20 5:31 GMT+02:00 Mr Bee : [...] > I have a little suggestion though. I prefer to use {$J-} directive in my > Pascal program. I think it encourages good programming practice in Pascal. > The {$J-} means constant is a constant no matter how you declare it. To bad > FPC is still using {$J+} as the default even in the {$MODE OBJFPC}, which > means a constant becomes a variable once you include the data type > eventhough it's declared within a 'const' block. CMIIW. > Ouch. For some reason, I thought that {$J-} is the default in {$mode objfpc} since years, and we have left that mistake behind us. Quick test showed me that I was mistaken. This makes a *lot* of my code less safe that I assumed, as in many recent projects I didn't bother to explicitly use {$J-}. This is an excellent suggestion then, thank you. I updated the document to encourage everywhere doing {$mode objfpc}{$H+}{$J-} at the beginning. I definitely *do not want* to explain to any new programmer what a "writeable constant" is... This concept should remain buried:) Regards, Michalis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers
> I definitely *do not want* to explain to any new programmer what a "writeable >constant" is... This concept should remain buried :) Exactly! I also don't >understand why the {$MODE OBJFPC} uses the {$J+} as the default. :) –Mr Bee Pada Selasa, 21 Juni 2016 12:47, Michalis Kamburelismenulis: 2016-06-20 5:31 GMT+02:00 Mr Bee : [...] > I have a little suggestion though. I prefer to use {$J-} directive in my > Pascal program. I think it encourages good programming practice in Pascal. > The {$J-} means constant is a constant no matter how you declare it. To bad > FPC is still using {$J+} as the default even in the {$MODE OBJFPC}, which > means a constant becomes a variable once you include the data type > eventhough it's declared within a 'const' block. CMIIW. > Ouch. For some reason, I thought that {$J-} is the default in {$mode objfpc} since years, and we have left that mistake behind us. Quick test showed me that I was mistaken. This makes a *lot* of my code less safe that I assumed, as in many recent projects I didn't bother to explicitly use {$J-}. This is an excellent suggestion then, thank you. I updated the document to encourage everywhere doing {$mode objfpc}{$H+}{$J-} at the beginning. I definitely *do not want* to explain to any new programmer what a "writeable constant" is... This concept should remain buried:) Regards, Michalis ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal