This is topic Perl help [Now Java help, what a time to be alive] in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=025878

Posted by Hobbes (Member # 433) on :
 
I’ve been asked to create a web service for work, now I consider myself to be a decent programmer, but I’ve never done any web related things before besides some really basic html and javascript. I’m trying to leave in time for KamaCon (once I leave, works over for me) and I may even have to take a week off in between. So I’m rather pressed for time.

And I now have to learn Perl, write the web service, and write a download version as well before I go, not to mention helping put together a website and converting various random data, and insert metadata into all sorts of created data files. Why am I telling you all this? Because I feel guilty asking for help, but I’m going to anyways.

So I have a few questions overall, but let’s start with my specific one.

code:
sub ConvertString {
local ($str) = @_;

print "Length: $#str<br>\n";
for ($i = 0; $i < $#str; $i++) {
print "$i: _$str[$i]_<br>\n";
if ($str[$i] == ' ') {
print "If!<br>\n";
$str[$i] = '_';
}
}

print "Conversion: $str<br>\n";
$str;
}

Obviously this isn’t the entire thing, but if you want to see the whole code output, go here and click continue.

The output from this function is:

code:
Length: -1
Conversion: List File
File Name: List File

What’s going on here? The string is clearly there and stored in $str, but it’s length is -1? I’ve tried all sorts of different things, like @str, or just declaring str and then pushing @_ into it but this is the closest to success I can come. Someone who knows Perl, what am I doing wrong? (In case you’re wondering and can’t figure it out, this is supposed to replace spaces with ‘_’s, I can do this without a subroutine, but I need to figure this out anyways so I want to get this to work.

Hobbes [Smile]

[ August 03, 2004, 01:02 PM: Message edited by: Hobbes ]
 
Posted by Farmgirl (Member # 5567) on :
 
Exactly why are they saying you HAVE to learn Perl?

FG
 
Posted by fugu13 (Member # 2859) on :
 
I believe your problem is simple.

@_ is an array.

Use shift @_ to take the first/only element off the arry and assign it to the string variable.
 
Posted by Hobbes (Member # 433) on :
 
Well orginally I was supposed to learn SOAP, XML, and Perl, but I told them that I could get done everything they needed with Perl only so I'm off the hook on the other two (though I did learn a bit of those). Also I'm supposed to use Java, which I've had one, one semester course on, and C, which I learned the week before I came to the job (I knew C++ very well though, so that wasn't that bad). I was also supposed to help out with javascript (which I knew how to do form validation with). I think my employers feel that if I don't know every language out there, it should only take me a few days to learn them. I'd say I was inspired by their confidence in me, but I think it's more lack of knolwedge about reality than confidence. [Wink]

Hobbes [Smile]
 
Posted by Hobbes (Member # 433) on :
 
Thanks Fugu! Once I ge this licked I'll have some broad questions instead of my lack of debugging skills on a language I've been learning in the last few days. [Smile]

Hobbes [Smile]
 
Posted by Farmgirl (Member # 5567) on :
 
Well, I can't help, because I can't even read the code you posted (old eyes), and I don't know Perl. But I do find it amusing that you told them that
quote:
I could get done everything they needed with Perl only
when you hadn't even taught yourself Perl yet...

[Wink]

FG

edit: aahh...for the confidence of youth!

[ July 13, 2004, 02:03 PM: Message edited by: Farmgirl ]
 
Posted by Hobbes (Member # 433) on :
 
[Razz] Well number one I can (with help from Hatrack of course [Big Grin] ) and number two I meant SOAP and XML weren't required. [Razz]

Fugu, I did it and it's still giving me negative 1 for the length (but it is also still recgonizing and printing out $str right). [Confused]

[EDIT:
actual line is this:
local ($str) = shift @_;
]

Hobbes [Smile]

[ July 13, 2004, 02:05 PM: Message edited by: Hobbes ]
 
Posted by Farmgirl (Member # 5567) on :
 
Hobbes - you don't have AIM where you are? Fugu is almost always on -- I ask him web questions there all the time (and then know one else but him knows how dumb I am [Wink] )

Of course, posting it here helps us ALL learn..

FG
 
Posted by Hobbes (Member # 433) on :
 
Well no, techincally I can install it but... well I feel werid doing that at this computer. Especially since as soon as I leave my Boss gets my computer! [Angst]

If this takes much more time I'll probably use the java version despite my hatred for it. [Smile]

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
Strings are not arrays, btw.

Use length($stringvariable).
 
Posted by Hobbes (Member # 433) on :
 
They aren't!?! What kind of stupid language is this. [Grumble]

Thanks! [Cool]

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
A sane one. Strings aren't arrays semantically, and thus shouldn't be treated like ones. That just causes logic errors.
 
Posted by Hobbes (Member # 433) on :
 
Well to me a string is an array, it's a linear series of characters, but let's not get in a semantics argument.

OK, I think this is the last picky question, I use this line:

code:
$str =~ s/" "/"_"/g;

I've also tried it without the quotes but that causes an error. The line certainly isn't working, it's leaving the string as is (there's a space in the middle and it's supposed to end up as a '_', what the syntax on this command?

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
On the semantics, a string is not just a linear sequence of characters, nor is an array anything that is a linear sequence. Tuples are a semantically separate linear sequence, for instance, but are distinctly not arrays semantically.

As for the re, do you just want each space, or do you want clumps of whitespace as well (multiple spaces, tabs, et cetera)?

If just single spaces:
code:
$string_test =~ s/\ /\_/g;


 
Posted by fugu13 (Member # 2859) on :
 
Oh, a useful hint. All escape sequences using \ in re's use alphanumerics afterwards. So if you're unsure, you can always just use \ before a non-alphanumeric character and it won't hurt anything.
 
Posted by Hobbes (Member # 433) on :
 
OK, it now officialy works. Thanks [Smile] .

So here's a my more general question for you. I've gotten to this page, it will ask for some metadata and a file. Now I don't know how to upload a file with Perl, but I've seen various pages that at least say they'll explain it, so don't feel you have to do so. Once I get the file and the metadata, I'm going to want to run a Java program on the file and then return it. Since you know Java this may be easier. [Smile]

So here's my questions:
Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
Why on earth is perl in the loop? The perl program is completely extraneous.
 
Posted by Hobbes (Member # 433) on :
 
Well... for one I wouldn't know how to do it with java.

[Nor was I aware that the cgi stuff can be done with Java]

Hobbes [Smile]

[ July 13, 2004, 03:08 PM: Message edited by: Hobbes ]
 
Posted by fugu13 (Member # 2859) on :
 
You don't know how to do it in perl, either. And Java's a heck of a lot more similar to C++ idiomatically than perl is, you'll pick up the java way in no time, but doing it in perl decently will be a whole new level of study.
 
Posted by fugu13 (Member # 2859) on :
 
There's nothing more special about one language on the web than another. Of course, java programs typically aren't run through CGI (overhead), but they run the web to a huge degree. Among other things, a properly tuned java server is faster than a perl or php one.

Instead one runs a java program through a Java server such as Tomcat or JBoss (which actually runs on top of a java server such as tomcat or jetty itself). Setting up Tomcat adequately for your needs would be easy.

One huge reason you should do this is the truly obscene overhead you'd be entailing if more than one person ran the CGI script, causing multiple instantiations of the java program, each in its own JVM.
 
Posted by Hobbes (Member # 433) on :
 
I wouldn't worry about the overhead on this, it;s not going to be incredibly popular. Seriously, time is a factor only one client at a time. However, I most certainly do not have the type of acess to do anything to the server besides put in data files and cgis (which I had to go to the sys-admin to get permession to do). No one would ever let me set anything like that up.

I think I need to stick to Perl for the cgi end. Is it really that hard to call a Java program from Perl?

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
How on earth are you going to get permission to run a java program on the server, then?

No, its not terribly hard, you could just do it through the shell, even. But I'm being quite serious when I say if two people use that script at once every other activity the server engages in will see a significant performance degradation.
 
Posted by Hobbes (Member # 433) on :
 
Well perhaps that's something to worry about too, if I put the .class files in the cgi folder I take it then they wont run without something else?

Also, really don't worry about the preformance bump, I know, I hate throwing preformance out of the window, but so long as I can run one file fast, nothing matters. No one does anything on this server, this wont be a popular web service, at least not that popular, don't worry about it.

Hobbes [Smile]
 
Posted by Bokonon (Member # 480) on :
 
I'd have perl write out the metadata and uploaded file to a known location with a standardized name. Then have your perl code execute a java command line program. Assuming you have compiled all your Java code, and placed them some place that your perl/CGI can access (this means you also need to expose your JVM/JRE to the perl code so it can be used), the general idea would be:

/JAVA_HOME (Exposed for use with your web app)

/WEBROOT
/WEBROOT/static_stuff
/WEBROOT/perl_suff
/WEBROOT/java_stuff (Java uses a hierarchical format to organize code; this is a non-issue if your code is essentially one class, with no user created packages)
/WEBROOT/metadata_and_file

Have your perl execute: "java MyCode.class <arg1> <arg2> <etc...>"

If you need to import some custom classes/packages from elsewhere, use the -cp commandline option of the java command, and supply the path to the packages.

Of course, on top of a resource issue, this is potentially a rather large security risk (if someone can stuff the call from perl to java with malicious code).

-Bok
 
Posted by Hobbes (Member # 433) on :
 
Thanks Bok! One thing though, my code is a whole lot of files (I'm half way done with the Java code at best and I'm up to 7 classes). I'm a little confused about what you said you have to do if you've got multiple files. Can you explain that more?

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
Okay, in that case I'd say learn php better and write the entire program using that. PHP is idiomatically quite similar to C++, it runs plenty fast for your purposes, and it saves you all sorts of silliness.
 
Posted by Hobbes (Member # 433) on :
 
I believe it, except I can't use PHP for various reasons (non-techincal reasons, employer related reasons). Which is a real shame since I already learned some PHP a while ago and have a pretty good book on it. [Grumble]

Hobbes [Smile]

[ July 13, 2004, 03:38 PM: Message edited by: Hobbes ]
 
Posted by Bokonon (Member # 480) on :
 
Honestly, you should have pushed to have tomcat set up on your server. It's lightweight, and it would let you work completely in Java. As well, I would have actually tried to use SOAP/XML, since that what how standard web services are built on, and there are tons of support to make this easy on you in Java (in perl too, I'd imagine, but your boss has made Java a requirement).

Now you have an amalgam of various code bases, based on different languages, that has potential security risks, as well as obvious performance issues. If this thing ever gets even a bit popular, and performance becomes a requirement, someone is going to have to throw out a bounch of your code, one way, or another.

-Bok
 
Posted by Bokonon (Member # 480) on :
 
Hobbes, how you have to handle you classes depends on how you have used the Java packaging mechanism (using the 'package' functionality in your source code).

-Bok
 
Posted by fugu13 (Member # 2859) on :
 
He's not using SOAP because his employer didn't really want a web service, his employer wanted a web page people could use non-programmatically.
 
Posted by Hobbes (Member # 433) on :
 
Sigh. Well like I said I took one course on Java, combine that with a good book on Java that I have, and it's high smilarity to C++ and I can do just about anything you'd want out of it on a single computer so long as it doesn't have to look fancy, and even then I could at least make something mediocre. However, I don't know any of the details, just the syntax really. I've been writting my program in Eclipse, I don't really know what you mean by packaging.

Hobbes [Smile]
 
Posted by Hobbes (Member # 433) on :
 
Fugu is right about that, though his employer has been constantly talking to him using the term 'web service' so much so that now poor Hobbes has it permentantly ingrained on his psyche and is consequently unable to think of anything else to describe what he's working on.

Hobbes [Smile]
 
Posted by Bokonon (Member # 480) on :
 
Okay, so it's not a "real" web service, per se.

As for as Java packaging is concerned, here's a tuorial (I can't vouch for the quality, it's the first google hit on the search "Java package tutorial".

http://jarticles.com/package/package_eng.html

-Bok

[ July 13, 2004, 04:28 PM: Message edited by: Bokonon ]
 
Posted by Hobbes (Member # 433) on :
 
OK, let's say I figure out this packaging thing, run my Java program just find, I've created a new file on the server (by the way, the returning file is binary, if that makes a difference, I assume not, but hey) and now I want to return it to the user. So questions ons that:

Hobbes [Smile]
 
Posted by Bokonon (Member # 480) on :
 
The reason there will be a performance hit is because everytime the java command is invoked, a whole new JVM is started.

Now, this isn't as bad as it used to be; the JVMs are a whole lot smarter about how much they start up before running your code. It used to be that a simple helloWorld app could take MBs of memory to run!

I honestly don't know of a way to send the Java data back to the script, particularly without knowing the use cases involved. In any event it is likely to be kludgy.

-Bok

EDIT: what you can expect in your perl script depends on how you invoke the java command. By default, using something like an exec() call, you cannot assume the program is done, since exec returns once it has spawned the requested command, not once the command completes (which is pretty hard for a program to figure out, and requires a bunch of error handling). If you want it to be synchronous (wait until java command completes before continuing), you need to think about what happens if a processing request takes longer than expected in the Java code, if there is a fatal error in the Java code, or hardest of all, if there is a non-fatal error (an exception) in the Java code, which means the java command completes and returns, but your data is in a bad state.

-Bok

[ July 13, 2004, 05:47 PM: Message edited by: Bokonon ]
 
Posted by Hobbes (Member # 433) on :
 
Yah, I'm not at all worried about preformance, but if something does happen it would be nice to tell the user something's being processed, instead of just making them wait. Like I said, in terms of cgi and running multiple apps, really no one has to worry about preformance, so don't this is just an ideal of warning users.

My two big questions are really if the script waits for the Java program to execute before moving on, and how do I get the file back to the user and then delete it?

Hobbes [Smile]
 
Posted by Bokonon (Member # 480) on :
 
Hobbes, read my edit above.

-Bok
 
Posted by Hobbes (Member # 433) on :
 
OK, so let's say I can handle all the none-fatal errors by putting a "try" "catch (Exception e)" around my whole main code. And it looks like you don't use the "exec ()" code. So does that mean that if I do it your orginal way, and don't worry about Exceptions (and don't mind returning a bad file to the user, I can deal with that part) then I can just assume that it'll wait for the program to finish? And then there's my file questions.

Hobbes [Smile]
 
Posted by Bokonon (Member # 480) on :
 
The exec() would be in your perl, not java. The exec() "executes" the command given to it, normally in the form of a string.

Exec is an asynchronous call, meaning it creates a new process on the system that runs the command, and returns 1 if the program can't be run, and a 0 if the program started up without a fata error. Now if a fata or non-fatal error occurs at some point within the Java code itself, there is no clear way to tell the perl code what happened. The try{} code in Java will let you handle it on the Java side, but that won't help on the handoff.

Your best bet is to see if there is an option that can be given to perl's exec() equivalent that waits for the code to complete. Otherwise, you'd have to think of setting up a little ava server app that would get contacted by the perl script to be told that there is processing to be done, and it would spawn a java thread to process the file/metadata, and then give a return message to the perl script client, saying where the binary data is. That would be pretty complex though.

-Bok
 
Posted by Hobbes (Member # 433) on :
 
OK, I'm catching on. [Smile]

so this:

Have your perl execute: "java MyCode.class <arg1> <arg2> <etc...>"

means a Perl syntax like:

exec ("jave MyCode.class <arg1> <arg2> <so forth and so on>"); ?

I'll look into this.

Hobbes [Smile]

[ July 13, 2004, 06:03 PM: Message edited by: Hobbes ]
 
Posted by Bokonon (Member # 480) on :
 
Right. I actually know only rudimentary perl, so I don't know the exact method of doing the exec()... The exec() is more from my Unix programming days.

I can help you more on the java end.

-Bok
 
Posted by Hobbes (Member # 433) on :
 
I'll be sure to ask then. [Smile]

Fugu? Perl? Help? [Angst]

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
http://www-cgi.cs.cmu.edu/Web/People/rgs/pl-exp-sys.html

http://www.cotse.com/perl/exec.html
 
Posted by Hobbes (Member # 433) on :
 
So system function is the way to go then? It says it waits for copmletion and then continues, that looks good. Thanks. [Smile] I'll be back at some point about the file questions. [Smile]

Hobbes [Smile]
 
Posted by Hobbes (Member # 433) on :
 
All right, well now I'm back to java questions. I'm using Eclipse to write all this code and it has an export function that's supposed to create JARs pretty easily. Well I guess it does, but when I try to run the JAR (simple double click) it just gives an error. So unless someone here really knows what they're doing with Eclipse I guess I need to know how to create a clickable JAR file some other way.

Also, and this is of more immeadite concern, I'm having memory problems. The program is running out of memeory converting a file I really need to get converted, but I know the computer has at least an order of magnitude, and possibly two orders of magnitude more memory than is required. So obviously when I run the program through Eclipse (which doesn't create a JAR, it runs it itself) it's limiting the memory pool. So... yah, help?

Ohh, and if there's some other option in creating an executable other than a .JAR that's fine too.

Hobbes [Smile]
 
Posted by Farmgirl (Member # 5567) on :
 
Hobbes,

Well my Java-junkie co-worker is at lunch right now, but I can tell you he is a moderator, and spends ALL his day, at this site answering Java questions for those learning that particular program. I would suggest you try going over to that forum for help.

Farmgirl
 
Posted by Hobbes (Member # 433) on :
 
Thanks Farmgirl! [Cool]

Hobbes [Smile]
 
Posted by Hobbes (Member # 433) on :
 
Actually, I got it, so no worries on creating a jar. But is ther any way to get the jar to have expanded memory when you double click it?

Hobbes [Smile]
 
Posted by Alcon (Member # 6645) on :
 
Hey Hobbes,
Didn't want to read through the entire thread becuase I've been dubugging kids C++ and html/javascript code all day and am kinda brain dead where code is concerned. But I did want to say: I can feel your pain trying to learn perl as a C/C++ coder. I'm having to do the same thing for the lab I'm working in. And it sucks. Trying to switch from C/C++ pure logic where you have to keep direct control of everything and every little bit of memory to perl where it just does everything for you and you're never quite sure WHATs going on is a real pain. And I officially despise regular expressions.

Just my 2 cents.
 
Posted by Hobbes (Member # 433) on :
 
You made my day. [Big Grin] [Group Hug]

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
http://www.omondo.com/faq/common/index.jsp

http://www.rgagnon.com/javadetails/java-0131.html

You should be able to make it use the arguments by just changing how windows runs the jar file, in the properties, I believe.
 
Posted by Hobbes (Member # 433) on :
 
OK, so I'm trying to create this jar file myself, I've put all my class into one directory, and I'm running the jar command on it. The command I run is this:

...jar cmvf add.txt Converter.jar Converter/*

add.txt contains this line (as a manifest file):
Main-Class: CFileProcessor.class

Converter.jar is the output jar file, and all the files are in Converter (the directory). The command runs, produces the jar file (and the verbose output tells me that all the required class files have been added). I then try to run the .jar file and it says it can not find the main class. Well the class is defaintly there (I've expanded it and checked, I've also tried labeling the path name as being outside and inside the directory Converter and checked spelling). When I expand the jar file the manifest file created does indded list the main class correctly, but that doesn't help the fact that it can't seem to find it. [Dont Know]

Hobbes [Smile]
 
Posted by Farmgirl (Member # 5567) on :
 
Remove the ".class" from the end of the class file, and then hit return (requires a new line)

Farmgirl (writing on behalf of my co-worker who knows this stuff)
 
Posted by Bokonon (Member # 480) on :
 
Yeah, to follow up FG, class files are generally not specified with their extension, while source files are, in Java.

Just a rule of thumb.

-Bok
 
Posted by Hobbes (Member # 433) on :
 
[Big Grin]

[Group Hug]

Thanks FarmWomen and co-worker. *Runs off to check*

[EDIT: and Bok [Smile] ]

Hobbes [Smile]

[ August 05, 2004, 04:09 PM: Message edited by: Hobbes ]
 
Posted by Farmgirl (Member # 5567) on :
 
[Angst] I've become plural now????

FG
 
Posted by Hobbes (Member # 433) on :
 
I have this problem, woman always becomes women when I type. I'm having it looked at. Or maybe it would be easier if you just went ahead and devloped multiple personalities...

By the way, it's still not working but I'm going to keep trying.

Hobbes [Smile]
 
Posted by Farmgirl (Member # 5567) on :
 
You put in the new line under the Main Class line? What error are you getting?

FG
 
Posted by Hobbes (Member # 433) on :
 
Yes I did, and the same error. I'm going to be more specific here.

In the base directory:
Converter (Folder)
Converter.jar (The jar file that's been created, and runs unsiccsefully)
add.txt (the data that's supposed to be added to the manifest file)

In Converter:
*.class (all the required class files, including the one with static void main (...) in it)
Various folders with other required files (my program has a dependency on another jar file called netcdf.jar, I've expanded it and put all the new files in this directory, with all of the class files)
.regconv (a file that my program requires, just some small ASCII data).

The exact line I'm using on Window's cmd:
D:\Hobbes\Java Source\Project 2>C:j2sdk1.4.2\bin\jar cmvf add.txt Converter.jar

This is followed by two possible options that I've tried:
Converter/
Converter/*
(and Converter alone as well)

add.txt has contained (always followed by a new line) the following lines (always it's only one line, but I've tried many options):
Main-Class: Converted/CFileProcessor
Main-Class: Converted\CFileProcessor
Main-Class: CFileProcessor

The error is:
Could not find the main class. Program will exit.

Hobbes [Smile]
 
Posted by Gregg (Member # 6752) on :
 
Alrighty hobbes

If you place class files in folders and JAR those folders into the JAR file, your class file has to specify a package. Here is an example:

code:
package Converter;
public class hello
{
public static void main(String[] args)
{
System.out.println("Hello Hobbes");
}
}

Now, put that file in a folder call Converter and compile it.

Next, create a Manifest file like so:
code:
Main-Class: Converter/hello

And then do the JAR:

code:
C:\>"c:\Program Files\java\jdk1.5.0\bin\jar" -cmvf manifest.txt hello.jar Converter/*.class

HTH

P.S. I work with FarmGirl. [Smile]

Gregg Bolinger
Javaranch Sheriff | Weblog

[ August 05, 2004, 05:57 PM: Message edited by: Gregg ]
 
Posted by kaioshin00 (Member # 3740) on :
 
System.out.println("Java rules!");
 
Posted by Hobbes (Member # 433) on :
 
cout << "Java's lack of low-level control over the computer, and it's run-time compiling make it ideal for it's use as a multi-platform language, but when it comes down to power in a programming language nothing delivers that with felxibility and scalibilty like C++" << endl;

Hobbes [Smile]
 
Posted by Hobbes (Member # 433) on :
 
Big thanks to Gregg, I'll try that as soon as I get into work tomorrow. [Big Grin] [Group Hug]

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
Which is why Microsoft is moving to a very java-similar language, C#.

Plain and simple, if you want to develop high level software quickly, efficiently, and securely (in the general sense, there are always exceptions), you want a language less like C++ and more like Java (or even past Java for many purposes).

[ August 06, 2004, 12:27 AM: Message edited by: fugu13 ]
 
Posted by Hobbes (Member # 433) on :
 
Well I agree in general, but I don't think they have to take that route, through the use of standered libraries (like the STL) C++ can be turned into a high-level language just as easily as Java (in my opinion). I agree that if you're basically after quick programming and don't much care about speed a language like Java or C# will give you a much quicker return on your buck, but I'm of the opinion that taking the time to really develop standered libraries for C++ would allow people to use it as a high level language without giving up the functionality that accompanies a low-level language.

Now if you're after something as high level as say Perl, or PHP then C++ will be too far off the mark, but then again, so will Java.

Speaking of C#, has Microsoft finished writting their .NET platform for anything besides Windows? The last time I looked into this was years ago. [Embarrassed]

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
And unless you're using a JIT compiler (highly unlikely), there's no run time compiling in java . . . It uses java "machine" language bytecode instructions on the java virtual machine, just like you downloaded them off the internet or compiled them five minutes ago, no further compilation involved.
 
Posted by Hobbes (Member # 433) on :
 
You're right, compile is the wrong word, but I just strongly dislike the idea of having to run something on code that's already been compilied. [Dont Know]

Have you heard about the .NET?

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
Sorry Hobbes, but this one's one CS people have been looking at for a long time. Excepting speed, higher level languages have significant advantages over C++. Just the ability to dispense with the bookkeeping is a godsend, not to mention higher level abstractions. Average number of lines in a java project is something like half the lines in a C++ project doing the same thing, and that can be cut in half again or better by a higher level language. LOC improvements like that with better runtime security (from buffer overruns and such), better readability, and higher "paradigmicity" are very hard to argue with except when some overriding concern crops up.

Not only that, with many higher level languages you can write speed sensitive parts in C++ and still have most of the program in python or whatever.

And C# can run on pretty much any platform out there nowadays, even a lot of the winforms stuff. The server side stuff's been pretty much completely ported, in part by MS implementation (Rotor is their FreeBSD/OS X implementation, though its a little behind the times), and in part by open source projects (Mono and dotGNU, mainly the former).
 
Posted by fugu13 (Member # 2859) on :
 
Hobbes, C++ code doesn't run on the metal exactly, either [Razz] . It has to go through the operating system for a lot of things (requesting memory, for instance [Smile] ).
 
Posted by Hobbes (Member # 433) on :
 
quote:
Sorry Hobbes, but this one's one CS people have been looking at for a long time. Excepting speed...
What are you sorry about? I prefer C++ for many reasons, one of which is that my mind works exactly like the way C++ is written (object oriented, but with no abstraction above hiding registry moves and the like). It's exactly as tedious as I like and incredibly powerful, and it is faster if you know what you're doing (which I do like to flatter myself that I do).

And I still think that if some real time and money was invested in good, high-level libraries C++ could really compete on that platform with languages like Java and C#, the reason it isn't competing is because no one wants to put in time and money. Which is acceptable, I wouldn't really want to use those libraries myself, and I wouldn't be surprised in the least if it wasn't really monetarily beneficial, I'm just saying if a company with some money really wanted to they could build C++ to compete on just about any level.

Hobbes [Smile]
 
Posted by Hobbes (Member # 433) on :
 
Fugu, going through the system for commands like file i/o and memory allocation is different then sotring all of it's commands in a byte format that can't directly run on the processor. [Razz] Java does all tha and has to be whatevered at run time.

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
Hobbes, more time has been invested in C++ than any other language, probably, and definitely in the past decade. I do assume you're using the Boost libraries, btw?

Yet even with all the time that's been invested in it, C++ still doesn't have nearly the development efficiency that higher level languages do.

And its not just calling some operating system functions, C++ has a (minimal) runtime environment. It does let the metal handle many of the calls, but its still very much there. Is Java significantly further from the metal? Sure, but C++ isn't right there on the metal.
 
Posted by fugu13 (Member # 2859) on :
 
Actually, given the C++ was MS's big thing for at least a six or seven years but wasnt' able with their billions to mold it into what they needed for many purposes, I'm rather certain you're not quite correct with your assertion.
 
Posted by Hobbes (Member # 433) on :
 
[EDIT: Which assertion?]

I'm agreeing with on that Fugu, and I'm agreeing with you on the fact that turning it into a lnaguage that could high-level functionality is really just my own personal pipe-dream, I'm just saying it could be done. You're right though, I was reaching to far on that one.

Though I disagree that C++ is the most time-invested language, perhaps in the last century, but I'd be willing to bet dollars to donoughts (if I was willing to bet anything, which of course I'm not) that Fortran has a significantly larger amount of time invested in it.

What can I say, C++ will always be my favorite language, it's powerful, and for me it's not cluncky because I don't have to translate my thoughts to program in it, it's one of the reasons I so love programming. English is a language in which I speak like forienger, C++ is my native language of the mind. [Smile]

Hobbes [Smile]

[ August 06, 2004, 01:09 AM: Message edited by: Hobbes ]
 
Posted by fugu13 (Member # 2859) on :
 
Fortran had more time spent programming in it, likely, but development on the language itself not so much as C++, I think.

Lisp is probably a better competitor, at least if you include the entire Lisp family, but possibly even just Common Lisp.
 
Posted by Hobbes (Member # 433) on :
 
I'm giving you the argument, I have no doubt that it's far more effective to program in Java for most companies (or C# or Lisp or some other at least kind of high-level language) especially with rapidly increasing processor speed (and most people using their 1.5GHZ to write letters and play solitare), the effeciency just isn't need like it's used to.

The one thing they did with Fortran was really write the compilies to the edge in efficiency, heck, until around 92 I believe it was, all C and C++ programs were first converted to Fortran and then compiled in Fortran because the compilers created faster code. High-level languages are going to give you a lot mroe devloping time though, since you have to write all those abstraction layers.

I think I'll go back to talking longingly of C++...or perhaps finishing the program I'm currently working on in C++. [Big Grin]

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
Nope [Smile] . C was C, and was compiled directly, first in a compiler written in assembly and then in a compiler written in C. You can read the abbreviated story in Kernighan and Ritchie, the standard book of C.

C++ was originally (when developed by our good friend Stroustrup) converted to C and then compiled (oddly enough, our other good friend SCO owns the rights to the descendants of this original compiler [Smile] ), but quickly became compiled directly.

I'm not sure what you mean about having to write all those abstraction layers . . . higher level languages are higher level because they make it easy to develop abstractions, and they cut down on development time, usually by large factors.

You might be interested in one of the few people out there I think is completely fluent in C++ : http://www.moderncppdesign.com/

Here's a few of his columns on the CUJ website:

[ April 13, 2019, 02:56 PM: Message edited by: Hatrack River ]
 
Posted by Hobbes (Member # 433) on :
 
I have this book with a title something akin to "Efficent C++ programming", and if I ever feel like everything that can be done has been done in terms of writting the most efficent code to do basic, everyday problems, I'll just read a few lines and remind myself that's just plain not true. [Smile]

quote:
I'm not sure what you mean about having to write all those abstraction layers . . . higher level languages are higher level because they make it easy to develop abstractions, and they cut down on development time, usually by large factors.
I mean that a high level language is one in which so much more code has to be written for the language itself, C++ has the abstraction that you don't have to worry about registry values and what not, but you have to deal with memory pretty directly (like arrays of charecters instead of String objects), every layer up you go in the language is a layer more you have to write into it. I was talking about the time making the language itself, not programming in it. [Smile]

Hobbes [Smile]
 
Posted by Hobbes (Member # 433) on :
 
It worked, thanks a lot everyone. [Big Grin]

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
Higher level language development isn't really all that hard, actually. Take a look at all the hobbyist-grown languages around, and you'll see that its pretty easy to develop a new language, particularly (say) a .NET CLR language.

And most of the development you're talking about in C++ is just writing those abstraction layers, anyways, because abstraction layers are what make programming more efficient, plain and simple [Smile] .
 
Posted by Hobbes (Member # 433) on :
 
If I was to explain how to run a .jar file on a Windows machine, and do so with a lot of of memory (like -Xmx512m type of memory) how would I do this? I would like to avoid using cmd if I can, though I wouldn't mind all that much making the user write a little batch file if I give them the skeleton (a one line batch file of course... well I guess it has to be two lines but not the point), but obviously I'd rather not do that. What's this you were talking about with properties for memory?

Hobbes [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
I was misremembering (or can't find what I was thinking of), the command is system wide (which we don't want)

http://forum.java.sun.com/thread.jsp?thread=517241&forum=22&message=2472461

So use that command in a batch file (with the memory expanding arg and the jar name filled in), and put the two in the same folder. Then name the batch file "Double Click to Launch AppName.bat" or something else really obvious.
 
Posted by Hobbes (Member # 433) on :
 
Here's what I wrote:

quote:

How to Run the Converter

The first step in running the file converter is unpacking it. In Linux or Unix you should be able to use the “unzip” command to do this. In Windows, right click on the file (Converter.zip) and then select “Extract All”.

No matter the operating system, you must have Java installed on your computer. You can download Java at Sun’s website. Once you’ve downloaded Java you have all the tools you need to run the file converter.

If you’re on Linux or Unix, then you can run the file converter with one line. Once you’re in the appropriate directory (within the Converter folder) the following line should run the program:

java -Xmx512m -jar Converter.jar

If you’re running Windows it is both easier and much more difficult. Double clicking on the file “Converter.jar” will run the program, but will do so with a very limited amount of memory. The file converter is very memory intensive, so it’s quite likely that it will hang if it runs this way. In the Windows version this program also comes with a MS-DOS batch file named “RunConverter.bat”. Double clicking this will run the program with the appropriate memory, if you installed Java in the default location, and if it’s the same release as was current when the converter was created. Failing that, try to find where your java files are (the normal is in C:\Program Files\Java\j2re1.4.2_04\bin\java, the "j2rel.1.4.2_04" will change when a new release of Java is made). Then open the batch file with a text editor like notepad or WordPad. The file should look like this:

“C:\Program Files\Java\j2re1.4.2_04\bin\java” -Xmx512m -jar Converter.jar

Change it so that it looks like this:

“Your_Java_Folder\bin\java” -Xmx512m -jar Converter.jar

Be sure to include the quotation marks and a new line at the end of the file. Save and exit, and then you should be able to run the file converter simply by double clicking the batch file.

How does that strike you?

Hobbes [Smile]

[ August 06, 2004, 10:54 AM: Message edited by: Hobbes ]
 


Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2