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.

Comments

  1. seems like someone wants CSharp or Swift in Delphi.
    in Jarvis voice : that ain't gonna happen.

    ReplyDelete
  2. I use functions when I need functions, and procedures when I don't. That's my distinct method. I don't miss 'subroutine' either.

    ReplyDelete
  3. Oxygene has only method keyword. It has also great language enhancments, which would be nice to have in delphi as well.

    ReplyDelete
  4. A long time ago I've proposed the method keyword to declare helpers

    method Integer.AsString: string;
    begin
    Result := IntToStr(Self);
    end;

    ReplyDelete
  5. But a free function (or procedure) is not a method...

    ReplyDelete
  6. But why stop there? Maybe the method keyword could be omitted entirely.

    TFoo.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) {
    //
    }
    }

    ReplyDelete
  7. '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.

    ReplyDelete
  8. Chris 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

    ReplyDelete
  9. This would be rather useless change, for no real benefits.

    ReplyDelete
  10. Dalija Prasnikar I don't see it as useless change, if it is why would RemObjects done this in Oxygene language :D

    ReplyDelete
  11. Horá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'.

    ReplyDelete
  12. Chris Rolliston How you fell about this?:
    method 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.

    ReplyDelete
  13. 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.

    In 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.

    ReplyDelete
  14. Paul TOTH​ F2 to rename is in CNWizards expert, it is a great feature

    ReplyDelete
  15. Horá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.

    ReplyDelete
  16. Horácio Filho Why RemObjects introduced it? Ask them.

    As 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.

    ReplyDelete
  17. Dalija Prasnikar It is not to replace but for live together :D People would still possible to use function and procedure :D

    ReplyDelete
  18. Ville 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.

    ReplyDelete
  19. Attila 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
  20. "Auto initializing" local vars will slow down execution. Besides it's completely useless

    ReplyDelete
  21. Horá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.

    ReplyDelete
  22. Agustin Ortu I tend to disagree, but local variable initialization could bypass this need 😁.

    ReplyDelete
  23. Horá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.

    On 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).

    ReplyDelete
  24. 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.

    ReplyDelete
  25. Horá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.

    The 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?"

    ReplyDelete
  26. Agustin Ortu - the default value should be zero of course, just like it is for integer fields and integer global variables.
    Attila Kovacs - the fact most but not all things are zero-initialised is, from a language POV, an arbitrary implementation detail.

    ReplyDelete
  27. Chris Rolliston​ what's the benefit?

    ReplyDelete
  28. Attila Kovacs Erm, do you hate zero-initialisation of fields too? Didn't have to be that way (e.g. old-style objects).
    Agustin 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.

    ReplyDelete
  29. 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

Post a Comment