using Java and .NET where the runtime holds your hand and makes it easier for mediocre programmers to survive. If they had to code in C/C++
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Code review - hilarious code snippets
Collapse
X
Collapse
-
.NET yes but Java? Incomprehensible. Even MFC was easier. If Fidel Castro has written a programming language it would have been Java.bloggoth
If everything isn't black and white, I say, 'Why the hell not?'
John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson) -
But that wasn't what you were originally complaining about. If its null when you are trying to create an object that's should be an error, if its null when retrieving an object that's plausible.Originally posted by doodab View PostIf it's a valid result then fair enough but if you can't initialize an object properly when the constructor is called throw an exception in the constructor.
You are however forgetting that people don't like raising errors as that means you have to do proper error trapping and handling which requires thinking and that will never occur.merely at clientco for the entertainmentComment
-
Java and C# have virtually the same syntax, which is largely the result of Microsoft copying Java.Originally posted by xoggoth View Post.NET yes but Java? Incomprehensible. Even MFC was easier. If Fidel Castro has written a programming language it would have been Java.Comment
-
I was complaining about people writing java like it's C, i.e. returning null to indicate an error condition rather than raising an exception. One could see from reading the code it was written in a particular idiomatic C style. The only thing missing was an attempt at a static global Errno class.Originally posted by eek View PostBut that wasn't what you were originally complaining about. If its null when you are trying to create an object that's should be an error, if its null when retrieving an object that's plausible.
In this case the only reason the results would be null was because the object had not been initialized properly at create time because one of the 20 or so mostly unnecessary parameters to the constructor was null. This should result in an exception from the constructor, not a null pointer exception from somewhere inside the offending class 3 minutes later.
This particular guy, not knowing about 'throw', was returning a ****ed up object, calling a method called isValid() (that was broken too) to see if the constructor had worked, and then proceeded to invoke methods on the class that would either result in a null pointer exception or a null result which may or may not get checked
The 20 or so constructor parameters were being passed down a chain of constructors calling constructors 4 or 5 deep, with the various objects holding references to their parent to access certain fields.
The worst one I have seen was an attempt at recreating function-per-file modularity where each class had a single static method in it.
Another sign of a C programmer who is converting to java is returning an int status code from a method to indicate an error so that every method call has to be followed by an if (result != 0) spaghetti monster rather than using a try-catch block. Which you need anyway to catch the null pointer exceptions
Last edited by doodab; 13 February 2012, 13:07.While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'Comment
-
I agree returning null from a method where you are querying for a specific object , if its not found then it should return null, not throw an exception as they are expensive, this though leads to lots of if (obj == null) all over the shop.Originally posted by eek View PostBut that wasn't what you were originally complaining about. If its null when you are trying to create an object that's should be an error, if its null when retrieving an object that's plausible.
You are however forgetting that people don't like raising errors as that means you have to do proper error trapping and handling which requires thinking and that will never occur.Comment
-
I can't remember the last time any of my apps crashed and took down the system... my C++ apps crash just the same way as my Java apps crashOriginally posted by russell View PostYeah but a bad C/C++ program can do much more damage than a managed program. Can take down the whole system if you can't properly manage memory or work with pointers etc.
Don't MacOSX, Linux and modern versions of Windows protect against this?
Originally posted by MaryPoppinsI'd still not breastfeed a naziOriginally posted by vetranUrine is quite nourishingComment
-
It's fair to say the guy in question wasn't a very good C programmer either.Originally posted by Spacecadet View PostSounds like a bad programmer rather than a problem of moving from C/C++ to JavaWhile you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'Comment
-
Was reviewing some code the other day with the main developer for the site in question. In a comment written a couple of years ago:
/* Here be dragons, proceed with caution */
No clue as to exactly why the dragons existed there or what we should be cautious about
Comment
-
Java and C# don't run directly on the metal, they are managed by a runtime. Granted you don't see Linux kernel crashing much, but you must remember BSOD, no doubt caused by unmanaged code.Originally posted by d000hg View PostI can't remember the last time any of my apps crashed and took down the system... my C++ apps crash just the same way as my Java apps crash
Don't MacOSX, Linux and modern versions of Windows protect against this?Comment
-
Was having a discussion on here some time ago with a .Net "guru". It turns out he wanted to use data binding to populate a control where was iterating through a dataset to build a simple array and then iterate through this array to populate the control was all that was needed.
Knock first as I might be balancing my chakras.Comment
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers

Comment