• Esku (unregistered) in reply to Gene Wirchenko

    Actually, it would. On Windows 2000 or later with shell command extensions enabled, mkdir created all necessary directories by default (and silently ignores any options given).

  • Esku (unregistered) in reply to Gene Wirchenko

    Gene Wirchenko:
    Anonymous:
    Just because Java is extremely portable, doesn't mean the software being developed is going to be used on every platform. Sure, it's a best practice to use more abstract functions, but this WILL work as long as the 'mkdir' command exists. This is a very minor WTF.


    No, it will not.  MS-DOS has mkdir.  It is the same as md.  It does not have the "-p" parm though, so the code will not work.

    Sincerely,

    Gene Wirchenko

    Actually, on Windows 2000 or later with shell command extensions enabled, mkdir creates all necessary directories by default (and silently ignores any options given).

  • (cs) in reply to Xepol
    Xepol:
    BiggBru:

    Wow. The portability of Java, minus the stupidity of the programmer, equals useless code.

    Then again, how can we expect him to know that Windows and Unix require different commands? Honest mistake, right?

    [:P]

    again, who the hell lets these people program? They are scaryier that the original bug originator!! That's it, from now on, there will be tests, licenses, societies, and most important, horse whippings.

    Holy garbled quotes!

    Anyway, is a horse whipping really necessary here? I would prefer a "you're wrong, and here's why..."

    By the way, nobody lets me program yet. I'm still a CS student. So forgive me for not knowing that a DOS command prompt accepts "mkdir" as a valid directory creating command. I would certainly assume that Unix's mkdir would be unique.

    I guess that's what happens when you assume. You make an  <FONT color=#0000ff>ASS </FONT><FONT color=#000000>of </FONT><FONT color=#0000ff>U </FONT><FONT color=#000000>and </FONT><FONT color=#0000ff>ME...</FONT>

  • (cs) in reply to ammoQ
    ammoQ:
    So .net got it perfectly right (IMO) and Java got it horribly wrong (IMO). Funny, since I write Java code much more often than .net code.


    Since file IO is such a basic, crucial thing, it had to be part of the Java API from the very beginning, so it's not very surprising that there were more design flaws than in the later APIs where people were more experienced and naming conventions more established.

    And no suprise at all that .Net, which is basically Microsoft's reaction to Java, improved upon it in some areas.
  • (cs) in reply to brazzy
    No, it will not.  MS-DOS has mkdir.  It is the same as md.  It does not have the "-p" parm though, so the code will not work.

    Sincerely,

    Gene Wirchenko


    Command Extensions are enabled by default.

    If
    mkdir -p
    gives an error on your system, then someone's been fidgeting with your machine, and it's not your girlfriend.
  • (cs) in reply to brazzy
    brazzy:
    ammoQ:
    So .net got it perfectly right (IMO) and Java got it horribly wrong (IMO). Funny, since I write Java code much more often than .net code.


    Since file IO is such a basic, crucial thing, it had to be part of the Java API from the very beginning, so it's not very surprising that there were more design flaws than in the later APIs where people were more experienced and naming conventions more established.


    File IO is a basic, crucial thing, but making directories isn't. E.g. IIRC mkdir() is not part of the C standard library. Some operating systems do not even implement the concept of directories; I expect that in 5-10 years from now, in most operating systems the concept "directories" will only be a compatibility layer for old software, while the actual location of files is managed in a (non-hierachical) database.
  • (cs) in reply to dhromed

    Java does have some strangely named elements - if I wanted to move a file for example, I would look for File.move() or something similar.  However, I've worked in systems before where renaming a file and moving it are the same thing, so the next thing I look for might be File.renameTo().  JavaDoc may not help much, but google does:  http://www.google.co.uk/search?q=java+create+directory  (first match has a nice simple example).  But I'm willing to accept that this may be old code from before Google became mainstream.

    If given the choice, though, I would always hunt and hunt for the Java method for it.  I intensely dislike doing things like this through command line exes.  Error handling is bad, it's more likely to fail at runtime than at design time (such as if they decide to change the mkdir command in a particular OS or if the OS doesn't support all the switches or they're supposed to be in a different order), the calling method is just text which (to me, anyway) doesn't seem as concrete as an actual method call...   I think this is a minor WTF in a way, but it'd still be a WTF in most languages.  The portability of Java only increases this.

    That kind of thing is ok for scripting languages - partly because a lot of them are designed for just stringing together some command line commands anyway, partly because most scripts will be simpler than most compiled programs, and partly because a script is just a text file so you can edit it easier if it goes wrong.

    Lastly, if this goes wrong and causes bugs, yes it's easy to fix (we'll skip the obvious note that it shouldn't have become an issue in the first place) but how many other bits of code like this are in the system?  If the coder used techniques like this on a widespread basis, then that's a big WTF.  And how many people are calling this based on some special quirk of that mkdir implementation that won't work on another OS.  Fixing that one bug might cascade into more bugs.

  • (cs)

    Sollution to porting this is very simple, install VMWare... [:D] Or maybe you could try cygwin first... [6]

  • (cs) in reply to ammoQ
    ammoQ:

    So .net got it perfectly right (IMO) and Java got it horribly wrong (IMO). Funny, since I write Java code much more often than .net code.



    If you were to copy a term paper that you got from a kid who graduated several years earlier, you are likely to fix all the areas the teacher marked in red pen while you are doing it.
  • Stewart (unregistered) in reply to kentcb
    kentcb:
    TankerJoe:
    kentcb:
    TankerJoe:
    kentcb:
    I'm not defending the WTF as there is clearly a valid abstraction around directory creation (be it a very unixy one - mkdirs?). However, Java fails to provide a decent abstraction around file manipulation. You cannot, for example, reliably copy a file. Check it: http://kentb.blogspot.com/2005/06/i-hate-java-part-1.html


    One can, in fact, reliably copy a file in java. From your blog...

    If you take a look at the File [^] API documentation, you'll be disappointed to (still) not find a copy method of any sort. Sure, you can check whether a file exists or whether it's a directory. Heck, you can even rename a file. But you cannot copy a file (because that would be way too useful). A quick google [^] finds other people struggling with the same issue, confirming this fact.

    Maybe it would be simpler if I just showed you how to do it?
        // Copies src file to dst file.
    // If the dst file does not exist, it is created
    void copy(File src, File dst) throws IOException {
    InputStream in = new FileInputStream(src);
    OutputStream out = new FileOutputStream(dst);

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    }
    in.close();
    out.close();
    }

    The funny part is that just because you and supposedly others struggle with this doesn't mean that it is fact.  The solution above came from the 2nd result of your own google search.



    If you actually read my blog entry you'd realise why your code above does not reliably copy a file. It copies the file contents and discards file attributes.

    I have gone back and read the entire blog entry.  My mistake for not doing that from the begining.  Maybe in my defense, its kinda long for "Right-before-I-get-off-of-work" read.  Nevertheless, point taken.  When I read your original post, my impression was that it was a "I-Hate-Java-Too" post that seems so common on this site.  Anyways, point conceded, there is not a way to copy a file, including attributes, in Java.  Apologies.

     



    Apology accepted. It is a long entry and I guess that's kind of the point. It took me a long time just to get files copying properly in a supposedly platform-agnostic environment.

    It's interesting to note that .NET does support file copying in its APIs. For example:

    using System;
    using System.Configuration;
    using System.IO;

    namespace CopyTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                File.Copy(ConfigurationSettings.AppSettings["from"], ConfigurationSettings.AppSettings["to"]);
            }
        }
    }

    If I run this code on Mono (Mandrake) then file attributes are copied along with the file. Therein lies the difference. Of course, all this is a little OT since the OP was trying to create a directory, not copy a file.

    Anyhoo cya,
    Kent

    org.apache.commons.io.FileUtils anybody?

     

     

  • bubba (unregistered)

    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/mkdir.mspx

  • Araqnid (unregistered)

    No-one seems to have mentioned that if Constants.UPLOAD_PATH contains a space (someone later updates it without knowing how it's used), then things will go horribly wrong because the directory expected will not actually be created at all...

    e.g. if Constants.UPLOAD_PATH contains "/tmp/uploads", it's fine, but if someone changes it to "/tmp/uploaded files", then the command will create "/tmp/uploaded" and "files". Oops.

  • cjd (unregistered)

    The big wtf is there is no "bignumberjustincase" variable.

  • (cs) in reply to cjd

    Just had a thought:  ammoq points out that the directory creation stuff is used by creating a file object, which is confusing.  Now, if you were on *nix this would make sense because (IIRC) a directory IS a file.  If the people making Java were *nix-o-philes (Sun, so I'm gonna take a shot that they were), then I can see why they would do it this way.

  • thomas.galvin (unregistered) in reply to ammoQ
    Anyway, I've just checked the docs and IMO it's pretty hard to find the right way, because of its name. (For those who wonder, it's File.mkdirs(). I've looked for something in the line of createDirecory() first. No wonder people are tempted to go the easy WTF way.

    The very fist Google result for "java create directory:"

    // Create a directory; all ancestor directories must exist
    boolean success = (new File(<font color="#0066ff">"directoryName"</font>)).mkdir();
    if (!success) {
    // Directory creation failed
    }

    // Create a directory; all non-existent ancestor directories are
    // automatically created
    success = (new File(<font color="#0066ff">"directoryName"</font>)).mkdirs();
    if (!success) {
    // Directory creation failed
    }
  • Gast (unregistered)

    mkdir is faster because it is written in C.

  • (cs) in reply to Stewart
    Anonymous:

    org.apache.commons.io.FileUtils anybody?

     


    No, the copy function in that class copies the contents of the specified source file to the specified destination file.  No attributes.

  • (cs) in reply to Gast
    Anonymous:
    mkdir is faster because it is written in C.


    No fair.  I'm the one who starts flame wars.  Some of my recent work includes...
    • CS degree is/is not valuable
    • Java performs well/not so well
    • C++ operator overloading is/is not a WTF
  • (cs) in reply to TankerJoe

    A google search turned up this:

    http://dev.eclipse.org/viewcvs/index.cgi/platform-ui-home/permissions-proposal/permissions-proposal.html?rev=1.2

  • (cs) in reply to RevMike
    RevMike:
    trollable:
    Bashing...
    But how many of you know what the difference is between Runtime.getRuntime().exec ("mkdir -p " + Constants.UPLOAD_PATH);
    and
    new File(Constants.UPLOAD_PATH).mkdirs() ?
    Or do you know what is mkdir in the previous statement?

    Are you referring to the new process or the extra object creation?

    No ;)
    I'm refering to the access and creation times, to the given rights, to the fact that mkdir is here an executable and not a shell command, to the environment (that is transmited in 1.5 but not in 1.4), to the asynchronous nature, ... In fact all the things you simply can't do by using the Java API.
  • JOe (unregistered) in reply to DiamondDave

    And if you bothered to read the Java API, you'd realize what a dork you are

  • Mattpalmer1086 (unregistered) in reply to Suck My Lisp
    Suck My Lisp:
    Oh, another problem with SortedSet (and the classes that implement it) is that it might be perfectly OK for his file to have multiple identical lines, which a Set-implementing class would clobber.


    SortedSet?   Shudder.  Sets don't have ordering of elements, by definition.

    I know, I know, it's only an interface.  Still, just goes to show that WTFness is everywhere...


  • (cs) in reply to Suomynona
    Anonymous:
    On my system (WinXP with Command Extensions turned on), a test of "mkdir -p upload" creates BOTH a "-p" folder and an "upload" folder.

    Gene, maybe you don't have command extensions turned on, or you're using a different version. Enter "cmd /?" to see info about it.


    The result of that is "Bad command or file name".  I am using Windows 98.

    So Anonymous, the command as given _may_ work, but if so it will not work as expected. If it works, it will create the desired folder, but will also create an unwanted folder as a side-effect.


    Or maybe something else.  Caution is good.

    Sincerely,

    Gene Wirchenko

  • (cs) in reply to Esku
    Anonymous:
    Gene Wirchenko:
    Anonymous:
    Just because Java is extremely portable, doesn't mean the software being developed is going to be used on every platform. Sure, it's a best practice to use more abstract functions, but this WILL work as long as the 'mkdir' command exists. This is a very minor WTF.


    No, it will not.  MS-DOS has mkdir.  It is the same as md.  It does not have the "-p" parm though, so the code will not work.

    Actually, on Windows 2000 or later with shell command extensions enabled, mkdir creates all necessary directories by default (and silently ignores any options given).

    Who said that was the version of Windows being used?  I use Windows 98 myself.

    Sincerely,

    Gene Wirchenko

  • CoyneT (unregistered) in reply to RevMike

    The command is the same, the syntax is not.  Since the constant undoubtedly contains a Unix path (like "/a/b/c") it won't work in Windows, which expects "\a\b\c".  Result of the former on XP is a syntax error, not a new directory.

  • (cs) in reply to Warp
    Warp:
    Manni:

    I hear that there are talks to standardize the command frequently used in movies known as "PASSWORD OVERRIDE". I use it all the time.



    Frequently? Can you mention more than one movie where you can see that command being written (or shown or whatever)?

    I'm amazed at your ability to invalidate the correctitude of my joke. Did you know that sometimes jokes use exaggerations (also known as "hyperbole") to achieve comedic effect? Just a thought.

    If you want anyone to take you seriously, try not posting useless shit as an anonymous fucktard.

    And before you try to correct me on this post, I'll state up front that I'm aware that "correctitude" is not a word. "hyperbole" is though.

  • Anonymous (unregistered) in reply to Mattpalmer1086

    So, you would rather force people to use an unsorted set even when they want a sorted one, and make them waste time sorting it any time they want to iterate over it in order, just because some ivory tower mathematicians don't like the idea of an automatically sorted set? I hate it when people who've never written a program bigger than "Hello World" in their lives feel they have the right to dictate what should and shouldn't be in a programming language. I'm glad Sun didn't listen to them, otherwise they would have just made another abomination like Haskell.

  • (cs) in reply to johnl
    johnl:
    Just had a thought:  ammoq points out that the directory creation stuff is used by creating a file object, which is confusing.  Now, if you were on *nix this would make sense because (IIRC) a directory IS a file.  If the people making Java were *nix-o-philes (Sun, so I'm gonna take a shot that they were), then I can see why they would do it this way.


    IMO the method make "mkdir" resp. "mkdirs" is more confusing than the fact that it belongs to the File class. I would have expected "createDirectory" or something like that, just like most other method names in the API.

    Anonymous:
    Anyway, I've just checked the docs and IMO it's pretty hard to find the right way, because of its name. (For those who wonder, it's File.mkdirs(). I've looked for something in the line of createDirecory() first. No wonder people are tempted to go the easy WTF way.

    The very fist Google result for "java create directory:"

    // Create a directory; all ancestor directories must exist
    boolean success = (new File(<font color="#0066ff">"directoryName"</font>)).mkdir();
    if (!success) {
    // Directory creation failed
    }

    // Create a directory; all non-existent ancestor directories are
    // automatically created
    success = (new File(<font color="#0066ff">"directoryName"</font>)).mkdirs();
    if (!success) {
    // Directory creation failed
    }


    Fine, but at some sites you don't have access to Google or the websites Google links to. Some companies have very strict firewall rules.

  • thomas.galvin (unregistered) in reply to ammoQ
    ammoQ:
    Fine, but at some sites you don't have access to Google or the websites Google links to. Some companies have very strict firewall rules.


    If a software company is preventing their employees from Googling "java create directory," they are so completely and utterly screwed that I'm having trouble coming up with a suitably humorous description.

    Also, Google Cache takes care of most firewall problems.
  • (cs) in reply to Mattpalmer1086
    Anonymous:
    Suck My Lisp:
    Oh, another problem with SortedSet (and the classes that implement it) is that it might be perfectly OK for his file to have multiple identical lines, which a Set-implementing class would clobber.


    SortedSet?   Shudder.  Sets don't have ordering of elements, by definition.

    I know, I know, it's only an interface.  Still, just goes to show that WTFness is everywhere...


    I suspect that your disgust is entirely due to false assumptions about the functionality of java.util.SortedSet. It does NOT provide a way to insert or query elements at a given "index" within the set; that would indeed be bad. It merely extends the Set interface with functionality that assumes that there exists a total ordering of the elements in the set so that it makes sense to ask for the "first" and "last" element as well as for a subset containing all elements that are bigger than or smaller than a given element, or between two given elmenets. The interface contract also guarantees that the set's iterator will follow the ordering.

    The reason why it exists is pretty much that the Java API contains a Set implementation based on a red-black tree (TreeSet) which can implement such funcationality efficiently, and they wanted people to be able to use that in a clean, polymorphic way through an interface.
  • (cs) in reply to Anonymous
    Anonymous:
    So, you would rather force people to use an unsorted set even when they want a sorted one, and make them waste time sorting it any time they want to iterate over it in order, just because some ivory tower mathematicians don't like the idea of an automatically sorted set? I hate it when people who've never written a program bigger than "Hello World" in their lives feel they have the right to dictate what should and shouldn't be in a programming language. I'm glad Sun didn't listen to them, otherwise they would have just made another abomination like Haskell.


    No, if you want your set sorted, then maybe, you do not want a set at all.  A set, by definition, does not have an order.  A list does have order.  Use a sorted list if you want one, instead of trying to bolt order onto the side of a set.

    Sincerely,

    Gene Wirchenko

  • (cs) in reply to thomas.galvin
    Anonymous:
    ammoQ:
    Fine, but at some sites you don't have access to Google or the websites Google links to. Some companies have very strict firewall rules.


    If a software company is preventing their employees from Googling "java create directory," they are so completely and utterly screwed that I'm having trouble coming up with a suitably humorous description.

    Also, Google Cache takes care of most firewall problems.


    If a company gives you access to Google, it can quite as well give you access to the whole net. Fortunately, most software companies do that, otherwise this forum would be a lonely place.
    But I have a friend who works as a in-house-programmer for a para-govermental agency which has a strict internet policy, there are only a few selected websites (like oracle.com, since they are oracle shop) available and Google is not.
  • Suomynona (unregistered) in reply to Esku
    ammoq:

    This is not an unwanted side effect, but the wanted effect of -p also on Unix.
    														</div></BLOCKQUOTE><br><br><BLOCKQUOTE class="Quote"><div><i class="icon-quote"></i> <strong>Esku:</strong></div><div><br>Actually, it would. On Windows 2000 or later with
    

    shell command extensions enabled, mkdir created all necessary directories by default (and silently ignores any options given).



    On a WinNT type OS, the "-p" isn't a valid option for the MKDIR command and is not what causes a chain of folders to be created. And neither is it silently "ignored", it is silently acted on.  It causes a folder called "-p" to be created. I would call that an unwanted and unexpected side effect.

    Gene, most folks who showed an example of the command said what version of Windows they were using, except you. Of course it doesn't work on Win98.

  • (cs) in reply to Suomynona
    Anonymous:
    Gene, most folks who showed an example of the command said what version of Windows they were using, except you. Of course it doesn't work on Win98.


    True, strictly speaking; HOWEVER, it was not stated at the outset.  Given just "Windows", it will not necessarily work.  I (and others) later started specifying what versions we are using.

    Sincerely,

    Gene Wirchenko

  • Anonymous Coward (unregistered) in reply to Gene Wirchenko
    Gene Wirchenko:
    Anonymous:
    So, you would rather force people to use an unsorted set even when they want a sorted one, and make them waste time sorting it any time they want to iterate over it in order, just because some ivory tower mathematicians don't like the idea of an automatically sorted set? I hate it when people who've never written a program bigger than "Hello World" in their lives feel they have the right to dictate what should and shouldn't be in a programming language. I'm glad Sun didn't listen to them, otherwise they would have just made another abomination like Haskell.


    No, if you want your set sorted, then maybe, you do not want a set at all.  A set, by definition, does not have an order.  A list does have order.  Use a sorted list if you want one, instead of trying to bolt order onto the side of a set.

    Sincerely,

    Gene Wirchenko



    Maybe I do not want a set?  Well, maybe I do.  What do you suggest to use for a data structure which should not contain duplicates but should be accessed in a particular order?

    FYI, Java has a Set interface as well, if you require a set without the overhead of sorting.  What's the objection to taking something and adding extra functionality to it?  Or should everybody who wants to access a Set of Strings in alphabetic order convert the Set into a List or array so it can be sorted?

  • (cs) in reply to Anonymous Coward
    Anonymous:
    Gene Wirchenko:
    Anonymous:
    So, you would rather force people to use an unsorted set even when they want a sorted one, and make them waste time sorting it any time they want to iterate over it in order, just because some ivory tower mathematicians don't like the idea of an automatically sorted set? I hate it when people who've never written a program bigger than "Hello World" in their lives feel they have the right to dictate what should and shouldn't be in a programming language. I'm glad Sun didn't listen to them, otherwise they would have just made another abomination like Haskell.


    No, if you want your set sorted, then maybe, you do not want a set at all.  A set, by definition, does not have an order.  A list does have order.  Use a sorted list if you want one, instead of trying to bolt order onto the side of a set.

    Sincerely,

    Gene Wirchenko



    Maybe I do not want a set?  Well, maybe I do.  What do you suggest to use for a data structure which should not contain duplicates but should be accessed in a particular order?

    FYI, Java has a Set interface as well, if you require a set without the overhead of sorting.  What's the objection to taking something and adding extra functionality to it?  Or should everybody who wants to access a Set of Strings in alphabetic order convert the Set into a List or array so it can be sorted?



    To piss Gene off more, a SortedSet with a custom comparator can hold and sort duplicate elements.
  • (cs) in reply to Anonymous Coward
    Anonymous:
    Gene Wirchenko:

    No, if you want your set sorted, then maybe, you do not want a set at all.  A set, by definition, does not have an order.  A list does have order.  Use a sorted list if you want one, instead of trying to bolt order onto the side of a set.


    Maybe I do not want a set?  Well, maybe I do.  What do you suggest to use for a data structure which should not contain duplicates but should be accessed in a particular order?

    FYI, Java has a Set interface as well, if you require a set without the overhead of sorting.  What's the objection to taking something and adding extra functionality to it?


    What the heck are you two  talking about? The "sorted" functionality incurs NO overhead and is NOT "added" or "bolted on". It's a BYPRODUCT of the tree-based implementation of the Set functionality.

  • Anonymous Coward (unregistered) in reply to brazzy
    brazzy:
    Anonymous:
    Gene Wirchenko:

    No, if you want your set sorted, then maybe, you do not want a set at all.  A set, by definition, does not have an order.  A list does have order.  Use a sorted list if you want one, instead of trying to bolt order onto the side of a set.


    Maybe I do not want a set?  Well, maybe I do.  What do you suggest to use for a data structure which should not contain duplicates but should be accessed in a particular order?

    FYI, Java has a Set interface as well, if you require a set without the overhead of sorting.  What's the objection to taking something and adding extra functionality to it?


    What the heck are you two  talking about? The "sorted" functionality incurs NO overhead and is NOT "added" or "bolted on". It's a BYPRODUCT of the tree-based implementation of the Set functionality.



    Bzzzt.  Wrong.  We are talking about SortedSet, an interface; there is no implementation for anything to be a byproduct of.  You are (presumably) talking about TreeSet, a specific implementation of a SortedSet.  You probably think all Maps are HashMaps  and all Lists are ArrayLists too, don't you?

    And WTF is wrong with you computer scientists anyway?  Don't you know what "sort" actually means?  (I'll give you a hint: it means "to categorize" not "to order".  You sort laundry not integers.)


  • Zorro (unregistered) in reply to kentcb
    kentcb:
    You cannot, for example, reliably copy a file. Check it: http://kentb.blogspot.com/2005/06/i-hate-java-part-1.html

    Couple of things crossed my mind while reading your blog:

    It seems you're confusing Java the language and the Java libraries. If you don't like Sun libraries, take a look at Apache commons IO. The language have really little to do with the fact that the exact method you would like to use is not in the Sun's libraries.

    Also, yes, unix's cp seems to be copying a file along with the permissions; but the date, owner, group are changed depending on who's running cp and who's the owner of the src file. So basically it seems to me the only additional thing carried with a cp are permissions.
    Now I'm not sure all systems have permissions attached to a file, and if Java should worry about this since it's supposed to be cross platform.


  • Zygo Blaxell (unregistered) in reply to TankerJoe

    Perl:  mkdir($mode, $filename), open or sysopen.
    For "mkdir -p" equivalence, use File::Path::mkpath (had to look up the last of those...I remember "File::Path::mk..." but it wants an unusual order of arguments, has a boolean flag, and takes a reference to a list of directories instead of sane arguments...actually I usually code this myself since it's easier to remember split and a for loop than to use that monster mkpath function, unless the program has to be portable to an OS that can't use forward slash as a directory separator).

    Tcl:  "file mkdir", "open", "exec".  "file mkdir" is always like "mkdir -p".  "open" can execute commands, "exec" can create files.

    C:  mkdir(), open(), fopen().  "mkdir -p" requires a loop and string parsing.

  • Zygo Blaxell (unregistered) in reply to RevMike

    What animal have you evolved into when you've got multiple VPN's on each interface, and you're running your own CA?

  • Zygo Blaxell (unregistered) in reply to csrster
    Anonymous:
    Anonymous:

    Inability to write portable code seems quite common among unixoids. Typical WTFs include:

     

    • Using shell commands for everything, including operations that are provided by the language (e.g., mkdir).
    • Using regular expressions for all string comparisons, even trivial stuff like "is the first character in the string a Q".


    What's non-portable about regular expressions?


    Advanced, Basic, Extended, Perl-compatible, or SQL?

    Quiz:  without testing it, write a regexp to match a string like "()|<>{}%_$^" that works on multiple platforms.
  • Zygo Blaxell (unregistered) in reply to Zorro
    Anonymous:
    kentcb:
    You cannot, for example, reliably copy a file. Check it: http://kentb.blogspot.com/2005/06/i-hate-java-part-1.html


    Now I'm not sure all systems have permissions attached to a file, and if Java should worry about this since it's supposed to be cross platform.




    More to the point, in many (most?) non-trivial attribute systems, you can't necessarily copy all of the attributes because you might not have the privileges to recreate them (e.g. the immutable attribute, a group that you're not a member of, compartment ID's etc).
  • Zygo Blaxell (unregistered) in reply to Pedant
    Anonymous:
    I've done something like this before.....

    I needed to do a sort unique on a hundred odd meg file.


    Linux sort (which is really GNU sort) does much better than in-core tree-based or quicksort-based algorithms for huge data sets (i.e. take the amount of RAM you have and multiply by 100).   It uses algorithms that were popular when the biggest chunk of available high-speed storage you had access to was a tape drive.  On modern systems it doesn't just run, it flies.

    The sort program does a quick sort of chunks of the input that are sized to fit nicely in RAM, then does a merge sort over the results.  The overall performance is usually proportional to your disk I/O speed unless you have very fast disks or very slow CPU or very complex ordering functions. 

    RDBMS systems use a similar algorithm if there's no index on the sorting columns and you're doing a query on a huge data set with no hope of benefits from caching.  These systems can be faster than the Unix "sort" command if the data set is physically smaller in the on-disk RDBMS implementation, or if the ordering function is complex--in Unix, you usually represent floating-point numbers as ASCII strings, which can be almost twice the size on disk and more than twice as slow to process as native 64-bit doubles that an RDBMS can use.

    Either an RDBMS or Unix (merge) sort is going to blow away an implementation using a tree-based set algorithm regardless of language if the data set is large enough.

    A Perl hash or Java set implementation will be swapping (definitely not the fast I/O path in most operating systems) and will require O(N * log(n)) disk seeks per page of text sorted, and usually more auxiliary storage.  All that will be very, very slow.
  • (cs) in reply to Anonymous Coward
    Anonymous:

    Bzzzt.  Wrong.  We are talking about SortedSet, an interface; there is no implementation for anything to be a byproduct of.  You are (presumably) talking about TreeSet, a specific implementation of a SortedSet.  You probably think all Maps are HashMaps  and all Lists are ArrayLists too, don't you?


    Bzzt. Wrong. Unlike Map and List, SortedSet actually has only a single implementation in the standard API, namely TreeSet. And I would be willing to bet that the only reason it exists was that the API designers realized that TreeSet had this functionality and wanted to offer a "clean" way of using it.

    BTW, can you suggest an implementation of the interface that is NOT based on a tree structure?

    Anonymous:
    And WTF is wrong with you computer scientists anyway?  Don't you know what "sort" actually means?  (I'll give you a hint: it means "to categorize" not "to order".  You sort laundry not integers.)


    So what's wrong with you mathematicians anyway? Do you know what "set" actually means? I'll give you a hint: it means "a group of things of the same kind that belong together and are so used". It certainly doesn't require distinctness - a chess set, e.g. has a total of 8 white pawns. And what's that lunacy about "ring" and "field" having something to do with sets and operations on their elements?

  • (cs) in reply to Anonymous Coward
    Anonymous:

    Inability to write portable code seems quite common among unixoids. Typical WTFs include:

     

    • Using shell commands for everything, including operations that are provided by the language (e.g., mkdir).
    • Using regular expressions for all string comparisons, even trivial stuff like "is the first character in the string a Q".

    well the number of times i've seen hard coded "file://c:\..." in code is just too many to count. windows knobends always assume their users are on windows.

    (oh and any clue how to get these posts to be formatted properly - whenever i reply to a post it comes out as raw html)

  • Anonymous Coward (unregistered) in reply to brazzy
    brazzy:
    Anonymous:

    Bzzzt.  Wrong.  We are talking about SortedSet, an interface; there is no implementation for anything to be a byproduct of.  You are (presumably) talking about TreeSet, a specific implementation of a SortedSet.  You probably think all Maps are HashMaps  and all Lists are ArrayLists too, don't you?


    Bzzt. Wrong. Unlike Map and List, SortedSet actually has only a single implementation in the standard API, namely TreeSet. And I would be willing to bet that the only reason it exists was that the API designers realized that TreeSet had this functionality and wanted to offer a "clean" way of using it.

    BTW, can you suggest an implementation of the interface that is NOT based on a tree structure?

    Anonymous:
    And WTF is wrong with you computer scientists anyway?  Don't you know what "sort" actually means?  (I'll give you a hint: it means "to categorize" not "to order".  You sort laundry not integers.)


    So what's wrong with you mathematicians anyway? Do you know what "set" actually means? I'll give you a hint: it means "a group of things of the same kind that belong together and are so used". It certainly doesn't require distinctness - a chess set, e.g. has a total of 8 white pawns. And what's that lunacy about "ring" and "field" having something to do with sets and operations on their elements?



    You just don't get it, do you?

    The argument is about the existence of SortedSet.  It's implementations have nothing to do with it.  The fact that the best way to implement the functionality promised by a SortedSet is to use a tree structure has nothing to do with it.

    If there were no SortedSet interface, would that change the functionality of TreeSet in any way?  No.  TreeSet would simply be an implementation of Set with the additional property that the elements are accessed in order, you can get slices, etc.  Much like the way LinkedList provides additional capabilities over List (addFirst, addLast, etc.).  Instead, the designers of the standard API felt that a SortedSet was a useful enough concept to have a separate interface.  There is nothing "clean" about offering an interface that you expect only implementation of.  (BTW, TreeSet is not the only class provided by the JDK that implements SortedSet.  I'll leave it as an exercise for the reader to determine the other(s).  You might want to start by reading the TreeSet javadoc.)

    Finally, WTF do mathematicians have to do with it?  Mathmetical names like set, ring, field, group, etc. denote concepts that did not already exist.  Do you really think that re-using a common word to describe something that doesn't exist is as big a WTF as using a common word (sort) to describe a concept that already exists and for which there is a word for (order) when the original word (sort) also has a meaning (categorize) that is also a transformation one performs on a bunch of objects?


  • (cs) in reply to ammoQ

    If a company gives you access to Google, it can quite as well give you access to the whole net. Fortunately, most software companies do that, otherwise this forum would be a lonely place.
    But I have a friend who works as a in-house-programmer for a para-govermental agency which has a strict internet policy, there are only a few selected websites (like oracle.com, since they are oracle shop) available and Google is not.

    And this is why they fail.  This is a demonstration of deep stupidity on behalf of the management, and I can't understand wanting to work in an environment like that.  I also have a friend in government work, and the stories she tells me make me wonder why the state hasn't collapsed yet.

    Anyway, the majority of programmers will have access to Google.  If they don't, their management wants them to fail, and you will see things like the above WTF.

  • (cs) in reply to Anonymous Coward
    Anonymous:

    You just don't get it, do you?


    Nope, it is you who doesn't "get it".

    Anonymous:
    The argument is about the existence of SortedSet.  It's implementations have nothing to do with it.  The fact that the best way to implement the functionality promised by a SortedSet is to use a tree structure has nothing to do with it.

    If there were no SortedSet interface, would that change the functionality of TreeSet in any way?  No.  TreeSet would simply be an implementation of Set with the additional property that the elements are accessed in order, you can get slices, etc.  Much like the way LinkedList provides additional capabilities over List (addFirst, addLast, etc.).  Instead, the designers of the standard API felt that a SortedSet was a useful enough concept to have a separate interface.  There is nothing "clean" about offering an interface that you expect only implementation of.


    Not really, but when you're promoting a "collections framework" and want people to use interface types wherever possible, having functionality that is only accessible through a concrete implementation class sort of stands out, so you do interfaces everywhere, even when they're not useful.

    How do you determine that something is "a useful enough concept to have a separate interface"? Either because you want it to represent a common behaviour between different concrete classes, or because can do something useful with only that behaviour and write methods that take the interface type as parameter. Neither is the case with SortedSet (nor with SortedMap). There is only one implementation, and all uses (see http://java.sun.com/j2se/1.5.0/docs/api/java/util/class-use/SortedSet.html) are either part of itself, the implementation class or utility methods that create wrappers - with one exception: a constructor of PriorityQueue, a class introduced in 1.5. So it took 6 years and 3 major versions of the Java API until the first first use of SortedSet that doesn't exist for its own sake. And all it actually does is to get the SortedSet's comparator and leave out an intialization step because of the ordering contract. It does not use the actual functionality of the interface. There is no such semi-useful application of SortedMap at all.


    Anonymous:

    (BTW, TreeSet is not the only class provided by the JDK that implements SortedSet.  I'll leave it as an exercise for the reader to determine the other(s).  You might want to start by reading the TreeSet javadoc.)


    Bzzt. Wrong. from http://java.sun.com/j2se/1.5.0/docs/api/java/util/SortedSet.html:

    <font size="-1"> java.util</font>
    Interface SortedSet<e></e>

    All Superinterfaces:
    Collection<e>, Iterable<e>, Set<e> </e></e></e>
    All Known Implementing Classes:
    TreeSet

    In case you were talking about the subsets returned by tailSet() , etc.: take a look at the sourcecode. Those are TreeSets too. Then there are a couple of wrappers in java.util.Collections - which only exists to offer subtype-specific versions of the general Set wrappers.

    Anonymous:
    Finally, WTF do mathematicians have to do with it?  Mathmetical names like set, ring, field, group, etc. denote concepts that did not already exist.  Do you really think that re-using a common word to describe something that doesn't exist is as big a WTF as using a common word (sort) to describe a concept that already exists and for which there is a word for (order) when the original word (sort) also has a meaning (categorize) that is also a transformation one performs on a bunch of objects?


    This isn't even hairsplitting, it's no argument at all, which you admit yourself with the word "also". "to sort" is, and always was, a perfectly correct word to describe ordering something by size. Quoting http://www.m-w.com/dictionary/sort:

    Main Entry: 2sort

    Function: verb

    transitive senses
    1 a : to put in a certain place or rank according to kind, class, or nature <sort apples> <sort mail> b : to arrange according to characteristics : <font size="-1">CLASSIFY</font> <sort out colors>

    Compare that to http://www.m-w.com/dictionary/order:

    Main Entry: 1or·der [image]

    Pronunciation: 'or-d&r

    Function: verb

    Inflected Form(s): or·dered; or·der·ing [image] /'or-d(&-)ri[ng]/

    Etymology: Middle English, from ordre, n.

    transitive senses
    1 : to put in order : <font size="-1">ARRANGE</font>

    So it's not even more precise. What exactly were you complaining about again?

  • (cs) in reply to davesag
    davesag:
    well the number of times i've seen hard coded "file://c:\\..." in code is just too many to count. windows knobends always assume their users are on windows.


    There's a particular cute error this can cause in Java: If there ever is a hardcoded path with backslash as separator and a file or directory name beginning with U, it will either (most likely) not compile, or end up wrong, because \U (upper or lower case) starts a Unicode escape sequence.

Leave a comment on “Porting Java”

Log In or post as a guest

Replying to comment #:

« Return to Article