"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet wrote:That is also a solution. It is just another syntax for the same functionality. One problem in your case is that you don't know when to close the resources. It could be done when the variable goes out of scope but that could take for ever.
Well that is your opinion. I find it quite clear and intuitive.N Nan wrote:The proposed syntax is really ugly.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet wrote:
Well that is your opinion. I find it quite clear and intuitive.N Nan wrote:The proposed syntax is really ugly.
In your suggestion could you explain when the resources will be closed this the following situation:
You can use scientific method to find out if more lines of code is needed.
Matthew Brown wrote:
You can use scientific method to find out if more lines of code is needed.
That, in my opinion, correlates very poorly with readability. Just look at perl .
N Nan wrote:It's not opinion in this case. You can use scientific method to find out if more lines of code is needed, if more syntactic sugar is needed, if more restriction is needed.
N Nan wrote:As I said above, the implementation is the same, so you shouldn't ask that question. But I'll answer here anyway:
Indeed in your case that can't be done. That is one of the things I like about the Java 7 syntax. It forces you to think about the scope of your resources. Probably resulting in a smaller scope and thus reducing resource usage.N Nan wrote:It's not the variable going out of scope here.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
N Nan wrote:I took the time explain above why the code is better. People here just ignore it.
You can use scientific method to find out if more lines of code is needed
Paul Clapham wrote:
N Nan wrote:I took the time explain above why the code is better. People here just ignore it.
Yes, I think that was an explanation. I didn't read it because I'm not really interested in the subject, but let's say for the sake of argument that it was an explanation.
And then you said
You can use scientific method to find out if more lines of code is needed
But this statement had no foundation at all. Where's your experiment? What's the theory you're testing? You're the one with the "talking general" in this case.
N Nan wrote:I think you're mistaken different things here. You start to talk general. The number of lines, and other things I mentioned sure cause readability issue if the get abbreviated. I didn't do anything like that to the code.
Just a tag.
N Nan wrote:For C# reference, that's rather strange. We don't have to borrow C# if we have a better solution.
Matthew Brown wrote:
N Nan wrote:I think you're mistaken different things here. You start to talk general. The number of lines, and other things I mentioned sure cause readability issue if the get abbreviated. I didn't do anything like that to the code.
Just a tag.
I don't think so. You've just added a tag, that's fine, but you've added a new mechanism. The question is whether that tag expresses that new mechanism in a way that is clear to all readers. Then you appeared to try to use the number of lines as proof that the approach was superior (the "scientific method") - I was just pointing out that it isn't. I think the proposed mechanism expresses the proposed meaning more naturally. But, of course, that's just my opinion.
N Nan wrote:For C# reference, that's rather strange. We don't have to borrow C# if we have a better solution.
I think it's a relevant reference, because it means I've recently started using the syntax that you are objecting to for real development, and I know it works well. I'd probably put it as one of my three favourite features that C# has that Java doesn't yet.
Matthew Brown wrote:The construct expresses two things: the concept and the scope. I think it is clearer to express the concept with the keyword and the scope with the brackets: one idea one representation. This is why I disagree with the statement "shorter, hence better" - I prefer "more natural mapping to the meaning, hence better".
You're right that an empirical study would be the only way to be sure, though.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook