Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Naming - Creating objects.

  1. #1

    Naming - Creating objects.

    Code:
    var
    Tpar = class
    // data
    // constructor, destructor, etc.
    end;
    
     
    procedure test;
    begin
    
    par_001        := tpar.Create;
    foo_x          := tpar.Create;
    nice_weather   := tpar.Create;
    
    
    end;
    Why isn't this implemented, it's much easier.
    Why do I have to tell the compiler what names I will use in advance. It strikes me as being a bit.. stupid. Why isn't compiler smart enough to recgnize a creation of an object and do the rest.


    Now, I am forced to use only new () and Dispose () (the old fashioned way), because I don't want the compiler to know what instances i'm going to use.
    Marmin^.Style

  2. #2

    Re: Naming - Creating objects.

    Quote Originally Posted by marmin
    Why isn't this implemented, it's much easier.
    This what? Maybe if you tell what you are puzzling over we might be able to answer questions. As far as I can tell from your snippet ... it is implemented.


    Quote Originally Posted by marmin
    Why do I have to tell the compiler what names I will use in advance. It strikes me as being a bit.. stupid. Why isn't compiler smart enough to recgnize a creation of an object and do the rest.
    That's because they designed the compiler around an explicit declaration of constructors and deconstructors, not the other way around. So? It's just like C# and Java's implementation of Namespaces ... whoopie, a feature.

    Don't forget that even a bug can be considered a feature.

    Quote Originally Posted by marmin
    Now, I am forced to use only new () and Dispose () (the old fashioned way), because I don't want the compiler to know what instances i'm going to use.
    Yeah, because you aren't following what was set as the standard by your compiler. And whose fault is that choice? Obviously not the compiler when it is a quite limited program, though advanced, when compared against a human.

  3. #3

    Re: Naming - Creating objects.

    This what? Maybe if you tell what you are puzzling over we might be able to answer questions. As far as I can tell from your snippet ... it is implemented.

    >No, afaik you first need to make

    Code:
    type
    par_001,   
    foo_x,        
    nice_weather : Tpar;
    and that's what i'm talking about if you don't do it it gives an error.




    Quote Originally Posted by marmin
    Why do I have to tell the compiler what names I will use in advance. It strikes me as being a bit.. stupid. Why isn't compiler smart enough to recgnize a creation of an object and do the rest.
    That's because they designed the compiler around an explicit declaration of constructors and deconstructors, not the other way around. So? It's just like C# and Java's implementation of Namespaces ... whoopie, a feature.

    >Then why not make it better, it is a burden to do, and, it is a waste of time. A bad feature needs to be removed.

    Quote Originally Posted by marmin
    Now, I am forced to use only new () and Dispose () (the old fashioned way), because I don't want the compiler to know what instances i'm going to use.
    Yeah, because you aren't following what was set as the standard by your compiler. And whose fault is that choice? Obviously not the compiler when it is a quite limited program, though advanced, when compared against a human.[/quote]

    >in c++ you can just do it . That's not my fault..
    Marmin^.Style

  4. #4

    Naming - Creating objects.

    now I do not understand what you actually mean....

  5. #5

    Naming - Creating objects.

    Well, Setharian, it's simple, in my first post if you execute it you'll get:

    'undeclared identifier : par_001'.
    And that is my point. If the compiler can't figure out that it belongs to tpar, and automatically make a type for that, then I see that as a flaw.
    Marmin^.Style

  6. #6

    Naming - Creating objects.

    if you mean explicitly declaring variables then you'll have to live with that....it has been in Pascal from the very start and makes you think about variables before you start using them....if you can't get used to it, stay with C(++)....

  7. #7

    Naming - Creating objects.

    That 's the general reaction. If you propose change in any way, you are politely asked to go away from Pascal, like if I 'd be some kind of 'enemy' towards the language and gonna steal the Golden crown away from it.

    There is almost no in-depth discussion, as to the question if there really need to be changes like that. I don't think I'd go to a stronger language for now.. the C++ scene is too crowded. but it's more and more tempting..
    Marmin^.Style

  8. #8

    Naming - Creating objects.

    Pascal doesn't do declairation on the fly. That's by design. Some hate it, some love it. We're not coding VB here, this is object pascal.. a much better language by far..

    Anyway about your question.. this code will work

    Code:
    Tpar = class 
    // data 
    // constructor, destructor, etc. 
    end; 
    
      
    procedure test; 
    var
    par_001, foo_x, nice_weather : tpar;
    begin 
    
    par_001        := tpar.Create; 
    foo_x          := tpar.Create; 
    nice_weather   := tpar.Create; 
    
    
    end;
    It's the way the language works. The compiler doesn't attempt to assign the variable to the type used for the constructor unless it's told to, it would only add a level of complexity and possibly introduce unexpected behaviour.

    Hope this helps.

    http://www.delphibasics.co.uk/RTL.asp?Name=Var

  9. #9

    Naming - Creating objects.

    the obvious problem is that people expect all languages to have their favourite features....if they encounter something which is no the same, they ask why is it so and if it can be changed....well the simple answer is it's a different language and no it won't get changed.....pascal and basicly all algol languages are completly different from C-based languages (C, C++, D, Java, C# = all go here)...it's a different family of languages and thus it has different coding conventions and syntactic rules....

  10. #10

    Naming - Creating objects.

    Quote Originally Posted by Setharian
    ....if they encounter something which is no the same, they ask why is it so and if it can be changed.
    I didn't compare it to any other language in my first post. If you fail to see the advantages of my proposal, I can't help it.
    Marmin^.Style

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •