• (nodebb)

    fristly prepared

  • Quite (unregistered)

    Reading that line:

    "Now, this is a wrapper around a PreparedStatement, so guess how most of the methods work…"

    had that awful inevitability of what is about to happen when somebody is sitting next to you (or worse, opposite you) says, "I'm going to throw up," without actually making a move to do anything about it.

  • ray10k (unregistered)

    Ignoring how most of this class is just a thin wrapper that still breaks any advantage of using a wrapper in the first place, exactly 0 lines of this class are even needed. Java has auto-closing resources since 7, meaning that you just need to name the resource in the try statement. And since most (if not all) of the functions can throw exceptions anyway, there's got to be a try statement somewhere anyway.

    All in all, this is just a show of ignorance of the language's features. On top of being bad code.

  • (nodebb)

    In addition to the rest of the WTFs, what is this static variable for?

  • ForestPhoenix (unregistered) in reply to Medinoc

    It is public, so calling code could check if anything was finalized... because... um.

  • Thomas (unregistered)

    Well, if computer science professors knew anything about writing robust code for the real-word, we'd know by know...

  • Alexander (unregistered)

    somethingFinalized is nowhere read in the code. Based on its name, the static modifier, and its public access I'd guess it is used by some external code to check whether any of the classes instances was ever finalised.

    Still, that wrapper makes for an interesting piece of code, especially in light of try-with-resources (as ray10k mentioned earlier).

  • Grumpy Oldfart (unregistered)

    Professor was paid per line of code.

  • akozakie (unregistered) in reply to ForestPhoenix

    Looks didactic. Student's code can check whether the trick ever worked using this. Why? Why not. Not a bad idea as such if the code is only for use in classes. Doesn't make the code any less of a WTF though.

  • my name (unregistered) in reply to ray10k

    you have to be careful, though, AutoCloseable does not do a rollback which usually resides in the catch clause

  • About to receive hate (unregistered)

    TRWTF is that he can't spell "finalise".

  • Geek (unregistered)

    I'm disturbed that the variable is static, but the student might be using multiple instances - so all of the instances share the one copy.

    Surely this lump of rubbish should extend the thing it's supposed to wrap, and provide some kind of "execute-then-close" method which did, well, execute and then close.

    Then again, maybe this was a massive test of the students - if you didn't question the code, he failed you?

  • I dunno LOL ¯\(°_o)/¯ (unregistered) in reply to About to receive hate

    No, TRRWTF is that we spell "doesn't" with an "s".

    dozen

    doesn't

  • bvs23bkv33 (unregistered)

    EXEC SQL PREPARE sql_stmt FROM :my_stmt;

  • TheCPUWizard (unregistered)

    I am a big supporter of anonymity....but this professor and school should be publically named.

  • Kashim (unregistered)

    TRWTF is that there is a capstone course that requires Java.

    If the professor for my capstone course had given me this code, I would have asked him to his face why he bothered to write 1300 lines of absolute nothing instead of just extending the original class and providing a new function. Then again, I got into arguments like this with my professors all the time when they did totally retarded things because they'd clearly never been outside of academia. Best response I ever got:

    "It is not the student's role to question the professor or argue about methodology."

    I reported him to his department head. The student's ONLY role is to question the professor.

  • Alistair (unregistered) in reply to Kashim

    He could have autogenerated the code from the PreparedStatement source or documentation.

  • n (unregistered)

    Unfortunately, many professors prove the adage - "Those who can't, teach". There are some good ones out there, I've encountered exactly one. But, most are like this or worse.

  • Kashim (unregistered) in reply to Alistair

    And autogenerating 1300 lines of useless code is somehow better? I'm pretty sure that the amount of effort he did or did not put in doesn't excuse the awfulness of what he produced.

  • Necropaw (unregistered)

    Love the docuementation to the method "unwrap": * @param arg0 delegate's parameter * @param <T> delegate's parameter public <T> T unwrap(Class<T> arg0) throws SQLException

    Yep , <T> is a parameter ... not!

  • Alexander (unregistered) in reply to Geek

    As I mentioned earlier, I presume the purpose of the variable is not to be instance-specific, but to flag whether any instance was finalised at all (something).

  • Bill (unregistered)

    I don't know when the professor's code originates from, but as of Java 7, the language has built in facilities to automatically close resource handles when you're done with them. It's called try-with-resources: https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

    Anything that implements AutoClosable can be used in a try-with-resources block, and it's easy to extend, so you can easily add it to your own objects that have resource handles.

    So your code would merely be:

    try(PreparedStatement ps = con.prepareStatement(query)){ ... } catch (SQLException e) { ... }

    You can place multiple resources in the same block if desired, so you could immediately get your ResultSet right after the PreparedStatement in that same try() block. You probably wouldn't, since I would presume that you would need to bind variables, but there are situations where chaining them helps.

    Anyway, exception or not, your PreparedStatement will close.

  • Muad'DI (unregistered)

    I see strength in you, like the strength of the base class from which all classes are derived from. You shall be called Object, the base of the system.

  • Russell Judge (google)

    Brings back memories of my 370 Assembler class back in 1990, where we wrote Assembler code to run in an interpreter the professor wrote in GW-BASIC, and I broke by just doing a little code that went just beyond what his stupid interpreter could handle.

  • Alistair (unregistered) in reply to Bill

    A programmer who uses try-with-resource would probably close the statement anyway. The professor's class is idiot-proof.

  • Herby (unregistered)

    Sounds like this is a convenient way of shaming said "professor". I'm sure that one of his students will discuss with their classmates this exact post, and then the class will laugh behind his back.

    So, TDWTF has done its job!

  • Really? (unregistered)

    TRWTF is posting a 1,300 line class as a part of the article when the article has already described well that the class is mostly one-line delegation to the wrapped class.

    The 2nd WTF is a 1,300 line class in the first place, whether it's the class being wrapped or the wrapper itself.

  • Daniil S (google)

    Oh please.... I've inherited the system full of those WTFs. The professor is prepping them for real world. The real world where this kind of shit is not only allowed but probably even celebrated because in the end - if it works, its perfect. Just one of the projects can produce years of WTF supply for this site. The fun part, the guy responsible now works at one of the biggest banks who were part of fed reserve managing, as he so proudly put it, "team of indians". So yeah, all that shit is perfectly normal.

  • James B (unregistered)

    If professor could write production quality code, they probably wouldn't be professors. Those who can do and those who can't teach.

  • PHP Advocate (unregistered)

    PHP does get a fair amount of deserved hate here, but let me briefly lay out how this same this might be done there.

    class Delegator { public function __construct($obj) { $this->_obj = $obj; } public function __call($functionName, $args) { return $this->_obj->$functionName(...$args); } public function __destruct( ) { $this->_obj->cleanUp( ); /* or whatever */ } }

    Done!

  • Ron Fox (google)

    TRWTF is that I seem to find myself only reading Remy's submissions for the HTML comments.

  • Tim! (unregistered) in reply to About to receive hate

    Oxford: "in British English, all of the following spellings are acceptable: finalize/finalise; organize/organise; realize/realise. In American English, the only correct spellings are finalize, organize, and realize."

    Considered globally, -ize is never incorrect and -ise is sometimes incorrect, therefore -ize is better.

  • motzus (unregistered)

    Not defending the code as it is pretty moronic. As someone who's wife taught computer science while getting her PHD and someone who works at a national research laboratory I can give some insight into the situation.

    For one the actual professor for the course probably did not write that code. They probably had one of their teaching fellow, teaching assistant or unpaid intern write it for them. The teaching fellow, teaching assistant or unpaid intern probably took an introduction to Java class and that is the extent of their experience with the language. The professor probably never bothered to look at the code the teaching fellow / teaching assistant / unpaid intern wrote for them and just asked if it worked. You might say the professor is pretty uninterested in how the code works and by extension the education of their students. You would be right. That is because if the professor is at a research university he / she primary job is to get research grants and conduct research which is very profitable to the university and themselves. If the professor ever wants to get tenure they better be getting grants and lots of them. Teaching classes and dealing with students is a gigantic waste of time for them so therefore they spend the least amount of time / energy possible on it.

    Think about that the next time you blow $400K on your kids education at a fancy university.

  • Simon (unregistered) in reply to Kashim

    If the professor for my capstone course had given me this code, I would have asked him to his face why he bothered to write 1300 lines of absolute nothing instead of just extending the original class and providing a new function

    Oh, that part's easy. PreparedStatement is only an interface - the implementation is provided by whatever actual database driver you're dealing with - so extending the class and adding new methods won't achieve anything.

    That said, the "correct" way to implement this WTF would be to use a reflective proxy to do method pass-throughs instead of manually implementing every method in the class. It would still be a stupid idea, but it'd be about a dozen lines instead of 1300, and wouldn't need updating whenever new methods are added to the interface.

    (I know this from experience having encountered code very similar to this before, and having successfully used such proxies at a first step to cleaning up the mess)

  • Zenith (unregistered)

    I once worked for a state agency where the Indian lead did this except with every .NET framework that he could get his filthy mitts on. He stored "his" framework in a locked repository and frequently checked in non-compiling code before taking a 4-day weekend. Daily pulls were mandated so 3-4 days every other week were wasted. Of course, the project being years behind was the fault of a revolving door of new hires/fires who just didn't understand how busy he was needfully reverting about 10 whole e-mails per week.

    At least the professor has the disposed resource excuse.

  • Daniel Bos (google)

    Not to mention that finalize has now been deprecated, as it has been an abomination since Java 1.0

    Not only are you not sure if and when it will be called, since all finalize methods are called sequentially, one could e.g. infinite-loop and block finalization for all the rest.

  • Me (unregistered) in reply to I dunno LOL ¯\(°_o)/¯

    You are both right. TRWTF is english.

  • John S (unregistered) in reply to ray10k

    " Java has auto-closing resources since 7"

    What if, ummm, I dunno, what if it was written pre-7?

    The real WTF is that it took them until version 7 to add this. People go on and on about how much work garbage collectors save you, totally ignoring all the extra work they create when dealing with anything that isn't RAM.

    Stack unwinding FTW!

  • doubting_poster (unregistered) in reply to n

    That adage applies to veterans of a trade no longer being able to perform it, so they retire to teach the next generation. It has nothing to do with inept people teaching. A better way to frame the adage is "Those who are no longer able, teach".

  • (nodebb) in reply to Russell Judge

    Hmm. When I did 370 Assembler (in 1985), I at least got to run it on a real 370. (3081D, dual processor machine, nicknamed Sybil - so sort of not a 370, but compatible)

  • The original (and the best) (unregistered) in reply to Me

    No, TRWTF is the US thinking they own the world and can change all the agreed-upon conventions. "Let's change all the spellings that everyone else uses!" "Let's use outdated units of measurements that no one else uses!" "Let's use a nonsensical date format that no one else uses!" etc. etc.

    Plus... "Let's name ourselves the same as an entire pair of continents!"

  • (nodebb) in reply to doubting_poster

    "Those who are no longer able, teach" I like it! Only ever heard the expression used the other way, but this is a much more positive interpretation.

    Addendum 2017-03-30 09:06: "Those who are no longer able, teach"

    I like it! Only ever heard the expression used the other way, but this is a much more positive interpretation.

  • (nodebb) in reply to The original (and the best)

    Plus... "Let's name ourselves the same as an entire pair of continents! pubic wigs!"

    FTFY

  • yep (unregistered)

    It seems like a common problem, people who have never worked in the real world teaching students rubbish :(

  • Me (unregistered) in reply to The original (and the best)

    A. Webster was RIGHT when he took all those silent 'u's out because words should be spelled like they sound! I wish he'd won with "soop" too.

    B. The units weren't outdated when we adopted them, and they still work just fine. I believe the expression is "if it ain't broke, don't fix it".
    It really isn't our fault you got shanghaied by the french into changing all your numbers, so just let go of your globalization worries, head down to the pub, and down a pint... I mean a 0.57 liter.

  • Not you (unregistered) in reply to Me

    Yes, and you'll note that the spelling isn't broken, so why bother fixing that? There are plenty of words that the US hasn't "fixed"... if you're going to try to "fix" the spellings, then go all the way rather than stopping after four rules.

    Fun fact: approximately 4% of people live in the US. That is nowhere near enough reason to insist on changing things (for the worse)

    And it's spelt "litre", FYI... it amuses me how Americans can't even spell metric units, let alone use them.

  • Herr Otto Flick (unregistered) in reply to Tim!
    Oxford: "in British English, all of the following spellings are acceptable: finalize/finalise; organize/organise; realize/realise. In American English, the only correct spellings are finalize, organize, and realize."

    Considered globally, -ize is never incorrect and -ise is sometimes incorrect, therefore -ize is better.

    You are incorrect. "Acceptable" is not the same as "correct". "-ize" is incorrect but acceptable in English English, but "-ise" is unacceptable to the rigid American English speaker.

  • rdwells (unregistered)

    As one who recently made a late-life career change from software development to teaching, I live in constant fear that these's some complete misconception I've had for 30 years that I'll now be passing down to my students, and which I'll someday find on this site. Luckily, some of my students are insanely bright HS kids who love correcting every mistake I make on the board, so maybe they'll help prevent that from happening. (BTW, that last statement was not sarcastic; I'd rather have my mistakes corrected than live forever in my students' notes.)

  • Not you (unregistered) in reply to Herr Otto Flick

    Can't argue with that. Americans are so insistent on their own rules and conventions that everyone else is forced to deal with it.

  • Me (unregistered) in reply to Not you

    The spelling IS broken, and I wish Webster had finished the job. And we went to the moon on miles, pounds, and gallons. Where have your oh-so-superior french numbers gotten you?

Leave a comment on “Prepared for the Real World”

Log In or post as a guest

Replying to comment #473995:

« Return to Article