- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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).
Admin
Actually, on Windows 2000 or later with shell command extensions enabled, mkdir creates all necessary directories by default (and silently ignores any options given).
Admin
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>
Admin
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.
Admin
Command Extensions are enabled by default.
If gives an error on your system, then someone's been fidgeting with your machine, and it's not your girlfriend.
Admin
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.
Admin
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.
Admin
Sollution to porting this is very simple, install VMWare... [:D] Or maybe you could try cygwin first... [6]
Admin
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.
Admin
org.apache.commons.io.FileUtils anybody?
Admin
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/mkdir.mspx
Admin
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.
Admin
The big wtf is there is no "bignumberjustincase" variable.
Admin
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.
Admin
The very fist Google result for "java create directory:"
Admin
mkdir is faster because it is written in C.
Admin
No, the copy function in that class copies the contents of the specified source file to the specified destination file. No attributes.
Admin
No fair. I'm the one who starts flame wars. Some of my recent work includes...
Admin
A google search turned up this:
http://dev.eclipse.org/viewcvs/index.cgi/platform-ui-home/permissions-proposal/permissions-proposal.html?rev=1.2
Admin
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.
Admin
And if you bothered to read the Java API, you'd realize what a dork you are
Admin
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...
Admin
The result of that is "Bad command or file name". I am using Windows 98.
Or maybe something else. Caution is good.
Sincerely,
Gene Wirchenko
Admin
Sincerely,
Gene Wirchenko
Admin
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.
Admin
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.
Admin
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.
Admin
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.
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.
Admin
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.
Admin
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.
Admin
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
Admin
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.
Admin
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.
Admin
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
Admin
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?
Admin
To piss Gene off more, a SortedSet with a custom comparator can hold and sort duplicate elements.
Admin
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.
Admin
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.)
Admin
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.
Admin
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.
Admin
What animal have you evolved into when you've got multiple VPN's on each interface, and you're running your own CA?
Admin
Advanced, Basic, Extended, Perl-compatible, or SQL?
Quiz: without testing it, write a regexp to match a string like "()|<>{}%_$^" that works on multiple platforms.
Admin
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).
Admin
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.
Admin
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?
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?
Admin
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)
Admin
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?
Admin
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.
Admin
Nope, it is you who doesn't "get it".
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.
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>
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?
Admin
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.