Delphi Rio 10.3 Inline Vars & Consts

just write whatever you want

Delphi Rio 10.3 Inline Vars & Consts

Postby iconic » Sun Jan 13, 2019 1:27 am

iconic
 
Posts: 857
Joined: Wed Jun 08, 2005 5:08 am

Re: Delphi Rio 10.3 Inline Vars & Consts

Postby madshi » Sun Jan 13, 2019 10:07 am

It looks really weird to me, but I guess if used properly, it can help making code more readable. Especially large functions can be hard to understand if all the vars are defined at the top and when trying to understand the code you have to scroll up and down all the time to check which vars have which type.

They obviously copied this from other languages, and I'm fine with this change (after all, I don't have to use it, if I don't like it). However, as with any new language feature: Since it's only supported in the very latest Delphi version, I can't use it in anything that still has to support older Delphi versions. So for me it's mostly useless in any case...
madshi
Site Admin
 
Posts: 9931
Joined: Sun Mar 21, 2004 5:25 pm

Re: Delphi Rio 10.3 Inline Vars & Consts

Postby iconic » Sun Jan 13, 2019 7:29 pm

Madshi,

You've highlighted some very good points and I can honestly say I agree with you completely. I find non-inferred types to be a bit clumsy within loops though, see below.

Type declared explicitly and variable initialized (i1 existence is strictly within loop-only scope, which is a plus):

Code: Select all
for var i1: Integer := 1 to 10 do //


I prefer the inferred type below, looks less awkward syntactically (too bad keyword var had to stay however):

Code: Select all
for var i1 := 1 to 10 do //


As far as it being a hassle when you are working within the context of a very large function where you have to constantly check the variable declaration block... this can be annoying as you mentioned. However, I still regularly use Hungarian notation so I'm almost always aware of what the variable type is based on the naming prefix I've assigned the variable. If it's an unsigned int I'll use ul or dw prefix, for signed ints I'll use i as the prefix, if it's an int64 I'll use lli (LONGLONG integer) or perhaps i64 etc. Not everyone is pro Hungarian notation being that its use is subjective, some make the case that it makes code less readable and is messy, but personally I find it useful when I don't have to reexamine the variable declaration block and know simply by looking at the variable name what data type I am working with in the moment.

Everything considered I believe it's a step in the right direction even though it does break strict traditional Pascal conventions and rules. The language itself needs an overhaul otherwise newer promising languages with equal or better performance, more bells and whistles etc., like Rust, will leave Delphi in the dust.


--Iconic
iconic
 
Posts: 857
Joined: Wed Jun 08, 2005 5:08 am

Re: Delphi Rio 10.3 Inline Vars & Consts

Postby madshi » Sun Jan 13, 2019 7:37 pm

I like code to look more like readable text, so I'm not a big fan of using hungarian notation myself. But I don't have a problem at all if devs/code uses it.

Yeah, the loop definition looks a bit awkward, but it's definitely very nice to not have to declare loop vars at the beginning of each function! And you're right, being able to simply skip the "var" would have been nice.
madshi
Site Admin
 
Posts: 9931
Joined: Sun Mar 21, 2004 5:25 pm


Return to fun talk

Who is online

Users browsing this forum: No registered users and 2 guests

cron