Will php ever do strong typing?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dterrors@hotmail.com

    #1

    Will php ever do strong typing?


    Will php 6 do strong typing and/or namespaces?

    I was shocked to find out today that there are some people who actually
    argue that weak typing is somehow better. I didn't even know there was
    a debate. Shocking. That's like arguing that square tires are better
    than round.

    Anyway if anyone knows that php is going to intentionally stay weak in
    the future let me know so I can jump ship, thanks,

    mrb

  • Andy Hassall

    #2
    Re: Will php ever do strong typing?

    On 23 May 2005 15:33:58 -0700, dterrors@hotmai l.com wrote:
    [color=blue]
    >Will php 6 do strong typing and/or namespaces?[/color]

    AFAIK there's no decided feature set for PHP 6 yet.
    [color=blue]
    >I was shocked to find out today that there are some people who actually
    >argue that weak typing is somehow better. I didn't even know there was
    >a debate. Shocking. That's like arguing that square tires are better
    >than round.
    >
    >Anyway if anyone knows that php is going to intentionally stay weak in
    >the future let me know so I can jump ship, thanks,[/color]

    If PHP ever went strongly typed it would be a fundamental change to the
    language. It's not at all likely to happen IMHO. (You probably want to stay
    away from Perl as well).

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Oli Filth

      #3
      Re: Will php ever do strong typing?

      dterrors@hotmai l.com wrote:[color=blue]
      > Will php 6 do strong typing and/or namespaces?
      >
      > I was shocked to find out today that there are some people who[/color]
      actually[color=blue]
      > argue that weak typing is somehow better.[/color]

      I completely agree. Strong typing makes far more sense due to the
      compile-time constraints it enforces. Anyone who thinks otherwise is
      lazy, quite frankly, and isn't thinking in terms of long-term
      maintainability and debugging.

      It also buggers up the fundamental point of OOP, i.e. polymorphism.
      [color=blue]
      > Anyway if anyone knows that php is going to intentionally stay weak[/color]
      in[color=blue]
      > the future let me know so I can jump ship, thanks,[/color]

      Scripting langauges are not compiled, in general. Therefore most don't
      seem to use strong typing, because there's no compiler to catch this
      sort of thing. e.g. PHP, Perl, VB, VBscript, Javascript. I don't think
      this is likely to change in the future. As Andy says, this would be a
      fundamental paradigm shift in any language.

      Also, I think languages like PHP are designed for people who don't know
      much about "proper" programming. It's designed for people who just want
      to throw something together that does the job. No need to worry about
      algorithm optimisation, memory allocation or deallocation, hash-table
      searching, string handling, type-casting, or indeed typing in general.

      --
      Oli

      Comment

      • Ken Robinson

        #4
        Re: Will php ever do strong typing?

        Oli Filth wrote (in part):[color=blue]
        > Also, I think languages like PHP are designed for people who don't[/color]
        know[color=blue]
        > much about "proper" programming. It's designed for people who just[/color]
        want[color=blue]
        > to throw something together that does the job. No need to worry about
        > algorithm optimisation, memory allocation or deallocation, hash-table
        > searching, string handling, type-casting, or indeed typing in[/color]
        general.

        Them thar's fight'en words.... :-)

        I use PHP because it's easy to program and to get the job done.

        <dating myself on>
        I have been involved with computers since 1969! Pre Internet, Pre
        ARPAnet, Pre OOP, almost Pre CRTs, Pre PCs, Pre MAC, PRE WEB ... the
        punch-card era. I've seen the introduction of OOP, I've see "Go To"
        less programming, I've seen the "Come From" counter rebellion...
        <dating myself off>

        Fine, if you don't like PHP because it isn't OOP and strongly typed,
        don't use it, but don't expect everyone to agree with you. Find a
        programming language you like, use it to interface to the WEB servers
        as a CGI. Or, create your own language that can be used with the web
        servers, prove to everyone that it is better than what is already out
        there. And while you're at it, make sure that it does an excellent job
        at catching array overflows and boundary checking. Make sure no one can
        use it to write malicious code.

        Ken

        Comment

        • Oli Filth

          #5
          Re: Will php ever do strong typing?

          Ken Robinson wrote:[color=blue]
          > Oli Filth wrote (in part):[color=green]
          > > Also, I think languages like PHP are designed for people who don't[/color]
          > know[color=green]
          > > much about "proper" programming. It's designed for people who just[/color]
          > want[color=green]
          > > to throw something together that does the job. No need to worry[/color][/color]
          about[color=blue][color=green]
          > > algorithm optimisation, memory allocation or deallocation,[/color][/color]
          hash-table[color=blue][color=green]
          > > searching, string handling, type-casting, or indeed typing in[/color]
          > general.
          >
          > Them thar's fight'en words.... :-)
          >
          > I use PHP because it's easy to program and to get the job done.
          >
          > <dating myself on>
          > I have been involved with computers since 1969! Pre Internet, Pre
          > ARPAnet, Pre OOP, almost Pre CRTs, Pre PCs, Pre MAC, PRE WEB ... the
          > punch-card era. I've seen the introduction of OOP, I've see "Go To"
          > less programming, I've seen the "Come From" counter rebellion...
          > <dating myself off>
          >
          > Fine, if you don't like PHP because it isn't OOP and strongly typed,
          > don't use it, but don't expect everyone to agree with you.[/color]

          I'm not disagreeing with you! I like PHP for the same reason you do: it
          gets stuff done *very* quickly.

          But you can't deny that PHP hides one hell of a lot of nitty-gritty
          low-level (and even standard high-level) stuff from you, so that the
          average PHP user can safely assume that, for instance, arrays can
          safely be indexed by strings (even though this isn't done natively in
          any compiled language that I can think of). But sometimes this stuff is
          important. Especially in large, non-trivial systems.
          [color=blue]
          > Find a
          > programming language you like, use it to interface to the WEB servers
          > as a CGI. Or, create your own language that can be used with the web
          > servers, prove to everyone that it is better than what is already out
          > there. And while you're at it, make sure that it does an excellent[/color]
          job[color=blue]
          > at catching array overflows and boundary checking. Make sure no one[/color]
          can[color=blue]
          > use it to write malicious code.[/color]

          Again, I'm not disagreeing with you. But from a progammatic point of
          view (i.e. "what is my script *actually* doing?"), PHP is not the best
          answer. If you are used to a language where compile-time and link-time
          catch a large number of syntax errors, silly mistakes and algorithmic
          boo-boos (e.g. comparing a string with an integer, which doesn't make
          sense in e.g. C), then PHP is going to look pretty basic. If this check
          isn't even performed at load-time, then debugging becomes a very
          hit-and-miss affair.

          And when you consider that many PHP programmers consider eval() to be
          an acceptable way of achieving things, the problem becomes even worse.

          Like I said before, PHP (along with many scripting languages such as
          Javascript and Perl) seems to be designed to get stuff done in an
          extremely high-level, abstract way, where even things like object types
          are (essentially) irrelevant. Except at run-time, when they bite you in
          the arse 6 months down the line if you've screwed up. If only they bit
          you in the arse at compile-time (which doesn't exist)...

          (P.S. IMO, any language without pointers (and pointer arithmetic) isn't
          a real language!!)

          --
          Oli

          Comment

          • Chung Leong

            #6
            Re: Will php ever do strong typing?

            Great, just what we need, flame bait.

            Comment

            • Oli Filth

              #7
              Re: Will php ever do strong typing?

              Oli Filth wrote:[color=blue]
              > Also, I think languages like PHP are designed for people who don't[/color]
              know[color=blue]
              > much about "proper" programming.[/color]

              I should probably point out that by this, I do *not* mean that everyone
              who uses PHP is some kind of retard. Far from it. I am just stating
              that one of its original design objectives was to be a language that
              anyone could pick up, with little (or no) programming experience.
              Therefore, lots of typical programming issues have been made completely
              transparent to the PHP programmer.

              --
              Oli

              Comment

              • Jordi

                #8
                Re: Will php ever do strong typing?

                I would also not mind if they would somehow inplement strong typing in
                PHP, but I really don't see that happening. It is one of the things I
                like about C++ (and Java) and in this area I would like it if PHP was
                more like those languages. I am kind of using strong typing already by
                prefixing any variable-name with a letter (i for int, s for string, a
                for array...).

                I would also like to see the OOP and pointers of C++, although I hate
                pointers, but that's just because I'm appearantly to stupid to use them
                effectively.

                One thing I really really like about PHP however, is how it handles
                arrays. I hate the C++ mechanism where you have to specify the length
                of the array and it is then fixed... I hope they never touch that in
                PHP.

                Comment

                • dterrors@hotmail.com

                  #9
                  Re: Will php ever do strong typing?


                  Jordi wrote:[color=blue]
                  > One thing I really really like about PHP however, is how it handles
                  > arrays. I hate the C++ mechanism where you have to specify the length
                  > of the array and it is then fixed... I hope they never touch that in
                  > PHP.[/color]

                  Pretty much every other modern language besides C and cpp will let you
                  freely add and delete from arrays. perl, java, php, python, javascript,
                  c#, whatever.

                  Comment

                  • Philip  Olson

                    #10
                    Re: Will php ever do strong typing?

                    Use === instead of ==.

                    Comment

                    • Colin McKinnon

                      #11
                      Re: Will php ever do strong typing?

                      Oli Filth wrote:
                      [color=blue]
                      > dterrors@hotmai l.com wrote:[color=green]
                      >> Will php 6 do strong typing and/or namespaces?
                      >>
                      >> I was shocked to find out today that there are some people who[/color]
                      > actually[color=green]
                      >> argue that weak typing is somehow better.[/color]
                      >
                      > I completely agree. Strong typing makes far more sense due to the
                      > compile-time constraints it enforces. Anyone who thinks otherwise is
                      > lazy, quite frankly, and isn't thinking in terms of long-term
                      > maintainability and debugging.[/color]

                      "We will encourage you to develop the three great virtues of a programmer:
                      laziness, impatience, and hubris."

                      -- LarryWall, ProgrammingPerl (1st edition), O'Reilly & Associates

                      Sorry, but I just don't get it. Why is enforced strong typing a benefit?

                      I like the way PHP works. I freely admit there are times when I want to make
                      sure of the type of a variable but in PHP I can *choose* to do that by
                      various mechanisms ('===', if ($test==(intege r)$test), ...) and if I want
                      to record the type of a variable I use comments(1).

                      IMHO Hungarian notation and SOAP do major damage to the readability of code.

                      [color=blue]
                      > It also buggers up the fundamental point of OOP, i.e. polymorphism.
                      >[/color]
                      Nope. I don't see that either. If the base types are (to most intents and
                      purposes) polymorphic, how does that undermine polyorphism in user classes?

                      IMHO the only design issues with PHP in its current form are:

                      - namespace collisions - implementing seperate namespaces is one solution to
                      this

                      - erm, that's about it really.
                      [color=blue]
                      > Also, I think languages like PHP are designed for people who don't know
                      > much about "proper" programming. It's designed for people who just want
                      > to throw something together that does the job. No need to worry about
                      > algorithm optimisation, memory allocation or deallocation, hash-table
                      > searching, string handling, type-casting, or indeed typing in general.
                      >[/color]
                      ( not to mention null pointer dereferencing, buffer overflows, failed build
                      cycles...)

                      There are no BAD programming languages(2) - just bad programmers ;)

                      Certainly I want to get things done with a minimum of effort however I have
                      written network protocol stacks and AI engines in PHP (and no, not because
                      it was the only programming language I know).

                      The most expensive component in most computer systems is programmer time.
                      Have a look at the Great Computer Language Shootout. PHP consistently
                      scores well in requiring fewer lines of code. It's not the most
                      minimalistic, but OTOH, I've yet to find someone that thinks PHP is not a
                      VERY easy language to learn. Add to this the flexibility of what can be
                      acheived with PHP and it starts to look like a language which excels at
                      being understood. This kind of transparency (despite my comments below - 1)
                      is therefore the most valuable asset of any programming language - want to
                      talk about maintainability and debugging?

                      But I am more than happy to be educated / proved wrong.

                      C.

                      1 - don't even think about posting a reply containing the string
                      'self-documenting code'
                      2 - except maybe brainf**k - but it's meant to be bad


                      Comment

                      • Jordi

                        #12
                        Re: Will php ever do strong typing?

                        Happy to hear that.

                        I don't know a lot about other languages. I've had a basic course in
                        Java a couple of years ago, but I don't remember much of it. I can
                        usually understand JavaScript, but that's it.

                        I'm studying Artificial Intelligence and they are teaching us to
                        program in C++, but I really hate their array-system.

                        By the way, do all of the languages you mentioned have associative
                        arrays? I kind of like that about PHP too.

                        [/offtopic]

                        Why do you think it is necessary for PHP (or any other language) to
                        have strong typing? I've been thinking a little bit about this today
                        and I'm not so eager to see it implemented anymore. I mean: what's the
                        big advantage? If you are a good programmer, chances are that you won't
                        be bitten in the arse 6 months down the line.
                        I don't think there are a lot of scenario's where strong typing are
                        essential and if you really want to check for a specific type, just use
                        the === operator.

                        Also, Oli Filth pointed out that PHP doesn't worry about a lot of
                        things. He mentioned algorithm optimisation, memory allocation,
                        hash-table searching, string handling and type-casting. I could be
                        wrong and/or I didn't understand the comment properly, but doesn't PHP
                        do a lot of these things automatically? I thought PHP had it's own
                        garbage collector (memory allocation) and you can also unset variables
                        yourself. I read somewhere that PHP arrays where actually hashes, so
                        who needs hash-table searching when it's already there? String handling
                        in PHP rocks IMO and you can optimize your algorithms (why not?).

                        Comment

                        • Chung Leong

                          #13
                          Re: Will php ever do strong typing?

                          The question of strong vs weak typing was discussion in a roundtable
                          discussion with representative from Perl, PHP, and Rudy:



                          Comment

                          • Chung Leong

                            #14
                            Re: Will php ever do strong typing?

                            IMHO the complexity introduced by namespace is not worth the benefit.
                            Suddenly people learning PHP have yet another feature to learn. Books
                            will have an additional chapter. In general PHP code would become more
                            complicated, since people will start using namespace just because it's
                            there and not because it's necessary in a given circumstance.

                            A more useful solution I think would be the ability to create separate
                            execution contexts, something similiar to the component system in
                            Flash/Actionscript. You would run a third-party script in its own
                            context, with separate namespace, variable-space, and settings. That
                            would eliminate other sorts of conflicts you may encounter in sharing
                            code, in additional to namespace collisions.

                            Comment

                            • NC

                              #15
                              Re: Will php ever do strong typing?

                              dterrors@hotmai l.com wrote:[color=blue]
                              >
                              > Will php 6 do strong typing and/or namespaces?[/color]

                              I hope not...
                              [color=blue]
                              > I was shocked to find out today that there are some people
                              > who actually argue that weak typing is somehow better.[/color]

                              But it IS better, sometimes at least.

                              Strong typing was advocated by Niklaus Wirth for one and only
                              one reason: the lack of transparent and well-documented rules
                              for handling type mismatches and out-of bounds errors. Say
                              we have:

                              if ($a == $b)

                              How should an interpreter/compiler go about it if $a is a float
                              and $b is a string? Wirth's preferred approach was to throw
                              a type mismatch error and refuse to complie/execute. PHP provides
                              both a transparent rule-based alternative for handling the type
                              mismatch without halting and an alternative strict comparison
                              operator (===).

                              Another problem which Wirth suggested should be solved with
                              strong typing is this:

                              It must be guaranteed that no [array] element can be accessed
                              with an invalid index, despite the fact that the resulting
                              address computation would point to some existing storage cell
                              -- probably holding another variable.

                              (Quoted from Witrh's 1997 interview to Software Development
                              magazine)

                              The problem is real enough. But the truth is, it DOESN'T have
                              to be solved with strong typing. And PHP is a good example of
                              an alternative solution; indeed, you can't get anything other
                              than NULL if you access a non-existing element of an array.
                              Moreover, you can check if this element exists before you
                              attempt to acces it...

                              Also, Wirth did not anticipate that distributed computing will
                              eventually come to a point when data will be exchanged between
                              distributed components not in their internal presentation, but
                              rather, in their STRING presentation. If you need to send an
                              argument whose value is 10 to a Web service, you will have to
                              send it as string '10', not as byte 0A. In this situation,
                              strong typing begins to smack of a headache; indeed, you need
                              to explicitly convert every string you receive via Web service
                              input into its appropriate type...
                              [color=blue]
                              > I didn't even know there was a debate. Shocking. That's
                              > like arguing that square tires are better than round.[/color]

                              Not really. Rather, it's like arguing that wide tires are
                              better than narrow ones on some vehicles in some circumstances.
                              [color=blue]
                              > Anyway if anyone knows that php is going to intentionally stay
                              > weak in the future let me know so I can jump ship, thanks,[/color]

                              Happy jumping. :)

                              Cheers,
                              NC

                              Comment

                              Working...