where programming languages are lagging

All things techie, be they discussions on troubleshooting, video encoding, programming, or algorithm design.

Moderator: Nuxius

where programming languages are lagging

Postby TerraFrost » Tue Feb 15, 2005 11:03 pm

all programming languages have their strengths and weaknesses. here are a few i've observed.

1. java can't perform "switches" on strings. ie. say temp will either be "this", "that", or "it". you can't do 'switch (temp) { case "this": break; case "that": break; case "it": break;'. what you'll have to instead do is use hash codes. in contrast, php can.

2. java shouldn't mandate try / catch blocks when doing file / input I/O. sure, they have their uses, but not to the average user, imho. in fact, imho, all they really do is impede the average user.

3. java should have more comprehensive official libraries. php has built-in functions to calculate such obscure things as the edit distance between two strings, can read files in dozens of ways (ie. fopen, file, file_get_contents, etc), has all kinds of nifty array functions (array_map, array_walk, implode, explode, etc). java has none of these.

4. php should support objects as well as java does. in java, if function a() returns an array, you can reference the 1st element in the array by simply doing a()[0]. in php, you'd have to do "$temp = a(); $temp = $temp[0]". i imagine there are other, similar, deffeciences with objects in php, but that's the only one i can think of, off hand.

now, there are some things that java lacks that php may or may not lack, too, such as templatable objects, friend functions, pointers / references, etc, but i don't use those, so i can't really comment. likewise, there are other things that php does that java doesn't do (such as allowing variables to assume any type, be it an object, primitve, or whatever), but that's not a feature i use all that much, and don't know if java would gain all that much be implementing it.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby TerraFrost » Sun Apr 03, 2005 7:05 am

the way files have to be included in java is pretty stupid, too. you have to put the files you want to include into a package, put the files for that package in a directory that has the same name as the package, and... all in all, i think it's stupid. you can read up on what all you have to do here:

http://www.kevinboone.com/classpath.html

in php, you just do include('whatever/whereever.php').
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby Fiedler » Sun Apr 03, 2005 4:16 pm

Hi,

Hope you don't mind me dropping in on your forum here, but I wanted to note that Java 1.5 does address some of your concerns. Specifically, a Scanner class has been added to allow for easier IO, and the generic/template programming paradigm has finally been introduced.

Switches are basically syntactic sugar to take the place of a sequence of if-thens, and most programmers I've heard discuss it prefer the latter. But, I'm more of a switch man, personally. Why would you use a hash code, though, when you can just write a sequence of if-then statements?

Oh, and I'll note that Java has no functions whatsoever -- it has methods, and further that Java doesn't lack references; all Objects are stored by reference... you just can't fiddle with the references like you can in other languages.
User avatar
Fiedler
Traveler
 
Posts: 7
Joined: Sun Apr 03, 2005 7:27 am

Postby TerraFrost » Sun Apr 03, 2005 9:17 pm

I didn't know about the new Scanner class - thanks for pointing it out! :)

As far as switches are concerned - I'm obviously a switch person, myself, too, heh, but I also think that if Java is gonna include a feature such as switches that they ought to make it as complete as possible.

Java doesn't lack references; all Objects are stored by reference... you just can't fiddle with the references like you can in other languages.

I believe that PHP's handling of objects is similar, although I can't say that definitively, as I haven't done OOP in PHP, before. (I think that OOP only truely excells over more "iterative" programming in libraries)

All that said, welcome to Frost Jedi! :)
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby Fiedler » Sun Apr 03, 2005 9:43 pm

This article is a great resource that goes into the changes that were made in Java 5. The addition of generic programming is a great feature, in my opinion, because it eliminates a lot of potentially unsafe casts, and, in general, just makes things simpler. It doesn't offer the same level of flexibility in terms of generic programming that you'll find in C++, but then that's true with respect to most features found in Java -- safety over flexibility, they say.

TerraFrost wrote:if Java is gonna include a feature such as switches that they ought to make it as complete as possible.
I definitely agree. I think, now that primitive types can be automatically "boxed" and "unboxed" into and out of their wrapper classes, the switch mechanism should function on a statement such as
Code: Select all
switch (term)
{ case a: x;
  case b: y;
          z;}

as if it were the statement
Code: Select all
if(term.equals(a))
    x;
else if(term.equals(b))
    y;
else
    z;

TerraFrost wrote:(I think that OOP only truely excells over more "iterative" programming in libraries)
I think another big selling point is that, often times, OOP code is easier to read and follow for someone becoming acquainted with a project, which, when dealing with large projects and code bases, and the inevitable need for new programmers, can be important.
User avatar
Fiedler
Traveler
 
Posts: 7
Joined: Sun Apr 03, 2005 7:27 am

Postby TerraFrost » Sun Apr 17, 2005 11:38 pm

There's a property whose name I can't recall (I think it's either the distributive property, communative, or associative) that states that if a = b and b = c then a = c.

Anyway, whatever the name of that property is, PHP's == operator doesn't have it. As an example, the following all evaluate as true in PHP:

"php" == true
"php" == 0
false == 0

From those, we can conclude the following:

true == "php" == 0 == false

I don't know what the above would evaluate as in PHP, but it is, at the very least, counter-intuitive.

The reason I imagine that it's set up this way is because $var and isset($var) are supposed to be equiv. The only times when they're not equiv. is when empty($var) is true.

Further, PHP casts strings to ints by seeing if the first character of the int is a number and then going on, from there, until a non-numeric character is encountered. In this way, "2php" is 2 and "php" is 0. Because php is a dynamically typed language, casting takes place automatically, too, so "2php" == 2 is true.

Similarily, 0 == false because that's how it is in most langs - 0 for off or false, 1 for on or true.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby Gigafrost » Mon Apr 18, 2005 2:52 am

Very interesting observation there.

I think "transitive" is the main property you're refering to, although there's a little symmetry property as well. So, in other words, PHP's == command does not properly define an equivalence class since it's not transitive, heheh.
User avatar
Gigafrost
Frost Weapon
Frost Weapon
 
Posts: 4900
Joined: Wed Dec 04, 2002 5:09 pm
Location: Here

Postby TerraFrost » Mon Apr 18, 2005 3:07 am

yeah - i think transitives it - thanks :)

incidently, the above was derived from php.net's entry on type comparisons. the === operator does a more traditional equality test (as evidenced by the table on the afore linked to page).
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby TerraFrost » Wed May 11, 2005 4:13 am

From php.net's entry on Arithmetic Operations...

The division operator ("/") returns a float value anytime, even if the two operands are integers (or strings that get converted to integers).


This means that the FPU is used even when it doesn't have to be. This means that processing divides in PHP can potentially take more time and use more power than they need to.

Shame on my CS352 class for contributing to anything other than a grade.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby TerraFrost » Mon Aug 01, 2005 5:31 am

vBScript is not a language I like. Granted I'm pretty new to it, but the syntax is totally alien to me. It's not quite as alien to me as I suppose asm would be to a pure C programmer, but still!

All the functions are named differently than they are in PHP. The best example, however, is Mid. In PHP, it's substr.

Concatenating strings is done with ampersands - not dots or pluses, and "\" is actually a valid string.

Equality is, oddly, similar to SQL (ie. not equals is <>, equals is =, etc).

And then, of course, there are the errors. I don't understand why I'm getting 'em for my latest program. Actually, to be honest, I haven't understand the past few errors I've come accross - I've just rewritten my script so as to avoid the conditions which bring them about. I mean, it really doesn't seem like I ought to be getting them... bleh.

Hopefully microsoft.public.scripting.vbscript will be able to help me out :)

Incidently, I suppose condemning older versions of languages is a tell tale sign that someone doesn't know a language very well. If I saw someone condemning PHP3 for stuff that PHP4 fixed, I'd consider 'em to be kinda stubborn or something. I guess, however, I've kinda done the same thing with Java (I've condemned older versions)...
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby Drazo » Mon Aug 01, 2005 9:43 am

Concatenating strings is done with ampersands - not dots or pluses, and "\" is actually a valid string.


Pluses are reserved for adding two numerical values (usually for adding up variables). :p Dots are reserved for marking up the property to the previous word. Only "anything in here" is applied as a string.

ex:

strex = "I am a banana!"
anotherstrex = " But I am not a \ nor am I "
numex = 7
anothernumex = 3 + numex
textbox1.Text = strex & anotherstrex & anothernumex

But that example might not work in other certain basic programming languages, such as Dark Basic.

Equality is, oddly, similar to SQL (ie. not equals is <>, equals is =, etc).


It is basic after all, and basic is closer to english logic. Makes more sense then the ugly looking !, ==, ~~ or whatever.... :p
[Don't watch here carefully]
User avatar
Drazo
Heroic Guard
 
Posts: 3935
Joined: Mon Jan 06, 2003 8:59 pm

Postby Gigafrost » Tue Aug 02, 2005 1:42 am

Drazo wrote:
Concatenating strings is done with ampersands - not dots or pluses, and "" is actually a valid string.


Pluses are reserved for adding two numerical values (usually for adding up variables).
Personally, I find this to be completely rediculous since older versions of basic had no problem concatinating strings using the plus. Most modern languages are able to use whatever symbol they want, to boot. At best I would think the requirement to use a specific non-math symbol would only be if Visual Basic was similar to PHP in that a variable can truly represent anything even after being first defined, and after that only for certain speed considerations. (For example, many of the choices for C were for program speed and program size comparison, but those choices are pretty arbitrary in some of C's descendants)

Equality is, oddly, similar to SQL (ie. not equals is <>, equals is =, etc).


It is basic after all, and basic is closer to english logic. Makes more sense then the ugly looking !, ==, ~~ or whatever.... :p
Only makes sense when comparing numbers because <> literally "means" "less than or greater than." != makes more sense than <> because in most languages that use it, it literally means "not equal." That's because the exclamation mark is a symbolic representation of the logical NOT operation in those languages. IMO, since the symbol chosen for basic's inequality does not represent the operation being performed, I'd argue that it's farther from english logic than the "ugly looking" alternatives.

Well, unless you meant "english logic" in the sense that packages sent by land are SHIPment and packages sent by sea are CARgo. IE, completely backwards.
User avatar
Gigafrost
Frost Weapon
Frost Weapon
 
Posts: 4900
Joined: Wed Dec 04, 2002 5:09 pm
Location: Here

Postby TerraFrost » Tue Aug 02, 2005 3:55 am

At best I would think the requirement to use a specific non-math symbol would only be if Visual Basic was similar to PHP in that a variable can truly represent anything even after being first defined, and after that only for certain speed considerations. (For example, many of the choices for C were for program speed and program size comparison, but those choices are pretty arbitrary in some of C's descendants)

I'm actually pretty sure that you can't do function or operator overloading in PHP. Default argument lists are the closest that you can come.

Also, the following kinda provides an interesting comparison of PHP / vBScript / JScript:

http://phplens.com/phpeverywhere/node/view/30
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby TerraFrost » Tue Aug 30, 2005 6:57 pm

Here's another page that compares PHP and vBScript:

http://songhaysystem.com/document.php?cmd=getDoc&get=19

One thing I've noticed (and also don't like about vBScript) is that urlencode is only available for vbscripts running on a webserver. So basically, I have to reimplement something that is already in vbscript to get it working in a simple *.vbs file. bleh.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Postby TerraFrost » Fri Oct 07, 2005 9:12 am

As an update to the above, Escape - which doesn't require a webserver - apparently does the same thing as urlencode.

Aanyway, here's a comparison of C# and Java:

http://www.25hoursaday.com/CsharpVsJava.html#strings

Unfortuantely, I haven't had much of a chance to look at it, yet.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Next

Return to Communications Center

Who is online

Users browsing this forum: No registered users and 1 guest