
- Well, enough already these banalities about the wheels, tired! - you say.
And that's not enough!
')
In the modern scientific world and the programming world, wheels only invent
rebel
idiots and students as homework.
Java is such a special language, the developers of which very carefully approached the problem of developing standard libraries. So the wheels here are enough for every taste and color.
Swallow take it - I do not want!
Here is a list of 6 reasons to use existing practices for those who have not yet believed:
1. Its wheel - eight.
The proof is trivial. The more code is written, the more mistakes are made. This means that your wheel code will probably contain errors. On the other hand, a stamped mass-produced wheel (libraries tested repeatedly) contains a minimum of errors.
Take the classical problem of sorting an array. Suppose you want to sort the array Person in non-decreasing name.
Sorting is done by first or last name, depending on the parameter.
class Person {
String name;
String surname;
String getName ( int index) {
return index == 0? name: surname;
}
}
void nativeSort (Person [] persons, final int index) {
Arrays.sort (persons, new Comparator <Person> () {
public int compare (Person o1, Person o2) {
return o1.getName (index) .compareTo (o2.getName (index));
}
});
}
void mySort (Person [] persons, int index) {
for ( int i = 0; i <persons.length - 1; i ++) {
for ( int k = 0; k <persons.length - 1; k ++) {
if (persons [k + 1] .getName (index) .compareTo (persons [k] .getName (index)) <= 0) {
Person buf = persons [k];
persons [k] = persons [k + 1];
persons [k + 1] = buf;
}
}
}
}
At first glance, both solutions are completely correct. One of them uses the library sorting function, and the second implements the sorting algorithm
a bubble. But it turns out that its solution has a serious drawback, which can lead to unpleasant consequences in real code. How? I will not say!
This is a task for independent work :). Answers please write in the comments in white font.
2. Its wheel is rolling more slowly.In the example from the first item, bubble sorting is used. As you know, it is performed in quadratic time. And standard sorting uses
merge sort algorithm with N * log (N) complexity, which works much faster.
3. Your code is more expensive to maintain.The code of their libraries one way or another will have to be maintained. Refactoring, refinement, optimization, debugging with a cup of coffee in three nights will be required.
And the use of ready-made libraries allows you to - just think - to transfer the development of part of the functionality to third-party (often more reliable) developers.
4. Knowledge of standard libraries will help you more easily understand someone else's code. After all, standard libraries are standard and that they are used by different teams.
5. Modules using standard libraries and interfaces are easier to integrate.Module integration involves data exchange. If the data is not standardized, then you will have to write converters.
For example, you want to combine in your project a library for working with http connections
org.apache.commons.httpclient.*
and a library for working with xml
javax.xml.parsers.*
. I guarantee a headache due to the fact that in these
libraries use a different class to describe a URL (
java.net.URL
and
org.apache.commons.httpclient.HttpURL
)
6. Library developers often know better what you need. Does this sound like a conspiracy theory?
- Not at all. Standards in the java world are adopted by a
consortium (en) , which means
The decisions made are suitable for most development teams. And since they suit almost everyone, then surely they will do for you.
Here you can remember about
other (en) technologies that are developed entirely within companies,
what can (but not necessarily) make them not comfortable enough for you.
Full version of the article in the
java blog wizard .