Recent

Author Topic: Please make your language more freedom  (Read 37041 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Please make your language more freedom
« Reply #45 on: June 22, 2018, 06:03:52 pm »
Imagine a very long function/procedure, everytime I want to use an additional temp variable I have to jump to the var section and declare it.

This is an IDE feature. Delphi has this as ctrl-shift-V  "declare variable".

Many shorthands syntax can be better solved in IDEs/editors, something that was not available in C's years of yonder.
 

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Please make your language more freedom
« Reply #46 on: June 22, 2018, 06:15:21 pm »
Imagine a very long function/procedure, everytime I want to use an additional temp variable I have to jump to the var section and declare it.

This is an IDE feature. Delphi has this as ctrl-shift-V  "declare variable".

Many shorthands syntax can be better solved in IDEs/editors, something that was not available in C's years of yonder.

Having such IDE features is good, although if a function is that long, it should probably be rewritten as several functions.

Regarding the brevity of curly braces, I just type "b" and start entering code in the block. That is a great IDE feature! :)
« Last Edit: June 22, 2018, 06:19:15 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Please make your language more freedom
« Reply #47 on: June 22, 2018, 06:23:26 pm »
But seriously, take javascript. The results of being able to declare your var wherever you want became so complex (
http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html ), that they needed a linter https://eslint.org/docs/rules/vars-on-top

Wow! That makes me appreciate the current approach in Free Pascal even more.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: Please make your language more freedom
« Reply #48 on: June 22, 2018, 07:31:45 pm »
It's difficult for a non-pro like me to foreknow everything to declare on var section first. Imagine a very long function/procedure, everytime I want to use an additional temp variable I have to jump to the var section and declare it.

Pascal is strict, you usually need to plan it before start coding and type more (compare to some other languages). But those actually are the good things. The beauty of Pascal is its strictness makes the code easier to maintain.

Pascal is not to please novice users, many beginners give up Pascal on the learning process. They think coding in Pascal is not as easier as the others. But when you're actually programming some real project, you'll know the hardest parts are doing the maintaining and debugging. Proper planning will make the code less bugs and easier to maintain. By using Pascal, you 'force' yourself to do some simple planning by thinking what variables you will need, what data types and ranges are needed.

It's difficult for a non-pro like me to foreknow everything to declare on var section first.
Then you now should start to learn planning before touching the keyboard. In my earlier days I wrote many codes and components but most of them ended up nothing, because I didn't plan them properly. So don't repeat my mistake, always do some planning before you write the code.

Imagine a very long function/procedure, everytime I want to use an additional temp variable I have to jump to the var section and declare it.
If the function/procedure is very long, you should split it. Each of them should be kept in a screen height so you can see all the code without using page up/down. It is good for debugging and maintaining.

mercurhyo

  • Full Member
  • ***
  • Posts: 242
Re: Please make your language more freedom
« Reply #49 on: June 22, 2018, 08:54:22 pm »
pascal is the best! NEAT!
photoshop 1stS releases were in Pascal
more than 100 000 lines, easy to maintain (2 only programmers), and to understand, because of Pascal
https://github.com/amix/photoshop
my typed structured approach for 'implicit containers iterators" and "local loops blocks" is the good choice at Pascal compilers improvements.
All other approaches are from disturbed languages adaptations. Pascal do not need such/their craps
« Last Edit: June 22, 2018, 09:09:55 pm by mercurhyo »
DEO MERCHVRIO - Linux, Win10pro - Ryzen9XT 24threads + Geforce Rtx 3080SUPRIM
god of financial gain, commerce, eloquence (and thus poetry), messages, communication (including divination), travelers, boundaries, luck, trickery and thieves; he also serves as the guide of souls to the underworld

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Please make your language more freedom
« Reply #50 on: June 22, 2018, 10:26:43 pm »
@mercurhyo
You are user piGrimm, aren't you?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Please make your language more freedom
« Reply #51 on: June 22, 2018, 10:32:28 pm »
Maybe I misunderstood, but Delphi and FPC output 9 at the end.
The point I was trying to make is exactly what you describe: whatever happens do nit rely on the value, although when you use break or exit the variable seems preserved.
In both dialects! - it is also documented for FreePascal - the value is undefined. Except - for some reason - when you break out of the loop. For FPC that is somewhat documented.
I think that part of the documentation should be removed. If you need the value, re-assign to another variable at the point from inside the loop that you want to break out of.
The 9-10 issue demonstrates exactly that.... the "if i = 9 then break;" tries to give an example to test against both Delphi and FPC behavior.
I think - if you agree - we should ask Michael to remove the last part of the quote from the documentation, because the behavior is deterministic (by accident) and not based on the language at all.
This is not by accident, but on purpose in both Delphi and FPC and stems back from TP times.

To quote the Delphi help:
Quote
After the for statement terminates (provided this was not forced by a Break or an Exit procedure), the value of counter is undefined.

Even ISO Standard Pascal contains this (section 6.8.3.9):
Quote
After a for-statement is executed, other than being left by a goto-statement, the control-variable shall be undefined.

FPC was recently even fixed to handle this correctly when loop unrolling is enabled (namely by not unrolling them in such cases).

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Please make your language more freedom
« Reply #52 on: June 22, 2018, 10:47:53 pm »
[]After a for-statement is executed, other than being left by a goto-statement, the control-variable shall be undefined.
FPC was recently even fixed to handle this correctly when loop unrolling is enabled (namely by not unrolling them in such cases).
[/quote]
Well the premature exits are not in all cases goto and certainly not statements (goto is), but thanks for the explanation.
You may have added that break and continue are  overrideable and as such are goto's?
Specialize a type, not a var.

mercurhyo

  • Full Member
  • ***
  • Posts: 242
Re: Please make your language more freedom
« Reply #53 on: June 22, 2018, 11:00:12 pm »
@mercurhyo
You are user piGrimm, aren't you?
no
DEO MERCHVRIO - Linux, Win10pro - Ryzen9XT 24threads + Geforce Rtx 3080SUPRIM
god of financial gain, commerce, eloquence (and thus poetry), messages, communication (including divination), travelers, boundaries, luck, trickery and thieves; he also serves as the guide of souls to the underworld

mercurhyo

  • Full Member
  • ***
  • Posts: 242
Re: Please make your language more freedom
« Reply #54 on: June 22, 2018, 11:38:24 pm »
@kupferstecher
to let you know, I was gulyone here, few years ago... I got banned for nonsensed reasons, and just decided to come back... we'll see  :D :D :D

I'm sure that if I got banned I'm never the looser one, due to my experience ha ha ha
« Last Edit: June 22, 2018, 11:44:34 pm by mercurhyo »
DEO MERCHVRIO - Linux, Win10pro - Ryzen9XT 24threads + Geforce Rtx 3080SUPRIM
god of financial gain, commerce, eloquence (and thus poetry), messages, communication (including divination), travelers, boundaries, luck, trickery and thieves; he also serves as the guide of souls to the underworld

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Please make your language more freedom
« Reply #55 on: June 23, 2018, 12:32:11 am »
Imagine a very long function/procedure, everytime I want to use an additional temp variable I have to jump to the var section and declare it.

This is what we refer to as "1st world problems".  Seriously, this is not a good reason to undermine the deliberate structure of a programming language to introduce a highly questionable convenience that is almost certainly going to result in debugging and troubleshooting issues 100x more times than it will generate true value or benefit.

The use of a structured language requires structured thinking.   What you are advocating is anything but...

You can keep the variable declaration area in a split screen and update it whenever you need to.    Or any other number of techniques... 
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

fred

  • Full Member
  • ***
  • Posts: 201
Re: Please make your language more freedom
« Reply #56 on: June 23, 2018, 11:01:24 am »
About the value of a for variable i remember something, i have used Omegasoft Pascal on OS-9/68000, from the older manual: Omegasoft 6809 Pascal Version 2 Language Handbook
--
FOR STATEMENT
for~statement = for variable := expression (to | downto)
expression do statement

( description of to and downto )

In either case if the statement is never executed then the
control variable will have the value of the first expression. If
the for statement finishes normally then the control variable
will have the value of the second expression.
--

So in any case the for variable had a defined value.

It had "Break" but was called "exit" and it could exit multiple loops like "exit(2)" to exit/break 2 inner loops.
I always liked the 68k compiler, it had static vars and external units, we used to look at the assembly code the see what would be faster or smaller :)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Please make your language more freedom
« Reply #57 on: June 23, 2018, 01:42:55 pm »
[]After a for-statement is executed, other than being left by a goto-statement, the control-variable shall be undefined.
FPC was recently even fixed to handle this correctly when loop unrolling is enabled (namely by not unrolling them in such cases).
Well the premature exits are not in all cases goto and certainly not statements (goto is), but thanks for the explanation.
You may have added that break and continue are  overrideable and as such are goto's?
[/quote]
What do you mean with overrideable? That you can define identifiers with the same name? If so than those are ignored. Only the correct control flow statements (continue, break, exit, raise*, goto and labels) are checked for. In addition to that FPC checks whether the variable is accessed outside the scope of the loop (e.g. a nested function).

* the compiler only checks for raise statements inside the loop, not in functions called

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Please make your language more freedom
« Reply #58 on: June 23, 2018, 05:10:47 pm »
Something I saw in my C days could be nice..

For COUNTER:Integer := 1 to Whatever do....


 That's not exactly like in C but it makes sure the COUNTER variable never exists out side
the control loop.

 I am pretty sure FPC does not support that, yet ;)
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Please make your language more freedom
« Reply #59 on: June 23, 2018, 05:39:56 pm »
Something I saw in my C days could be nice..

For COUNTER:Integer := 1 to Whatever do....


 That's not exactly like in C but it makes sure the COUNTER variable never exists out side
the control loop.

 I am pretty sure FPC does not support that, yet ;)

neither does it support:
Code: Pascal  [Select][+][-]
  1.   if condition then begin
  2.     a:= 1;
  3.     DoSomethingWith(a);
  4.   end;
  5.   // a may be undefined... And yet you can access it
  6.  

Or any other situation where a variable is only used for a subset of the code of a procedure.
It just isn't part of (proper) Pascal.

This discussion is a bit, like going to a javascript forum, and ask if they can introduce strictly typed variables, and abandon none typed vars. That wouldn't be javascript.
Different languages, different concepts.

 

TinyPortal © 2005-2018