|
Just came across this code from an ex-coworker (names changed to protect the innocent):
Select Case DoStuff(SomeVariable)
Case 0
Case 1, 2
Case Else
result = "omgnub"
End Select
When I saw that, I . Well played, n00b, well played.
|
|
|
|
|
Nice, that's epic!
""Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
That reminded me of a custom exception one of my friends made: NoobDetectedException . He said he would take it out when he turned in the project, but he didn't. The professor hit the exception, and was not very pleased.
The professor showed the class the exception, which had the message: "You are a noob. You will be assimilated. There will be no escape. (This also applies to <professor name omitted>")
public class SysAdmin : Employee
{
public override void DoWork(IWorkItem workItem)
{
if (workItem.User.Type == UserType.NoLearn){
throw new NoIWillNotFixYourComputerException(new Luser(workItem.User));
}else{
base.DoWork(workItem);
}
}
}
|
|
|
|
|
good practices to use a memcached client to make your site faster!
public IEnumerable<Product> GetProductList()
{
List<Product> data = null;
var key = string.Format("{0}", "Some_Beautiful_Key");
if (_cache != null)
if (_cache.Contains(key))
data = _cache.Get< List <Product> >(key);
data = TheDao.GetProductTable();
if (_cache != null)
_cache.SaveOrUpdate(key, data);
return data;
}
Rudy Alvarez // rdebug.com
|
|
|
|
|
Cache smash. Who needs it anyway?
"You get that on the big jobs."
|
|
|
|
|
When you already omit the {curly brackets}, you should not hesitate and do the next step: omit indentation, or better use random indentation.
public IEnumerable<Product> GetProductList()
{
List<Product> data = null;
var key = string.Format("{0}", "Some_Beautiful_Key");
if (_cache != null)
if (_cache.Contains(key)) data = _cache.Get<List<Product>>(key);
data = TheDao.GetProductTable();
if (_cache != null) _cache.SaveOrUpdate(key, data);
return data;
}
And such features will be even harder to spot for the guys who have to fix your code.
|
|
|
|
|
|
I'm the guy that fix code :'( jajajaja
|
|
|
|
|
Just saw this legacy gem
if(myArrayList.Contains(something)==true || myArrayList.Count>0)
{
if(myArrayList.Contains(something)==false)
{
default=something;
}
else
{
default=myArrayList[0];
}
}
this is for C#.net.
|
|
|
|
|
If you look at MSDN[^] you will see it returns a virtual bool , so obviously you can't trust it!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
"virtual bool" so anyone can override to make it float.
|
|
|
|
|
Well, you wouldn't want it to sink, would you?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I love how the first Contains is redundant and the default does not get set if myArrayList is empty.
|
|
|
|
|
Still worse: when the array list does not contain "something", the default is set to something. When the array list contains something, the default is set to the first element of the array list, which may or may not be "something"...
|
|
|
|
|
Hey guys, i'm a software developer from Romania, and I've been a lurker here for quite a while. Currently, i'm working on an Android project, and, well, this morning I've caused a wtf fail. Thankfully, I realized it immediately (i.e. after the first NullPointerException) and quickly fixed it.
However, I could not resist posting this here, as it's a beginner's mistake, and I shouldn't have done it in the first place (shame on me). Variable and method names changed, and the original class was much, much larger
public class CategoryProducts extends ListActivity {
private RangeSeekBar<Integer> seekBar;
private int minPrice = 0;
private int maxPrice = 100000;
private void initFilterView() {
if(seekBar == null) {
RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(minPrice, maxPrice);
seekBar.setOnRangeSeekBarChangeListener(new PriceLimitListener());
}
((LinearLayout) filterView.findViewById(R.id.priceSeekBar)).addView(seekBar);
}
}
The explanation (if you haven't spot it already) is that seekBar gets declared as local in the "if" of the initFilterView method, and visible only in that scope. The local "seekBar" and the global "seekBar" are in fact 2 different vars, and nobody guarantees that the global "seekBar" will not be null (which happens in this case). The correct code was
...(same as above)
if(seekBar == null) {
seekBar = new RangeSeekBar<Integer>(minPrice, maxPrice);
seekBar.setOnRangeSeekBarChangeListener(new PriceLimitListener());
}
...(same as above)
|
|
|
|
|
My vote of 5, to accept your mistake.
Newton's unspecified law:
No code in world is bug free!
|
|
|
|
|
Interesting!
How did that compile without an error:
"A local variable named 'seekBar' cannot be declared in this scope because it would give a different meaning to 'seekBar ', which is already used in a 'parent or current' scope to denote something else"
Because it won't for me!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
EDIT: I believe you've tried this in VS, I dunno if Eclipse has that sort of stuff
I can also post pics
|
|
|
|
|
Now I am starting to believe that world is moving to .net,
God save JAVA
|
|
|
|
|
Yeah, although Java was the first language I've learned and I do still love it with all my heart, after I worked with .NET I've started to understand why people are moving to it.
I think VS2010 Pro is a beauty of an IDE. I didn't get 2011 yet, but from what I've read around here, people aren't really satisfied with it
|
|
|
|
|
|
Agreed - variable masking is a bad idea, it leads to some very hard to spot bugs.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
In the code where the view get's cleared from the current model (i.e. when you want to save changes in the program but have everything cleared), I have found this little gem:
(Variable-Names changed to protect the innocent)
if(view != null)
{
SetUI(view);
myTree.Update(view);
}
else
{
MessageBox.Show("Error when saving, Model is lost in space");
}
As you'd assume, every change is lost when the view is null, and the user has no idea what just happened.
|
|
|
|
|
dakovinc wrote: and the user has no idea what just happened.
Of course they have! they know that the data he entered took the wrong path and ended up in a black hole!
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
Sentenryu wrote: Of course they have! they know that the data he entered took the wrong path and
ended up in a black hole!
Always Keep Smiling.
Yours Pankaj Nikam
|
|
|
|