Ranter
Join devRant
Do all the things like
				++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
				Sign Up
			Pipeless API
 
				From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
				Learn More
			Comments
		- 
				
				 Agred19868yNah, if blocks with one statement look bad and no one I know, be it certified Java Dev or a guy who just started working for the first time, ever said that they make reading easier. Agred19868yNah, if blocks with one statement look bad and no one I know, be it certified Java Dev or a guy who just started working for the first time, ever said that they make reading easier.
 I'm gonna cry if next time I'll see a post saying that breaking if else block into oneliner (return x == null ? y : x) is also bad and makes it hard to read.
 I'll stick to removing them when they are not necessary, thank you very much.
- 
				
				 Doruk3438yHere's a +1 from a c# guy. It's hard to read code without braces. It's open to mistakes. Doruk3438yHere's a +1 from a c# guy. It's hard to read code without braces. It's open to mistakes.
- 
				
				@Doruk Exactly open to mistakes. Also, due to the formatting, the single line of code may be word wrapped and it may go upto 2-3 lines and ya that is difficult to read and comprehend.
- 
				
				@Agred no I would still prefer an if-else with { } above ternery operator any day. Why are you so hell bent on reducing the locs??? Readable code is the best code.
 
 Also the scenarios where ? : actualy makes a good readable code is very hard to come by.
- 
				
				Imho it depends. For a longer line I'd definitely still use the {}, but if it's only a "i++;" or "return i;" I find it more readable to just write it without a block.
- 
				
				 uuid25468yWhen I started programming, I avoided having braces if there's one line, till I started working on unit testing and coverage using PHPUnit, it seems it does not know how to evaluate coverage of a block unless it's between braces. uuid25468yWhen I started programming, I avoided having braces if there's one line, till I started working on unit testing and coverage using PHPUnit, it seems it does not know how to evaluate coverage of a block unless it's between braces.
 Now it became a habit to put everything between braces. And to be honest, the code seems more organised.
- 
				
				 Agred19868y@bitsnpieces Why am I bent on writing like this? It's probably a problem like with Big and little endian. One doesn't really make sense to people that like the other better. Agred19868y@bitsnpieces Why am I bent on writing like this? It's probably a problem like with Big and little endian. One doesn't really make sense to people that like the other better.
 I guess the problem is not really with having braces or removing them but with writing clean, readable code. I think that if you write your code good there won't be any issue with or without them.
- 
				
				 Fradow8988yIt makes sense to always add braces all the time, even for 1 line, because otherwise, at some point, someone, either tired or inexperienced (or both), is going to add a line just after the 1 line, thinking it's in the "if" statement. Fradow8988yIt makes sense to always add braces all the time, even for 1 line, because otherwise, at some point, someone, either tired or inexperienced (or both), is going to add a line just after the 1 line, thinking it's in the "if" statement.
 
 And that mistake can cost you, a lot. In fact, I'm pretty sure I heard about this specific mistake in a public report of a costly programming error.





For fuck's sake please add braces for blocks even if there is only a single loc inside. 1 line wont ruin anything but it would be a very big favor for the person reading the code.
I am talking about java. Python guys, you good ✌️
rant