Scala, a Statically Typed, Functional, O-O Language
inkslinger77 notes a Computerworld interview with Martin Odersky on the Scala language, which is getting a lot of attention from its use on high-profile sites such as Twitter and LinkedIn. The strongly typed language is intended to be a usable melding of functional and object-oriented programming techniques. "My co-workers and I spend a lot of time writing code so we wanted to have something that was a joy to program in. That was a very definite goal. We wanted to remove as many of the incantations of traditional high-protocol languages as possible and give Scala great expressiveness so that developers can model things in the ways they want to. ... You can express Scala programs in several ways. You can make them look very much like Java programs which is nice for programmers who start out coming from Java. ... But you can also express Scala programs in a purely functional way and those programs can end up looking quite different from typical Java programs. Often they are much more concise. ... Twitter has been able to sustain phenomenal growth, and it seems with more stability than what they had before the switch, so I think that's a good testament to Scala. ... [W]e are looking at new ways to program multicore processors and other parallel systems. We already have a head start here because Scala has a popular actor system which gives you a high-level way to express concurrency. ... The interesting thing is that actors in Scala are not a language feature, they have been done purely as a Scala library. So they are a good witness to Scala's flexibility..."
... skah-lah not scale-la
Scala Programmers: $35K - $45K
Our company is looking for motivated individuals with 5 + years in depth experience with Scala.
Must be familiar with all aspects of O-O Languages.
We are an equal opportunity employer.
When Fascism comes to America, it will call itself Anti-Fascism, and tell you to give up your guns.
"Twitter has been able to sustain phenomenal growth"
This is my friend FailWhale. You are making FailWhale sad. You wouldn't like FailWhale when he is sad...
Scala is great, but one really annoying thing about it is that it inherits type erasure implementation of generics from Java. This means that you cannot overload methods on argument with the same generic class with different type parameters, cannot implement the same generic interface with different type parameters on the same class, cannot check whether a class implements a particular generic interface for a given type parameter, etc. They did fix some issues - for example, you can instantiate arrays - but it's still far from perfect.
I understand the need to match Java's broken model for the sake of interoperability, but surely a better way can be devised for pure Scala code? It's pretty much the only area where Scala noticeably lags behind advanced .NET-hosted languages (such as Nemerle or F#).
Different tools for different jobs.
That being said, does anyone know of a good comparison of languages broken down by what they're best at doing? How does one decide what the best language for what they want to do is? My google-fu is weak today. I found this: popular programming languages; but the analysis seems lacking.
Like mod_perl ?
You mean like Mason? Possibly you're looking for something more like Catalyst?
These things have been available for Perl for a long time.
maybe it will make my hair grow back
OTOH, it might as well make your back hair grow, and who wants that?
Who is General Failure and why is he reading my hard disk?
http://www.google.com/search?q=strongly+typed+language
http://en.wikipedia.org/wiki/Strongly_typed
Strongly typed languages usually make type conversions explicit and enforce type restrictions; whereas weakly typed languages usually allow implicit type conversions and relax type restrictions.
Explicit type conversions disallow a value of type T to be treated as a value of type S without invoking a function that takes a value of type T and returns a corresponding value of type S. For example, a conversion from an integer type to a floating point type requires the invocation of a function that performs the conversion. Contrast this with implicit type conversions where a value can be treated as almost any type depending on how it is to be used.
Type restrictions only allow certain operations to be done to certain types. For example, numerical addition mïay only be performed on numerical types. A lack of type restrictions allow for numerical addition to apply for, say, booleans, for example.
But if all you're doing is reinventing Perl with C-like syntax, it's not really a step forward.
Perl already has C-like syntax. It doesn't, however, have static type checking, let alone robust static type checking (with nice features like variance annotation etc.); nor does it have particularly robust functional programming support -- you can certainly do functional programming in Perl, but it isn't as clean and syntactically sugared as it could be; nor does perl have particularly clean OO if we're being honest -- yes it works and can be made to work quite well, but elegant isn't a word that comes to mind when I think Perl and OO; nor does Perl have function pattern matching and algebraic data types; nor does Perl have a nice concurrent programming interface based on the Actor model. None of this is really to say that Perl is bad -- it is very good for a great many things, and the features I've mentioned needn't hold it back. My point is that Scala is most certainly not re-inventing Perl. In fact Scala doesn't even have a particularly C-like syntax: it's less C-like than Perl really.
Craft Beer Programming T-shirts
Back at university I somehow dodged functional programming. I knew functional programming was and is an important concept, but besides an excursion to Prolog and some SQL I never went outside imperative and/or object-oriented programming. I never wanted to learn Lisp or Scheme, Haskell seemed to much for mathematicians back then. Scala intrigued me enough to give functional programming a try again. It's object-oriented, has generics, is strongly typed, but has a powerful inference systems, so declaring things is not too tedious. Java classes and packages can be used within. It has not only builtins for concurrency but also for parallelism. However, it was the functional programming paradigm opened my eyes, what I was missing yet.
No, this is Scala, a language that is a blend of functional and object oriented programming. Scalia is mix of textualism and originalism with a very conservative framework. Some consider its inability to recuse itself to be its greatest asset.
- None can love freedom heartily, but good men; the rest love not freedom, but license. -- John Milton
Ah - duh. Immediately started thinking typed, as in the clicky clicky kind of typing done on a keyboard.
Man, was that a loud and smelly brain fart.
Thanks for that.
Sorry. Sorry Everyone!
Shameless plug alert: Game server control panel
...had Martin Odersky in for an interview a while back.
It's good stuff; se-radio isn't afraid to get down in the weeds with the interviewee.
The Army reading list
What does that even mean?
It basically means that variable types are rigidly enforced and conversions are explicit.
It's annoying, but also eliminates some possible mistakes.
For example, say you've got a float variable: FloatNum1
And a couple integer variables: IntNum1, IntNum2
Some languages don't care much about variable types and do conversions on the fly. So you could write code to do
IntNum2 = (FloatNum1 + IntNum1)
and nobody would complain. No errors. Nothing. It would compile and run just fine. At least, assuming you didn't lose something important in a rounding error somewhere.
A strongly typed language will not allow that. It will kick out errors, refuse to compile, and generally pitch a fit. You are not allowed to add a float to an integer, and you certainly aren't allowed to assign it to another integer variable. Instead, you do something like this:
IntNum2 = (Float_to_Int(FloatNum1) + IntNum1)
"Work is the curse of the drinking classes." -Oscar Wilde
FTA: actors in Scala are not a language feature, they have been done purely as a Scala library
So:
1. There will be no useful compiler warnings/errors for the feature, since compilers implement only the core languuage.
2. Even if the library code will be 100% bug free, you'll still have to drag a debugger though it when debugging a hard bug in nearby code.
3. The library's API will never acheive the self-consistency of the core language because of too many cooks spoiling the broth.
4. The library will be massively overfeatured, but still not do what you actually want.
5. The library will change more frequently than core langage, meaning nothing will compile in the real world without hacks.
6. The library designer will hypnotise the core language designer and impose his own stupid ideas on the core language.
7. (6.) will lead to the entropy death of the language; people will simply stop paying attention to new versions.
Seriously, we should be figuring out a minimal subset of concurrancy features that really *can* go into a core language, with compiler support, debugger support, good consistency (like the while loop which does the same thing in all languages) etc.
Then libraries can implement endless semantic sugar/bullet-point fluff on top of the core features, since that's what libraries are good at.
Assuming you're not being merely rhetorical (because the definition is kind of loose), strongly typed just means that the language makes some restrictions on how operations operating on different value types can be intermixed. Assuming that you're not a programmer, I'll give an example. Letâ(TM)s say you have a BMW Z4 roadster. It's a car. Understanding the nature of cars, you know that it can be classified as a vehicle, a sports car, a BMW sports car, and a BMW Z4 roadster. Strongly type languages make restrictions like you can't just say: roadsterCar car = myCar. This is implicitly is saying my car is roadster. Rather you have to explicitly say that the car is a roadster (called a cast) like this: roadsterCar car = (roadsterCar) myCar This concept has a number of benefits, most of which are related to catching programming mistakes before they become bugs or immediately at runtime. Without strongly typed languages, you won't notice that you tried to call a bike a BMW Z4 roadster until you try to get it up to 140 miles an hour. And by then you might have tried to do valid but nonsensical things that might have really broken something.
Probably the most robust JVM compatible language to date. Even the creater of Groovy digs Scala: http://macstrac.blogspot.com/2009/04/scala-as-long-term-replacement-for.html
"Twitter has been able to sustain phenomenal growth, and it seems with more stability than what they had before the switch, so I think that's a good testament to Scala"
Have you ever bothered to look what the Twitter site does - there is virtually nothing to it. To argue that any language that is behind it is a testament to that language is ridiculous. The bigger question is how could they get any language to unstable for such a trivial set of functionality?
Martin Odersky is beardless, Scala is doomed.
crazy dynamite monkey
Scala on Scales?
Am I the only one not terribly enamored with Scala? It's a massive language (have you seen the book?), but a lot of the syntax is somewhat redundant and doesn't seem to add that much. The type system is downright byzantine, and the Java interface is, let's say, somewhat inelegant. And the whole object-functional thing seems like a paradigm in search of an audience (maybe I'm just not getting it).
And you get to pay for all this with a huge performance hit.
I guess their "more is more" approach is mostly making Clojure look more attractive.
sic transit gloria mundi
My point is that Scala is most certainly not re-inventing Perl.
True, it also doesn't appear to be a reimplementation of anything. It's somewhat related to Java (Scala programs execute with the JVM).
The code snippets on the website http://www.scala-lang.org/ are intriguing. It's certainly a terse language. That's both good and bad.
Comment removed based on user account deletion
Scala is statically typed. Most languages are strongly typed so that's not a particularly useful metric.
Static typing means that every object type is known at compile time and thus type safeness can be enforced before the code is executed.
The ultimate answer to your question (sort of)
The Tao of math: The numbers you can count are not the real numbers.
I could use an alternative programming language for the JVM that is more expressive than Java. Both Scala and Groovy integrate well with Java at the language level, albeit with different type systems. While I do use Groovy from time to time, what kept me from Scala was that it is not well supported by IDEs (Eclipse/Netbeans - I hear things are somewhat better with IntelliJ). The problem is the nature of Java libraries. They tend to be deeply nested and often expressed in lower level abstractions and are difficult to use without strong IDE support. I don't need an IDE for Python (flat module systems, high level libraries), but certainly do for Java. With solid IDE support however, I am nearly as productive in Eclipse + Java as with dynamic languages, even for medium apps. Scala and Groovy come with their own standard libraries and I don't need IDE support as long as I stay within them. But sooner or later, I will need to step into plain Java land and I no longer feel productive. I would rather use straight Java for them.
The development experience is language + tools, not just the language. While Scala can piggy back on JVM and undercut the rest of the process that languages need to go through to mature and be accepted, Scala plugin (or someone else) has to provide a JDT equivalent first to have popular appeal.
I just wish there was a well supported superset of Java with productivity considerations that maintains 1:1 byte-code compatibility on compilation. Java purists can keep their language clean. But the rest of us can be happy too. Scala has that potential.... almost. So far, Groovy has been filling that role for me. Groovy will never have the kind of edit-time IDE intelligence simply due to it's dynamic nature. But for now, it stands ahead (after all, it has been around longer).
Funny that you picked this particular example, because even strongly typed languages more often than not allow implicit floatint conversions. Take C/C++ for example, which would be a prime example of a strongly typed language but still it allows implicit int->float conversions, and many compilers don't mind going from int->float conversions either, even though it's a narrowing type conversion.
A better example would be something like string s = '0nice' and int i = 1. A typical weakly typed language allows statements such as string t = s + i (yielding '0nice1' for example) or i = i + s (multiple possible interpretations possible, but most languages would convert '0nice' to 0 to get i = i + 0).
I have no idea how hard is should be, but remember, each time Scoble farts, twitter has to handle 93,000 messages.
Nerd rage is the funniest rage.
Given the number of reported "fail whale" incidents (if I'm naming them correctly), apparently it's really, REALLY hard to do. Or at least for the people who did it...
Bit I'm not a Twitter-er. I have an account and I occasionally read news blurbs on it, but I have yet to post anything on it.
"This post contains words, known to the State of California to cause thought. Wash brain thoroughly after reading."
already has C-like syntax
Why not use the C instead then, or even better C++. After all many top websites run C++ (Google,eBay,Yahoo) as it is the fastest, well memory utilizing, best threading performance and green/CPU saving solution. With the native processor exceptions used properly it is also the most robust solution.
It basically means that variable types are rigidly enforced and conversions are explicit.
Actually, no, it means that value types are strongly enforced. A language may not have typed variables at all, and still be strongly typed - Python and Ruby are both examples of that. Static/dynamic typing, which is what you describe, is orthogonal to weak/strong typing.
Examples of weakly typed language are PHP, Tcl, and AFAIK Perl.
"To this day, many C programmers believe that 'strong typing' just means pounding extra hard on the keyboard." --Peter van der Linden, Expert C Programming.
Umm... I think we were doing this a long time ago in Lisp with CLOS (and flavors).
In a band? Use WheresTheGig for free.
Sounds like someone is bitter about not having much choice in their life. You probably don't have any hobbies, either, since your employer wouldn't approve. Have fun tilling the land for your lord. The rest of us will be making real money for ourselves, out-competing your boss because of productivity gains from using decent tools, as opposed to whatever tools your boss thinks are the cheapest to teach monkeys to use.
Enjoy your job. Maybe if you're a good, your employer will give you a 1% raise next year? As long as it doesn't cut into executive bonuses, that is.
What does that even mean?
It means you're not qualified to even enter this discussion. Go take a course on programming languages and then get back to us.
Next biggest thing for the "guys with a job" crowd.
Learn some other language that isn't C#, Java, C++, VB.NET, or in fact particularly related.
Specifically, learn something with functional programming, or a different sort of object orientation (Common Lisp comes to mind, or Smalltalk or Objective-C), or declarative programming (like Prolog)...anything that's considerably different from any of the standard compiled OO languages.
Learn and improve, or don't learn and become unable to earn a living in the field.
"When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
I like your definition.
One of the biggest problems with "strongly typed" that I've seen is that sometimes it becomes synonymous with with "statically typed" and they just aren't the same thing. Some people seem to think that dynamically typed languages are automatically "weakly typed" which is just flat out wrong.
Most languages are strongly typed so that's not a particularly useful metric.
Hardly. The One True Language for client-side web development, aka Javascript, is weakly typed, as is PHP, that ubiquitous server-side programming language. Perl is weakly typed. Good ol' shell script is weakly typed. Heck, even C is considered weakly typed (unless you enable -Werror, of course).
Recently I decided to move from contracting to full time work as the job market is balls here in the Bay currently for Contracts. Twitter was one of the companies which I applied and I had the pleasure of having a "phone screen" with them for a senior unix position. Here's what this screen was, a basic unix question, that any lunix user could get. A more intermediate type question that could trick some people. And finally their *BIG SCREEN* a tricky question that was based on esoteric knowledge that had absolutely nothing to do with one's ability to perform the job.
The person calling me was just reading these off a list, she didn't know why they were picked and was only able to write down the answers. Here's the hilarious part, I informed her that the question was silly and there's no reason anyone should really care about this sort of information except in extreme situations. That this was the question that lead me to believe they had a culture of primadonnas. She diligently wrote all this down, in case they still wanted to talk to me.
But here's the REAL kicker, their stupid asinine esoteric question? Was wrong. They had the phrasing wrong... what they were asking and looking for in an answer were not the same things. Being a pedantic asshole, in my followup to tell them what I thought of their process I pointed this out. Never heard anything back ;) Wonder if they have fixed their question yet?
--- I do not moderate.
It's kinda like "PC Load Letter".
Sent from your iPad.
a language that can be used in many different ways will result in code that will be a JOY to maintain and debug.
Privacy is terrorism.
No, this is Scala, a language that is a blend of functional and object oriented programming. Scalia [wikipedia.org] is mix of textualism and originalism with a very conservative framework. Some consider its inability to recuse itself to be its greatest asset.
Eh, different tools for different jobs.
http://en.wikipedia.org/wiki/Hyperlink
I have not only seen the book but also read it (assuming you mean Programming in Scala). It is very well written and gets you started with Scala easily.
I do not agree that the syntax is redundant. To the contrary: an important part of the language design is that Scala enables the programmer to extend the language using libraries. A good example is the way collections and iteration work in Scala vs. the way the foreach loop has been added in Java 5.
Whether static type systems help or hinder depends on whether you work with or agaist it, and on the kind of programs you write. The Scala type system is rather advanced (in the sense of complete) such that it allows you to express more in the type system than other languages do.
For Java style programming Scala is just much simpler and shorter to write. When you have written some code in both you can appreciate the way Scala works.
There has already been a comment on multi-paradigm programming, I do not have to extend that.
Those supposedly cute features are there for a reason--they make abnormally clean and maintainable code possible.
The best Scala code I've seen is clearer (to an outside observer) than the best Java code could possibly be, since the language features allow you to focus more on what is going on rather than necessary theatrics.
The worst Scala code is, admittedly, worse than the worst Java code could possibly be.
So, if I had programmers who wrote nice clean code, I'd encourage them to use Scala. If I had programmers who wrote ugly tangled code, I'd force them to use Java.
Obviously Java is weakly typed :-)
The Tao of math: The numbers you can count are not the real numbers.
No question that anyone who wants to make a living programming probably needs to learn a business safe language like the ones you mention.
Still, some of us really enjoy programming, even when we aren't making a buck off it. Working with a new language can make you think about programming in a new way, and can teach you lessons that you can bring back to your day to day business work.
Let's not forget how fun masturbation can be!
# (/.);;
- : float -> float -> float =
I actually really like dynamic/strong languages (like, for example, Python). It allows you the security and readability of a strongly typed language, without all the whiny syntax of a statically typed language.
Java cured me of ever liking static typing...Seems like I spend half my time in java dealing with weird casting issues.
ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
Yes, but understand that, when you're learning that language, you're doing it to expand your mind and development toolkit, *not* to add said language to the list you put on your resume, as the very fact it's niche means no one will care.
And by "development toolkit", I mean things like design patterns and approaches to software construction. Take Haskell, for example. Compared to a typical imperative language, it requires a *very* different mindset when constructing applications. But the lessons you learn (higher-order functional programming, function composition as a form of abstraction, etc) are powerful tools which can be utilized in other languages, and learning them will force you to re-think how you build software, which is a very good thing.
Yes, big difference; all combinations are possible:
Strong and Statically typed: Scala, Java, C++
Strong and Dynamically typed: Python, Ruby
Weak and Statically typed: C
Weak and Dynamically typed: PHP, Perl, Javascript
Here is a great resource on these issues and might help you use some of the language you are using correctly:
http://www.pphsg.org/cdsmith/types.html
I understand that static versus dynamic is a fairly binary valued property, but my understanding is that strength of type systems is real valued.
There are 2 axes to strength:
1. If you have a type system (you outlaw certain programs), how well is it enforced? Are there ways to get around it? (Yes/No)
2. How many and what type of behaviors do you outlaw in programs. On this axis a lot of trade offs can be made. Do you allow automatic coercion? Do you allow generic data types to be expressed? If so, are covariant and contravariant type parameters allowed? etc... (Subjective 0.0 - 1.0)
Unfortunately I don't have a link handy that will help me use English correctly.
Perl is weakly typed on a lot of things, but it's static for data structures and subroutines.
So you can have a hash of hashes, or an array of arrays, but you can't get arrays in your hashes or vice versa.
Php gets around that by having only one datastructure that tries to pretend to be other types of data structures, just without, you know, doing it very well.
ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
It depends on which language you use. A lot of people blame Twitters early problems on Rails, which has notorious scaling issues.
//Angry Ruby fanboy comments start below
ad logicam Claiming a proposition is false because it was presented as the conclusion of a fallacious argument.
Perl is weakly typed on a lot of things, but it's static for data structures and subroutines.
So you can have a hash of hashes, or an array of arrays, but you can't get arrays in your hashes or vice versa.
Yep. I mainly referred to Perl's and PHP's ability to treat strings as numbers and vice versa, depending on the context - Python wouldn't let you get away with that, for example. In that sense VB6 was also weakly typed, even though it had strongly typed objects.
So you can have a hash of hashes, or an array of arrays, but you can't get arrays in your hashes or vice versa.
Yo, Puppy, I heard you like arraying your hashes and hashing your arrays, so we put ... Oh, nevermind.
You assume that the only reason to learn something is to make money with it. Which is a rather depressing worldview, really.
"I hate computer languages because they force me to learn a bunch of shit that are completely irrelevant to what I want to use them for. When I design an application, I just want to build it. I don't want to have to use a complex language to describe my intentions to a compiler. Here is what I want to do: I want to look into my bag of components, pick out the ones that I need and snap them together, and that's it! That's all I want to do." Quoted from Why I Hate All Programming Languages.
Functional languages are worse because they are painfully counterintuitive. I don't want to write a function if all I want to do is link a sensor directly to an effector. Drawing a line from A to B is an order of magnitude simpler. Which is the way it should be.
Yeah, that would bring new meaning to "Strongly Typed" that I don't think was intended...
"Damn John, that brain fart was really strongly typed!!"
}#q NO CARRIER
To make matters more difficult, most languages are somewhere in between "pure" strongly typed and weakly typed.
Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
IIRC it was originally intended to be able to use the JVM or Microsoft's CLR; they just finished the JVM version first and that's what's being promoted.
Terseness is largely irrelevant. The right question is not "does this language let me express something in the minimal number of keypresses", but rather "does this language force me to repeat myself endlessly".
Scala has good support for abstracting code; Java, for example, does not. That means that code written in Scala could well be more maintainable (changes need to be made in fewer places), and it also means it's likely to be better quality (people are less likely to copy and paste if it's just as easy to do it properly).
I ran into this just today. I had a bunch of copy-and-pasted code that I was trying to refactor into a sane design, and Java thwarted me at every step. I could see why the original coder had given up! Eventually I had to resort to a hack using reflection, which of course lost me all the benefits of static typing. Thanks, Java. But at least the core algorithm is now stored in exactly one place, instead of there being ten copies of it scattered across as many files.
>> , the rest of us either (a) remember the types of our variables
1) Strong typing helps compilers and processors, not programmers. A weak programmer wouldn't understand the value of a strongly typed language.
2) Any developer who says he 'remembers the types of our variables' is either lying, or inexperienced. You may remember it today, a week from today, or perhaps even a month. You will not in a year. Nobody who looks at your code will 'instantly know' unless you name your variables 'thisIsAnUnsignedInt32', which, would be pretty silly.
3) SE Asia and India produce many fine programmers (FYI, I'm a caucasian american, so no favoritism.). because of the lower prices of programmers from India and SE Asia you're statistically likely to see _more_ of them, hence more bad programmers.
There, fixed that for you.
Strong typing helps _only_ weak programmers, the rest of us either (a) remember the types of our variables or (b) expect "1" + "2" -> 3, not "12".
As a programmer with 25 years of experience, I could hardly disagree more. When developing any large project, static typing is hugely beneficial. It lets you catch far, far more errors at compile time. In a dynamic language, those would all be runtime errors that could easily slip through your testing and make it out to a customer. It makes automated refactoring possible. (Ever try doing a major restructuring of a 500k line code base written in a dynamic language? Good luck!) It enables all sorts of static analyses that let you be a more productive programmer. Try using a really good Java IDE like Intellij IDEA, then try the best Python or Ruby editor available, and you'll feel like you've gone back to the stone age. No "Find Usages"? No autocompletion? No "Go to Definition"? You simply can't do these things in a dynamic language, because the editor has no idea what the type of any variable is.
This isn't meant to criticize dynamic languages. They definitely have their place. But 90% of the symbols in most programs should be statically typed. I don't see why more languages don't simply offer both options. In those that do (e.g. Groovy), type declarations are simply optional. If you declare a type, it gets checked at compile time. If you don't, that symbol becomes dynamically typed. It works very well.
"I'm too busy to research this and form an educated opinion, but I do have time to tell everyone my uninformed opinion."
Hey. Seems like you hate every languages ever conceived!
What's your favorite language?
Excellence is an attitude.
As to Perl's object model, I couldn't agree more. However, from CPAN you can get Moose and MooseX which really clean things up a lot and hide the nasty bits. For instance, with MooseX::Declare, the following is now valid Perl:
use MooseX::Declare;
class Car {
has make => (isa => "Str", is => rw"); # setting a member... they are in a hash type of thing
#some simple methods
method set_make (Str $make) {
$self->{"make"} = $make;
}
method return_make {
return $self->{"make"};
}
I just learned about the MooseX stuff yesterday, so of course my example isn't anything super, but as you can see, it's pretty god damned simple comapred to the alternative.
According to common usage, Python and Scheme are both "strongly typed" as well, since they guarantee that all type errors in programs are detected. This is in contrast to "weakly typed" languages like Perl or K&R C, in which many type errors are silently ignored. That is, all four combinations of strong/weak and static/dynamic typing are possible.
Some people are using the term "strong typing" as a synonym for "static typing"; I wouldn't really care, except that there is no good other term to describe what "strong typing" means.
From a practical point of view, it seems pretty clear that "strong typing" (in the first sense) is important, but I have seen little evidence that static typing is all that useful in a general purpose programming language.
LISP, Perl and OCaml are far more useful than C++, Java and C#
Let's see:
I'm not sure what point you're trying to make, but it doesn't seem to have anything to do with either strong typing or static typing.
The academic idiots,
That's as opposed to the non-academic idiots, who apparently don't even know what "strong typing" means.
You can totally make hashes of arrays and arrays of hashes... http://www.perlmonks.org/?node_id=1977
Try the more advanced languages. Once you have strong typing you can have variables that are of types like:
function of a string, int and a char to a string and then when you apply a char to it the system knows you now have a function of type string and int to string.
yes, the similarity is immediately obvious
--BF code for hello world removed because i was unable to get it past the junk filter. (http://www.roesler-ac.de/wolfram/hello.htm)
# Hello world in perl
print "Hello World!\n";
What would be the result of 354+true? What is the result of true+true? What is the result of false-true? What is the result of true^3? What is the squareroot of true? Does it make any sense? Is it well defined?
In C, any non-zero int value is synonymous with true and the int value 0 is synonymous with false. So, 354+true is something besides 354; true+true is the sum of two non-zero int values; false-true is simply the arithmetic negation of some non-zero int value; true^3 is some non-zero int value multiplied by itself twice; sqrt(true) is some non-zero int value cast into a double and given to sqrt. It does not have to make sense because these operations are well-defined.
I don't mean to sound pedantic, or borish, but C is actually "yeah baby yeah" typed, to enable pointer arithmetic, stack space exhaustion, buffer overflows, and system level development. It's not incorrect to say that it is weakly typed, per se. It's just awkward having to try to explain the direct parallels between the C type system and a 70s style love-in (where anything goes) -- to your manager.
You are where you are at the time you are there.
I'll pass on Javascript as with PHP. Perl is strongly typed, but not statically typed - you add an integer variable to a floating point variable and you will get a numerically reasonable result, unlike something like B.
Lisp is strongly typed. Using an example from an implementation I know best, Emacs Lisp is strongly typed - a cons cell always has a type tagged to it that is enforced by the interpreter. The fact that symbols may be bound to different cons cells in their lifetime matters nothing with respect to strong typing. Obviously, there is no static typing whatsoever.
C was originally a weakly typed language that has moved in the direction of static (but not strong) typing (with GCC extensions). Obviously, untagged unions blow any kind of type checking out of the window. Tagged, honor system unions also defeat static analysis. Unconstrained typecasts prevent C from ever being more than that.
The Unix Shell, has always been strongly typed. The grandfather of them all had every type as a string. More modern equivalents have integer and floating point types and those are strictly tagged.
If a language is strongly typed, then a + i where a is 1.0 and i is 1 will give a sensible result because either the runtime or the compiler will convert the integer to floating point and give the numerically correct answer. In a statically typed language, an error will be thrown at compile time.
Static type checking is particularly important for critical code like CGI and core O/S. The only grey area is when your input consists of bits coming across a wire or from some random H/W device. In that case you must always handcode the type checking.
Strong typing means that the compiler and the (optional) runtime always knows what type an object is. Static typing means the compiler always knows what type an object is and can refuse to compile something in violation of the established typing rules. There is a big difference.
that is simply caused by associative and automatic conversion -- i'm sure you could configure the compiler to throw a warning in this situation.
...
this needs three functions, one of which is implicitly called (actually builtin in this case, but you could easily be adding shapes and strings, it would make as much sense)
int plus (int, int)
string plus (string string)
string int2string(int)
3=plus(1,2)
"3 is not " = plus(int2string(3)," is not ")
"3 is not 1" = plus("3 is not ",int2string(1))
"3 is not 12"=
(unless it evaluates the other way, to 12 is not 3, its been a while since i've done any real programming, and things like this only come up once in a blue moon.)
Terseness is largely irrelevant. The right question is not "does this language let me express something in the minimal number of keypresses", but rather "does this language force me to repeat myself endlessly".
I did not mean "terseness" to be a pejorative. Length of code can sometimes and sometimes not be of assistance to the poor bastards maintaining it after the original developer has gone.
It's my fate in my career that I have been primarily maintaining other people's code and personally, I have an easier time reading small snippets of code in small functions than the multi-K lines of deeply nested if-else/etc. that certain coders prefer.
That was actually a dig on the four-letter P-word which can be compressed into incomprehensibilty.
The stuff I saw on the Scala website looked quite nice and terseness and reducing repetition appears to be one of their stated goals. I applaud them for that. Any time you have enforced repetition, maintenance costs go up regardless of how strict or sane the development environment is.
I need to rewrite a bunch of super-crap CGI code from scratch and I was planning on looking at something Scheme-ish to see if that would work (the core code I would like reuse is all in Emacs Lisp). I do plan on looking deeper into Scala before I propose anything because the Java tie-in might be easier for me to handle politically.
I don't mean to sound pedantic, or borish, but C is actually "yeah baby yeah" typed, to enable pointer arithmetic, stack space exhaustion, buffer overflows, and system level development. It's not incorrect to say that it is weakly typed, per se. It's just awkward having to try to explain the direct parallels between the C type system and a 70s style love-in (where anything goes) -- to your manager.
I hear where you're coming from, brother /.er.
I'm rather amazed at what work has been done in the Linux kernel regarding moving the code towards the static typing model with innovations in C and GCC extensions. Much of the Linux kernel *can* be statically type checked.
I am *so* hoping that Linus writes the Mythical Penguin Month as Fred Brooks did for O/S 360 the 3nd most important O/S, but most important at the time. For all his sometimes abrasive writing style, he has done something I didn't think could not be done. Well more than one something.
The point made by the GP was valid:
http://en.wikipedia.org/wiki/Comparison_of_programming_languages#Type_systems
He said 'most languages are strongly typed' and he is correct. Pointing out 3 weakly typed languages doesn't make him wrong. It's also not the point of his post. The article was probably mistaken for describing Scala as a strongly typed language. While true, it's about as relevant as calling it a language which supports for loops. It's easy to assume they meant to describe it as a static language, since that differentiates it from it's popular competitors (Ruby, Groovy & Python).
...it sounds like an absolute mess for anybody but the guy who wrote the code.
All you need to code Twitter is any language that can wrap SQL....
Add tweet: INSERT TABLE x (x) VALUES (@x, @userId)
Retrieve tweets: SELECT * FROM x WHERE UserId = @userId
I do respect some aspects of Scala, but using Twitter as a mark of success is worse than Hello World.
I'll pass on Javascript as with PHP. Perl is strongly typed, but not statically typed - you add an integer variable to a floating point variable and you will get a numerically reasonable result, unlike something like B.
And add an integer and a string, and you'll probably get a numerical result, but it may not be what you expect, because just like Javascript, Perl does dynamic coercion at run time.
So I have to violently disagree with you, here. The minute a language does free type conversions at runtime without erroring out it's most definitely *not* strongly typed. At best, Perl falls somewhere in the middle, but to call it strongly typed destroys any meaning the phrase has.
Strong typing means that the compiler and the (optional) runtime always knows what type an object is.
No, strong typing means the compiler and/or runtime *enforce* the typing rules, either statically (ie, at compile time) or dynamically (ie, at runtime). The minute a language (like Perl or Javascript, both of which behave identical in this regard) performs dynamic coercion automagically, sorry buddy, you don't have a strong typing system.
The real problem is that people seem to view the term 'weak typing' as a perjorative. It's not. There's nothing wrong with Perl having a weak typing system. It means it's incredibly flexible, and especially great if you want to throw something together very quickly. Conversely, strong typing can be a huge pain in the arse (sometimes I *don't* want Python's runtime throwing friggin' typing exceptions at me all the time). It's all about tradeoffs.
Not much for professionalism, are you? I can say with about 99% certainty that the fact that you know Haskell will have absolutely no effect on your career. The fact that you learned it will have a large effect on how well you can turn problems into programs.
The only stable asset you have is you. If you don't improve yourself, you'll get left behind, and in ten years you'll be working on legacy C# systems and not getting paid as much as the people working on the interesting stuff in whatever language is new and hot next decade.
I've watched small computer development be dominated by BASIC, Pascal, C, C++, Java, and C# (with a lot of Visual Basic thrown in). I have absolutely no reason to suspect it all stops here. Learn or die.
"When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
Pointing out 3 weakly typed languages doesn't make him wrong.
Well it does, indirectly. While you're right, in that in sheer numbers strongly typed languages outnumber weakly typed ones, the claim tacitly downplays the fact that three of the most popular languages in computing today *aren't*. As such, the OP's conclusion, that the strength of the typing system doesn't matter, is unsupported by the evidence.
Brilliant! ;-)
The summary reminded me of this:
http://www.willamette.edu/~fruehr/haskell/evolution.html
But I can't say that I'm not Haskell "biased". After all I tasted "her". And this resembles the experience best:
http://www.xent.com/pipermail/fork/Week-of-Mon-20070219/044101.html
Any sufficiently advanced intelligence is indistinguishable from stupidity.
Actually, C is a prime example of a weakly/statically typed language. The existence of a void pointer (or, actually, values in memory that are not tagged as being of a particular type) means that any piece of memory could be accessed as though it was any type. I could, for instance create an integer variable and a string variable pointing to the same piece of memory in C. This is weak typing. If there was a mechanism that explicitly forbade me from accessing a piece of memory which has been marked as 'type A' as 'type B', we have strong typing. If this can be enforced at compile time, we have static typing. Automatic type conversion does not really require weak typing if the coercion rules are well defined.
Languages aren't inherently fast -- implementations are efficient
C++ is only the backend language for at least two of the sites you mentioned. Yahoo runs mainly on PHP hence Rasmus working there and Google, though I can't speak to what extent they use it felt it was in their best interest to bring on the creator of python.
Does this sig remind you of Agatha Christie?
SatanicPuppy wrote...
:-)
> Perl is weakly typed on a lot of things,
> but it's static for data structures and subroutines.
> So you can have a hash of hashes, or an array of arrays,
> but you can't get arrays in your hashes or vice versa.
Bad puppy
I would like to mod that post '-1 good intentions w/ignorance'.
Thank you, bsDaemon.
It is worth looking at the code in bsDaemon's link.
For all the jokes about perl code being read-only,
this is really pretty clear:
--- begin excerpt ---
Answer: How do I make a hash of arrays?
contributed by chromatic
my %dramatis_personae = (
humans => [ 'hamnet', 'shakespeare', 'robyn', ],
faeries => [ 'oberon', 'titania', 'puck', ],
other => [ 'morpheus, lord of dreams' ],
);
Access it like this:
foreach my $group (keys %dramatis_personae) {
print "The members of $group are\n";
foreach (@{$dramatis_personae{$group}}) {
print "\t$_\n";
}
}
--- end excerpt ---
(I'm guessing 'Hamnet' is a typo).
Anyway...
There are other ways to do this in perl, but the *intention*
should be pretty clear.
Just for fun, does anybody here have a corresponding Scala example?
add an integer and a string, and you'll probably get a numerical result, but it may not be what you expect, because just like Javascript, Perl does dynamic coercion at run time.
Because objects are typed. What would the result be in weakly typed language like C where you do 1 + "1234"?
So I have to violently disagree with you, here. The minute a language does free type conversions at runtime without erroring out it's most definitely *not* strongly typed.
Um, that's part of the definition I gave as a distinction between statically typed languages and strongly typed languages.
No, strong typing means the compiler and/or runtime *enforce* the typing rules, either statically (ie, at compile time) or dynamically (ie, at runtime). The minute a language (like Perl or Javascript, both of which behave identical in this regard) performs dynamic coercion automagically, sorry buddy, you don't have a strong typing system.
It's late, I'm tired, just pass the bowl over to me brother /.er and I'll take a hit off of whatever it is you're smoking.
Strong typing != static typing. Period. Nearly all modern languages and all "scripting" languages are strongly typed, but not necesarily statically typed.
I have always viewed C as syntax sugar for assembly.
The Grey Goo disaster happened 3 billion years ago. This rock is covered in self replicating machines!
But if all you're doing is reinventing Perl with C-like syntax, it's not really a step forward.
Any change to Perl's syntax is a step forward.
(No idea what this has to do with Scala, though.)
The code snippets on the website http://www.scala-lang.org/ are intriguing. It's certainly a terse language. That's both good and bad.
Terse is mostly good, as long as it doesn't come at the cost of readability (see Perl for an example of that). Scala, while being about as terse as Ruby, doesn't seem to be quite as readable, unfortunately. But maybe the code snippets I've looked at aren't the best examples.
If C++ was well suited to web application development, it would be a very common choice for websites. Instead, Google, Ebay, and Yahoo need the performance it offers for their high volume websites. Most smaller volume websites and many of the competing high volume websites are willing to skip the performance of C++ for the faster development time and easier maintenance from using other languages.
For server side applications, the ability to move applications from Windows to Linux to BSD is nice. Scala gives you that while C++ requires a recompile for each platform with a mess of #ifdef and Make options.
Scala has tuples, traits (similar to Ruby mixins, and a very nice solution to Java's lack of multiple inheritance and C++'s multiple inheritance headaches), cases classes that are far more powerful than the C++ switch or other similar C++ constructs (or at least, all of the ones I've encountered), functional language constructs (which in many cases use compile-time tail call optimization to keep run time performance acceptable), and the ability to easily import and use existing Java APIs and libraries and run on existing Java servlet containers. Check out the Scala web development platform lift ( http://liftweb.net/ ) - the example website has a staggering number of features for such a tiny codebase.
Because objects are typed. What would the result be in weakly typed language like C where you do 1 + "1234"?
Probably a warning that you're adding an integer to a pointer, resulting in a pointer result. It's still doing coercion. Worse, it's not at all what you'd expect unless you know the niggly fact that, in C, strings == arrays == pointers.
Um, that's part of the definition I gave as a distinction between statically typed languages and strongly typed languages.
And it's incorrect. Statically typed languages do whatever they do with their types primarily at compile-time. In fact, in many cases, the types could just as easily disappear at run-time, as happens in the case of C (although they don't always... Java, for example, is statically typed, but it retains some of that typing information at run-time so that it can enforce type constraints when casts are performed).
Additionally, and this goes to your claim, a statically-typed language absolutely *can* do automatic type coercion, as does C, for example, by automatically converting floats to ints and vice versa.
In short, static/dynamic and strong/weak typing are 100% orthogonal concepts, and to conflate them is a mistake.
Strong typing != static typing. Period.
Of course. As I say, they're entirely orthogonal. Comparing them doesn't even make sense. So why are you doing it?
Weird casting issues? Maybe your design sucks.
And that of just about every Java library out there. There are a lot of great Java libraries that do lots of wonderful things, but mostly they do a lot of work to negate the advatages of static typing. Working with Java will eventually convince you that dynamic typing is the way to go.
What would the result be in weakly typed language like C where you do 1 + "1234"?
My guess would be it's the memory location where the "2" from that string is stored.
See, C, while superficially weakly typed, is actually a strongly typed language where every object is a memory location. At least that's how I managed to get somebody to finally understand C's pointer arithmatic.
Can't you do weak type casts in C++?
Hey, I'd love to program for fun. But I have to put food on the table. The honeymoon I had with Java is long over, but since I'm making twice as much as I did as a C developer, I'm going to stay with it.
If I could find a company local that would pay me as much, or nearly as much, to work on Scala or Haskell, I would jump ship in a hurry. Until then, I'm not going anywhere.
Astounding - an appropriate and accurate car analogy on Slashdot, for once.
Hats off to you, sir!
The secret to creativity is knowing how to hide your sources. - Albert Einstein
Ruby can be made a lot more terse than Scala can but at that point it's quite difficult to read. I've tried to match the terseness of a number of very compact Ruby programs in Scala and I'm lucky to get within 50%.
At the same level of terseness (maximum Scala terseness, comfortable Ruby terseness), Ruby is easier to read unless you're much more familiar with Scala than Ruby. (Stuff like _._2 < _ in Scala takes a while to figure out, and even when you've got it it takes a bit of thinking.)
At a comfortable level in both languages, I find Scala easier to read but less terse--the key being mostly Scala's descriptive inline operators.
The JVM scales nicely, but you can load stuff on top of it that makes it not scale nicely.
That the Scala folks were careful to let the JVM scale nicely is a credit to them.
(Plus, the scalability also refers to the types of modularity that are available--Scala allows good practice in that area also.)
Erm, I can't think of _any_ situation in applied programming where C++ is a good idea (I design medium to high frequency automated trading algos for a major bank, well run a small team that does that). 90% of the time something like jython or matlab is fast enough and a hell of a lot easier to write and debug, and doesn't give you nearly the amount of options to cut your limbs off by chance - and the 10% of performance bottlenecks can be handled by C/Fortran snippets.
I am aware that many coders seem to think the very messiness of C++ (several languages crunched into one, but not really in a consistent or compatible manner) is somehow an advantage (trying to call C++ DLLs from other languages, oh my god what a pain, tripled if you want it to work on both windows and Linux), but I'd rather fill my brain with domain-specific knowledge and not with language-specific trivia (eg valarray copy semantics are not compatible with STL, but the code using vector<valarray<> > only actually breaks under gcc and works under VC++; and so on and so forth - why the fuck should I care?).
I was in the "C++ is great" camp for a couple of years and filled my head with all those stupid quirks (local typedefs in recursive templated classes, oh what fun) , but at one point realized I just couldn't be bothered. Even Java, as crippled as it is language-wise, is IMO preferable to C++, because once it compiles, you can just use the jar, no linker issues, no memory corruption - and if I do need to manage my memory in a bottleneck, a C snippet will do just fine.
And if I can keep using the JVM but one day switch from Java to a less crippled language, maybe Scala, that's the best of all worlds.
Thanks! I'd mod you informative if I could.
What would the result be in weakly typed language like C where you do 1 + "1234"?
My guess would be it's the memory location where the "2" from that string is stored.
Correct.
At a comfortable level in both languages, I find Scala easier to read but less terse--the key being mostly Scala's descriptive inline operators.
That's probably the correct level of abstraction to think about it. Repeated sequences of anything are going to be mind numbing. Shorter sequences are going to be easier to grasp at first sight. But only on average and the 4-letter P-word has certainly proved that very short code isn't necessarily readable or maintainable.
My Perl colleagues are swooning at Moose. It certainly seems like something to take note of, if you're into that sort of thing (Perl, that is).
xkcd is not in the sudoers file. This incident will be reported.
I know.
http://www.kichwa.com/quik_ref/spec_variables.html
http://www.perl.com/doc/manual/html/pod/perlop.html
Can you explain why JavaScript is weakly typed? I allways was of the impression it is strong typed.
angel'o'sphere
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
I've read that, aside from startup times, the JVM is extremely fast these days. But I thought most well-written Java (and by extension, Scala) applications are still 2-10 times slower than equivalent C.