Good discussion on types of Typing
To quote:
"andrew cooke wrote in message news:...
> there are two different things:
>
> - static or dynamic typing
> - strong and weak typing
>
> you can have them in any combination (static+strong, static+weak,
> dynamic+string, dynamic+weak).
>
> static/dynamic relates to whether types are defined in the source.
>
> strong/weak relates to whether types are defined in the runtime
> system.
Actually the strong weak axis is determined by how strongly the type
system is enforced. Types don't necessarily have to be defined at
runtime. Pascal is a static-strongly typed language enforced mostly
at compile time. C is less strongly typed than Pascal because there
are more loopholes, e.g. unions and pointer manipulations; very little
is enforced at runtime. Python is a strongly typed language enforced
at runtime.
Michael Scott in "Programming Language Pragmatics", p321: A language
is said to be strongly typed if it prohibits, in a way that the
language implementation can enforce, the application of any operation
to any object that is not intended to support that operation. A
language is said to be statically typed if it is strongly typed and the
type checking can be enforced at compile time.
I guess he means that a static-weakly typed language doesn't make any
sense. You type all those declarations and the compiler just ignores
them.
Then I thought I would get a few pithy comments from Jeffrey Ullman,
"Elements of ML Programming", just to bolster my case: "ML is a
strongly typed language, meaning all values and variables have a type
that can be determined at 'compile time'." Good grief! What does he
know about languages? ;-)
Way at the end of the strong weak axis are un-typed languages like
Bliss and assembly language, where the type information is embodied in
the operation:
addf fr0,a ; a must be float
addi r1,a ; maybe it's an int
Judging from what is going on in the "passing by reference" thread
(100 articles!), we had better get quick agreement or another set of
useful concepts will be turned into mush. :-)
-- Russ"
To add to the above:
PHP is a weakly typed language.
Example: you can magically make an integer into a string without ever knowing what magic did that.
Perl is ???? typed language?
Haskel is a statically typed language?
Camel is a ??? typed language
Java is a dynamic/strongly typed language?
TCL is a ???? typed language?
Small talk is a weakly/??? typed language
(these will be filled in with time)
What is wrong with static-strong typing and weak typing:
A disadvantage of weak typing, is that if you didn't know or want that integer to be a string, then it could cause big havoc. If you are trying to debug a program and you made a simple mistake, your debugging session could take a while. If the integer was really supposed to be an integer, you just caused yourself a buggy program, which will be very hard to debug if the code is anything more than 200 lines.
Small PHP scripts can be whipped up fast, and perl ones, and maybe C programs too, since they are weakly typed. But when the program gets bigger the weak typing ends up shooting your own foot.
A disadvantage with strongly typed language is that you can't always whip up quick five minute hacks. But then again, with the IDE's available today, this is not true. A Delphi GUI application can be created in 5-10 seconds. Some weakly typed advocates have never used or seen the power of IDE's, or they have strong emotional opinions about IDE's, so they just wouldn't use them anyway.
With strong typing, your compiler will complain to you that you did not declare your variable before using it. But what was your variable doing there in the first place, and did you know that you were using it, or was it some code you forgot to delete? Do you even know what your variable is doing, or are you just guessing and playing along?
If you know your language well, then the weak typing is easier for you to get along with. Yet PHP people say that PHP is easy to learn and you will get up and running fast. But this contrasts or clashes with the fact that weak typing means you must know your language well! There lies a problem. This can cause also security issues in PHP programs and C programs.
Some weak typing advocates like to say that any programmer should know and study his programming language thoroughly, so why have strong typing if you already know the result of what's going to happen? Well, no programmer knows every little thing about his programming language when he is there at one sitting. Programming is not like a short story or short essay where you sit down and read the story in one sitting, and gather all the points about the story in one sitting. The language was created over several years, not in one sitting. Programs are not created where you know the results of what are going to happen. You do not know every little detail about your compiler that you are using (and if you do, think again.. even the compiler writers themselves don't know about each and every compiler issue or bonus - especially after 3 months or so when you wrote that code quite a while ago and forgot that the compiler even offered that bonus or that bug).
Automation of a compiler catching all sorts of errors comes into play with strong typing. Many times programmers will make a lot of little mistakes even if they are highly experienced programmers. It's a real joy to be able to make small mistakes while you focus on sorting out the big mistakes instead.
With regards to speed of rapid prototyping, and the advantages of a weakly typed language for rapid prototyping: sometimes having a short-form language such as QuikPas means that you can still whip up small quick programs even with a strong-static language. This means you have safety and quick fingers. Also, Delphi is considered RAD (rapid development), yet Delphi is strongly typed. So the major argument about weak typing being good for rapid prototyping sometimes doesn't mean anything when you compare the real factor: the IDE behind your development. Stick a good IDE behind your development and you will have rapid development. Just having a weakly typed language may make your development more rapid initially, but having an IDE with rapid capabilities and a strongly typed language seems like a much better solution.
But quick prototyping is not just about the IDE or the RAD tools. It's about the style of programming too, and many other factors. For example, in Pascal, you can still whip up quick solutions to problems by using no classes or no IDE at all. You can still build a a simple begin/end style application in a text editor with no classes, no special component palette, no special integration, etc. Some people feel with languages like Delphi that the IDE locks them down into GUI programming. That's simply untrue, because all you have to do is ditch the IDE and use the command line compiler and a text editor.
In web programming, it's also about html templates too. With Pascal web programming, you can still do quick fixes to your web application by using templates, which use macro style $variables in them. This means once again, there are many more factors to rapid prototyping than just weak typing. So in PHP you could whip up a quick page with embedded PHP in it and weak typing - but it's so much more than just the weak typing that makes PHP sometimes a fast prototype language (albeit many small scripts are insecure). It's also the fact, that you can just upload your PHP file without compiling it. But let's go back to the 5-10 second Delphi example. If you have a web development Pascal IDE, your web app could be built in a few seconds.
So weak typing causes faster prototyping usually in cases where you do not have good tools. Sure, if you are using a text editor and uploading interpreted files, weak typing may offer faster prototyping. But are other factors such as security, and strong knowledge and maintainability of your program more important?
When a language first comes out, it takes a while for the tools to be built. So in 1980 when tools weren't available, people could probably claim that SmallTalk was rapid development language compared to other languages, due to everyone using text editors without tools. When PHP first came out, you could still develop PHP applications faster than most other languages like C or perl applications, because you only had to upload your script with no permissions to worry about or directories to worry about. But as things move along, these factors become less important, since most FTP uploading and file permissions can simply be automated by an IDE or text editor (just that very few people are clever enough to realize the power of a plug-in based text editor or IDE allows you to automate all those.) Smalltalk and a text editor for web development or GUI development may be faster when only text editors are available, but with IDE's, even a strongly typed compiled language can be uploaded and tested just as fast.
The rapid prototyping factor behind PHP, is also due to the fact that you don't have to set up any permissions on your file once you upload it. But again, with a development IDE, all your FTP uploading and compiling could be automated anyway, which again means that it's more than just weak typing that makes prototyping fast (i.e. FakeLinux is an example of a tool that takes care of a lot of things, and makes rapid prototyping very possible even with a strongly typed compiled language). Weak typing is only one very small factor that makes PHP somewhat of a fast prototyping language. Since PHP has other more dominant factors that affect prototyping speed, we can say that weak typing really doesn't help all that much in the end anyway, for fast prototyping (maybe in small shell scripts, it does).
Have you ever seen a C programmer say he could build a GUI C program fast because of his weak typing? So if there are proper web development suites out there, it wouldn't matter about the weak typing so much. The other thing about integrated development environments, is that strong typing seems to only help them. Delphi came before C++ builder. Where is C builder or PHP builder? Strong typing seems to help out the integrated developments - maybe it's partly because strong typing means you know what you are doing instead of magically doing things that have results that are possibly unknown.
So it is true that back in the 1980's, using a weakly typed language in a plain command line text editor might mean that you got your weakly typed program up and running faster than the strongly typed one. But with IDE's, all that changes. So that is definitely not a reason or an advantage to use a programming language. Plus, again, you can still have a quick language with strong typing (as mentioned before, QuickPas is one example.)
It is also true that if you know your language well, weak typing can be less of a problem since you know the results of what is going to happen in some cases. But programming is such a complex and vast system, that no programmer knows the result of what is going to happen. You can't afford to guess. You can't catch every simple mistake or bug you make, because you are human. Weakly typed languages would be good for people that were perfect and knew everything about the language and their compiler, but in today's fast paced world no one has the vast knowledge about their programming language in order to predict results. Even the authors of the compiler themselves can't predict or know major portions of their own compilers at different times of the month, day or year.
|