Those are called quickscopes. ;D
If this thread is supposed to be satirical, here you go:
public class Jeviny extends JGOMember{
public Jeviny (){
super(0);}
Texture jev;
public void init(ResourceManager r){jev=TextureLoader.loadTexture("/jev.jif");};
public void update(float d){System.out.println(new Random().nextInt(1337));shit_post();}
public void render(Graphics g){ g.drawTexture(jev);
}public static void main(String[] a){new Jeviny();} // d
}
If this thread is supposed to demonstrate actual cringy coding styles/formatting, there’s a video you should watch.
- Jev
Yeah, I noticed that once I posted it. My bad!
Also, are you Bucky? My friend told be thenewboston writes the same way.
No, he’s impersonating Bucky and making fun of him for using weird, un-descriptive class names.
I came across this piece of incredibly awesome looking code:
Its in some kind of c++ type language, but still fits the topic, so…
MyClass* myClass = new MyClass();
if(myClass) myClass.doSomething();
Another thing that makes me cringe is…
public void doSomething()
{
new Thread()
{
public void run()
{
System.out.println("This code..");
}
}.start();
}
I also really hate this…
int integer=10; // bad
int integer = 10; // good
I also really hate this…
int integer=10; // bad int integer = 10; // good
Even worse is inconsistency: [icode]int x= 10;[/icode] :yawn:
Ow god that is even worse than my examples… Wow… It just looks soooo bad…
It does, but it does not make it harder to read so…
But its disgusting to look at. One should take pride in their code, especially how it looks…
I give you some code I had to deal with lately (legacy Java 1.3 or 4 code):
public Double addTwoDouble(Double a, Double b)
{
if(a != null)
if(b != null)
return new Double(a.doubleValue() + b.doubleValue());
else
return new Double(0.0);
else
return null;
//and the other way around
}
yes I know why they did it, but it is so cringe worthy not the less.
I imagine it’s projects like those that gave you your avatar?
I see this way too often:
if(blood == true){ //or just (!)blood
blood = false;
}else if(blood == false){ // but exaggerating is mandatory in this thread (just like the semicolons)
blood = true;
}
That’s annoying, but not as bad. Many “newbies” to programming don’t know the little tricks like that. I do cringe when I forget and sometimes do that though. Gets erased right away and I do it the shortcut way!
blood = !blood;
Shorter ideas?
blood = !blood;
Shorter ideas?
Actually, yes, Riven had one:
To reduce the redundancy and verbosity:
[icode]blood ^= true;[/icode] (it might look obscure, but your brain will soon recognize this as ‘toggle’)
I came across this piece of incredibly awesome looking code:
Its in some kind of c++ type language, but still fits the topic, so…
MyClass* myClass = new MyClass(); if(myClass) myClass.doSomething();
This makes sense, this is probably in more industrial or maybe code for an embedded device. If the new call does not work because you run out of memory it will return null. Well Malloc does at least i’m assuming new does too
-edit
I was wrong a new without enough space throws a new bad_alloc, but some compilers will just return null
Let me correct myself. Here is how the code might look in java.
String paramStr = "Param received in method";
HashMap<String, String> map = new HashMap<String, String>();
if(map != null) map.put("Key", "Value");
if(paramStr != null) map.put("Key", paramStr);
Don’t wan’t to get too off topic, but in Java when you don’t have enough memory for a new call it throws an OutOfMemoryException. In C++ it throws a bad_alloc. In C a malloc will return null and some C++ compilers, VC 06 being a good example, will also return null if there isn’t enough memory on a new call.
In C:
someting* stuff = malloc(TooMuchMem);
will return null, so to check that the memory allocation was successful it is common to start the next line of code with if(stuff).
Also this is a C thing, doesn’t have a reasonable equivalent in Java
-add/edit/reply
So you just added the parmStr thing after i posted this. That is different. In java this doesn’t apply as i noted earlier. Your first post I replied to was an example in C++
Ill try to explain this better:
if(null) is the same as saying if(false).
a new call in some C++ compilers and a malloc in C returns null IF there isn’t enough memory.
Therefore,
by doing
Pointer* ptr = malloc(sizeof(ptr));
or
Pointer* ptr = new Pointer(); //in SOME older compilers
if(ptr) …
we are just making sure that the allocation of memory for pointer was successful, AKA that we didn’t run out of memory.
Did you even read the code I wrote? It checks first line of the object is not null, and afterwards it doesn’t care if its null. Its same as saying if(true) doSomething();