DEV Community

Discussion on: What's one of the ugliest piece of code you've written so far?

Collapse
 
tomassiriouala profile image
tomassiriouala

I once wrote a boolToInt

int boolToInt(boolean bool){
     if(bool){
          return 1;
     else{
          return 0;
     }
}

Not proud. It was my first year

Collapse
 
murrayvarey profile image
MurrayVarey

Ah, I see the problem -- you should have used a ternary operator!

Collapse
 
moopet profile image
Ben Sinclair

It should use an IntegerFactory.

Thread Thread
 
murrayvarey profile image
MurrayVarey

Slaps forehead. Of course! Better make it Abstract, just to be sure.

Collapse
 
weeb profile image
Patrik Kiss

That is ugly indeed. What were you even doing there?

Here, I corrected your code

int boolToInt(boolean bool){
     if(bool===true && bool!==false){
          return 1;
     else{
          return 0;
     }
}
Collapse
 
sambajahlo profile image
Samba Diallo

10/10, I'd include it in every file of a project for the enjoyment of those reading my code.