• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Your experiences with scripting languages

 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not starting a war! I need some light!

I have started programming in Python and I found a few (no, many) things very weird and sometimes meaningless when I compare it with Java or C#. And there are so many things lurking in my mind these days that I want to get cleared for my lifetime.

--> Why are the scripting languages so hyped?

I just don't understand why. Of course, they are easy to program, you don't have to declare variables, you don't have to catch exceptions, hell, you don't even have to compile. Though it seems like exciting for people who don't know any programming language before, it seems like a recipe for disaster to me.

Let me give a small example:

I have a small program that tries and opens a socket or prints a message if the socket can't be opened. My Python program looks something like this:

I was happily using this code for one month till I hit a point where I couldn't open the socket and blow, I got a syntax error (at runtime, you hear me? RUNTIME) because I didn't import the 'socket' module. I was disgusted with myself and then with my scripting language. If I were to write the same program in Java, I would have compiled the code (no, eclipse will do it for me) and I would have been told by javac that, "You idiot, import the class before you try to do anything with it or go to hell."

I am using an IDE for Python which is just a fancy editor. Again I am NOT blaming the IDE because it has it's own limitations due to the language itself. Huh! I can't even get auto-complete for all the variables. There are so many things like type-safety, checked exceptions (even though people still argue over this), enums, interfaces that I'm missing while programming in a scripting language.

And many of the example say that Java gets really bigger and bigger and you will have a huge code to manage with, but I think Java with it's classes, packages, jar files makes it very easy to maintain and we always have our best friend 'ant' to make our builds. And the example I saw on most of the web-pages that talks about how tough and cumbersome it is to program Java give the "Hello world program" as their example.

Java:

Python:

Yes, I agree, scripting languages are the best ones for 'Hello World' programs but how many of us write "Hello World" programs in our daily life? Give me a break.

And about declaring variables, if you don't do it in Java, your IDE will complain as soon as you finished typing it. I use eclipse and I never declared a variable. This is how:

I just assign a value to a variable --> Eclipse points me the error --> I hit Ctrl + 1 (Quick Fix) --> I hit Enter (here my IDE declares the variable at the top or whichever scope you chose). And because my language is strongly-typed, I have auto-complete and I will never have a syntax error ever in my life programming in Java.

Many method calls in most of the scripting languages are determined at runtime, but what happens if we misspell the method name? I am having sleepless nights because of this. I would like to know the reason why scripting languages like Ruby (which doesn't care about types) are becoming popular nowadays while Java is becoming more and more strongly typed (with the addition of Generics). I always like to catch the errors as close to the problem as possible and as early in the development life-cycle as possible. With compile time safety, I can achieve this but still why are the scripting languages beating Java? Or are they really doing?

I am not against Python or any scripting language for the matter, but I would like to know how to avoid these things and how my programming approach must be while writing programs using these languages. And I would like to know why this kind of programming is really picking up nowadays.

Please share your opinions and give me your suggestions.

Thank you,
Srikanth
[ March 07, 2007: Message edited by: Srikanth Raghavan ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikanth Raghavan:

--> Why are the scripting languages so hyped?


You answer your own question here:

Originally posted by Srikanth Raghavan:

they are easy to program, you don't have to declare variables, you don't have to catch exceptions, hell, you don't even have to compile.



It is up to the programmer to determine where these pros outweigh the rich language features of Java.

Originally posted by Srikanth Raghavan:

Many method calls in most of the scripting languages are determined at runtime, but what happens if we misspell the method name?



You cannot tell me that you just whip out some code and it runs flawlessly in any language. You code, compile in some cases, test, and repeat. If you aren't getting full code coverage in your test scenarios, that's a problem with your tests, not with the implementation language.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"You idiot, import the class before you try to do anything with it or go to hell."



Ah ! but at runtime lurks the NoClassDefFoundError if your jar file is not in your class path. Yes, atleast it is compile time safe. I have not tried scripting as yet. I did write basic unix scripts once.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that Extreme Programming was born out of practices established by a Smalltalk programming team. Smalltalk is also a weakly-typed, late-bound language, and many errors that would be found at compile-time in Java are found at runtime in Smalltalk. Does that make Java "better"? No, it really doesn't. Does that mean that excellent test coverage is important in Smalltalk, and that the way you program in Smalltalk is different from the way you program in Java? Yes, it does.

If you're using a weakly-typed, late-binding language, then it's important to get as close to 100% test coverage as possible. You did not do that with your socket program; you had 50% coverage at best, which is not good.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, leave it to EFH to come in here and take it to a real technical level that makes sense. Stop hijacking these threads.

Mark
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to automate a process wherein I replace the occurences of the word "xyz" with "abc" and then launch a process.

I can cook a PERL script quickly to do this. I am not worried about runtime errors (actually Perl has a pre-compiler so I needn't worry anyway) because I am going to test this now and make sure it works.

In my experience scripting languages are used a lot in these small utility/automation programs. Imagine doing the same thing in C.

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is true, getting started with a scripting language can be frustrating. I love Python but had a couple of "intense" weeks with it at first. But the same is true of compiled languages. There is no silver bullet.

I agree with the last post about easy, throw away code. Here are some other thoughts:

-- Libraries. I've used Python to write a small client that would load-test a website. The Python libraries had a "semaphore" that I could use to limit the number of concurrent users. And I could download an HTML page to a file in 1 call.

-- New concepts. I've written about this elsewhere but one _thinks_ differently in various languages. This can cross-pollenate: Ruby could influence your Java style.

-- Autonomy. I've recently used Groovy to use my team's Java libraries to hit an OODB. I'm doing stuff in 30-40 lines of script. It took a _whole_ day to get the 1st script working (mostly due to classpath issues) but now I have a great new tool that is completely independent of Eclipse (as great as it is). That is power.
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, Scripting languages should only be used for batch jobs and other small utility programs and we shouldn't consider them for bigger applications? Is that right?

And to make sure my program works and it doesn't have any syntax errors, I must have code coverage. That means, we don't have to compile but we have to have run code coverage to make sure we don't have any bugs. Hmm....

Somewhere I am still not convinced but I have to.
 
M Easter
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
re: only for small utility programs.

In my experience, this is essentially true. That statement will draw fire from some people (Ruby on Rails, the Zope/Python folks, PHP BB writers, etc), but _I_ tend to wonder if dynamic languages scale with respect to (a) lines of code or (b) # of people on a team.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by M Easter:

In my experience, this is essentially true. That statement will draw fire from some people. . .



Ready. . Aim. .
One of my former employers had some huge team-built and maintained Perl/TCL apps even though the syntax of Perl lends itself to the lone guru kind of development.
One local company I have contacts with does nearly all their development in Python and it's a successful 18,000-employee enterprise.
A team at my current employer uses Zope/Python for a number of non-trivial applications. I've done some work with it and found it as useful as the typical Java JSP-servlet-db framework with a lot less code overhead.
I think problems with scale are caused by people not using a language effectively and not having a good software development process. Having worked in a number of shops with a number of languages, those problems don't seem to be language specific.
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joe Ess:

A team at my current employer uses Zope/Python for a number of non-trivial applications. I've done some work with it and found it as useful as the typical Java JSP-servlet-db framework with a lot less code overhead.
I think problems with scale are caused by people not using a language effectively and not having a good software development process. Having worked in a number of shops with a number of languages, those problems don't seem to be language specific.



But I find it more difficult to write client code in Python than in Java. For example, unless you document your method saying what is returned (a Cat or a Dog or both depending on some condition), I don't stand a chance to know about it. If you don't document I have to look into your code. When I have to look into my libraries for building my Client Code, you know I am programming to implementation which is really a bad idea.

Any thoughts about this?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikanth Raghavan:
When I have to look into my libraries for building my Client Code, you know I am programming to implementation which is really a bad idea.



We had a similar problem in Java with collections until 1.5 gave us generics so we could declare a collection of a particular type. I'm still using JDK 1.4 (employer uses WLS 8.1) and don't find using Object collections particularly onerous.
As for "programming to an implementation" I don't think that looking at the return type counts. If you make assumptions as to what the library does that are not based on a method signiture, that's programming to an implementation. Like if I'd made a method that returned Pet, but you looked at the code and saw I only used the Pet subclass Dog, so in your code you always used Dog. The danger is that one day I'd change my code to use Pet subclass Cat, which would not break the method contract, but it would break your code.
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joe Ess:


We had a similar problem in Java with collections until 1.5 gave us generics so we could declare a collection of a particular type. I'm still using JDK 1.4 (employer uses WLS 8.1) and don't find using Object collections particularly onerous.
As for "programming to an implementation" I don't think that looking at the return type counts. If you make assumptions as to what the library does that are not based on a method signiture, that's programming to an implementation. Like if I'd made a method that returned Pet, but you looked at the code and saw I only used the Pet subclass Dog, so in your code you always used Dog. The danger is that one day I'd change my code to use Pet subclass Cat, which would not break the method contract, but it would break your code.



Joe, That's exactly what I was trying to say. I agree to your point that Generics was added only after 1.4, but I would always wrap an Hashtable with something like PetMap and I will have my own methods that take and return Pet and not Object.

Eg:-



Even though I don't have Generics in 1.4, I got around the problem? But I can't do the same with Ruby or Python because there's no return type.

And coming to the second part of your solution, I agree that one may still cast my Pet to some Dog or Cat by seeing my implementation (although my return type is explicitly Pet) but I will not join him in my Java league and neither will the other Java devs. And he will hate code reviews.

I agree with M Easter that scripting languages can be difficult when the lines of code grows and it all depends on the context of our current problem. Personally I would like Java or C#.

-- Srikanth
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikanth Raghavan:
I would always wrap an Hashtable with something like PetMap and I will have my own methods that take and return Pet and not Object.


I'm aware of that idiom and never used it. My personal feeling is that it introduces an unnecessary class to replace a simple cast. If one were to change a method's return type, which itself is a Bad Thing, a simple test case would reveal the problem.

Originally posted by Srikanth Raghavan:

And coming to the second part of your solution. . . And he will hate code reviews.


Correctly so, as I was illustrating the problem with coding to an implementation.

Originally posted by Srikanth Raghavan:

Personally I would like Java or C#.


If that's what works for you, great. I only wanted to point out that people are getting non-trivial work done with scripting languages.
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joe Ess:

If that's what works for you, great. I only wanted to point out that people are getting non-trivial work done with scripting languages.



I am doing the exact same thing. I am actually enjoying Python as long as I don't compare it with Java or C# and when I'm writing small programs.

-- Srikanth
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikanth Raghavan:
But I can't do the same with Ruby or Python because there's no return type.



There's always documentation...
 
reply
    Bookmark Topic Watch Topic
  • New Topic