Does anyone feel necessary introduce method keyword to live together procedure/function keywords? Or even have functions without return type? These days the distinction between procedure and function nomenclature no longer exist.
Does anyone feel necessary introduce method keyword to live together procedure/function keywords? Or even have functions without return type? These days the distinction between procedure and function nomenclature no longer exist.
Sorry Stefan Glienke 😢.
ReplyDeleteyawn
ReplyDeleteNo
ReplyDeleteseems like someone wants CSharp or Swift in Delphi.
ReplyDeletein Jarvis voice : that ain't gonna happen.
I use functions when I need functions, and procedures when I don't. That's my distinct method. I don't miss 'subroutine' either.
ReplyDeleteOxygene has only method keyword. It has also great language enhancments, which would be nice to have in delphi as well.
ReplyDeleteA long time ago I've proposed the method keyword to declare helpers
ReplyDeletemethod Integer.AsString: string;
begin
Result := IntToStr(Self);
end;
But a free function (or procedure) is not a method...
ReplyDeleteBut why stop there? Maybe the method keyword could be omitted entirely.
ReplyDeleteTFoo.GetBar(x:integer):string;
begin
//
end;
And maybe we could switch argument:type:
string TFoo.GetBar(integer x);
begin
//
end;
and use curly braces instead:
string TFoo.GetBar(integer x) {
//
}
And maybe this can be embedded in the class definition:
class TFoo {
string GetBar(integer x) {
//
}
}
'These days the distiction between procedure and function nomenclature no longer exist.' How does it no longer exist...? There remains a fundamental difference in using a method that returns a value and a method that doesn't - if the former is the case and you use it just like a procedure, then the design is likely dodgy.
ReplyDeleteChris Rolliston What I meant by 'These days the distinction between procedure and function nomenclature no longer exist.' is that I won't see other languages using procedure/function keywords, the notion of procedure get extended to a function that doesn't return a value, now all is called function :D
ReplyDeleteThis would be rather useless change, for no real benefits.
ReplyDeleteDalija Prasnikar I don't see it as useless change, if it is why would RemObjects done this in Oxygene language :D
ReplyDeleteHorácio Filho Last time I looked, Java and C# still had 'void' methods, which (IMO) is just a more obscure way of expressing what Pascal calls a 'procedure'.
ReplyDeleteChris Rolliston How you fell about this?:
ReplyDeletemethod MyMethodName(aParameter: String; aNotherParameter: Integer): Boolean;
method MyClass.IncrementCount(aBy: Int32);
Also there is other things I don't like in the language, Result variable is cached between calls :(, I just saw a lot of bugs in Quality Portal caused by this behaviour, some of these by Embarcadero itself. Local variables are not initialized with their default value, just for managed types :( You won't see this kind of behaviour in any of those popular languages, if the idea is to attract new developers the language should behave like others as well.
Horácio Filho what could be just fine is shortcuts (like in Eclipse) that let you change procedure to function when you add a result type. And the same thing to change the implementation part according to a change in the interface part.
ReplyDeleteIn fact, what would be very cool it a inline editor when you hit F2 to rename a variable (everywhere), change the parameter of a method (same time i the interface and implementation), and fnally that allow to type a multilined string in a inline memo before putting nasty "#13#10 +" in the code :)
and all this are just IDE features that do not change anything in the compiler.
Paul TOTH F2 to rename is in CNWizards expert, it is a great feature
ReplyDeleteHorácio Filho Local variables are not initialized with default values in any native language that I know of. Compare with C++. I don't want Delphi to turn into Java :-). It is better to make sure the compiler warns if you try to use a variable before it has been assigned.
ReplyDeleteHorácio Filho Why RemObjects introduced it? Ask them.
ReplyDeleteAs far as useless is concerned... function and procedure are serving their purpose just fine. Ask yourself what would we gain with method besides backward incompatibility? What great functionality would we get... None.
If we had method from the start, I would not care... but introducing change just for the purpose of the change... that is useless.
Dalija Prasnikar It is not to replace but for live together :D People would still possible to use function and procedure :D
ReplyDeleteVille Krumlinde No longer in these days, newer C++ versions already initialize local variables with their default values (as far as know :D). A compiler switch could resolve this question. I don't see considered overhead adopting this and this won't make Delphi Java-like.
ReplyDeleteAttila Kovacs It looks pretty amazing, I didn't know this possibility :D Thanks a lot man :D Using only function is better for me.
ReplyDelete"Auto initializing" local vars will slow down execution. Besides it's completely useless
ReplyDeleteHorácio Filho C++ does not autoinitialize local variables of primitive types (int, float, char etc). For local vars that are classes they initialize with a call to constructor. In C# it is a compiler error to try to use a local variable before it has been assigned.
ReplyDeleteAgustin Ortu I tend to disagree, but local variable initialization could bypass this need 😁.
ReplyDeleteHorácio Filho 'How you fell about this?' - useful 'at a glance' information has been lost, since my eye has to follow through to the end of the method declaration to see whether calling it involves an expression or simply a statement. That said, if 'method' was the current syntax, I wouldn't be advocating changing it to procedure/function for the reason Dalija gives.
ReplyDeleteOn Result, well that's not 'cached', it's just turned into a 'var' parameter. Personally I'd quite like it to be an 'out' one instead, since the current situation means failing to assign a Result variable that has a managed type isn't picked up by the compiler (where it is for non-managed types).
Ville Krumlinde 'Local variables are not initialized with default values in any native language that I know of.' How about Delphi: all local variables with a managed type are zero-initialised. The COM-based VB (as found in Office VBA to the present day) also zero-initialised everything.
ReplyDeleteHorácio Filho what should be the default value for Integer? What should be for Single/Double/Extended? What about currency? All them zero? Search your code base. Do you always initialize a local numeric var to zero? Surely you don't.
ReplyDeleteThe programmer should explicity set a meaningful value before the var is used. Everything else is else a waste of cpu cycles and "and again, what was the default value for XXX? should I live with that or perhaps set a proper value?"
Agustin Ortu - the default value should be zero of course, just like it is for integer fields and integer global variables.
ReplyDeleteAttila Kovacs - the fact most but not all things are zero-initialised is, from a language POV, an arbitrary implementation detail.
Chris Rolliston what's the benefit?
ReplyDeleteAttila Kovacs Erm, do you hate zero-initialisation of fields too? Didn't have to be that way (e.g. old-style objects).
ReplyDeleteAgustin Ortu Consistency, although not sure why you think I'm advocating it especially. I was just disagreeing that wanting a default gives rise the question of what the default should be, as that's already well-defined.
If you don't initialize managed fields, how can you tell if it's pointing to garbage or not? How can the ref count know if it should or not dispose the data? It's not a matter of consistency, it's a matter of using and mixing different memory paradigms
ReplyDelete