LLVM Coding Standards

Spacen Jasset spacenjasset at yahoo.co.uk
Fri Apr 15 04:10:01 PDT 2011


On 12/04/2011 11:21, Mafi wrote:
> Am 12.04.2011 00:31, schrieb Spacen Jasset:
>> std::getline(is, line);
>> while (line.size() != 0)
>> {
>> ...some things...
>> std::getline(is, line);
>> }
>
> What's wrong with
> while( std::getline(is, line), (line.size() != 0) ) {
> //... some things
> }
>
> I mean, that's what the comma operator is for.
Ah yes well. I was wondering who was going to throw that in. 
Well...okay. But sometimes it's not just one statement that you always 
need to do before your test condition.

Also, I would say that sort of code is a little bit more difficult to 
read. I don't mind typing a little bit more to be able to make it look a 
bit better.

As other posters have pointed out, it seems to me, at least, that having 
a way to express your model/idea or view of a problem directly is the 
most useful thing a language can give you.

In other words less code structure design caused by safety and/or other 
issues, and more problem, higher level design visible in the code. As an 
example, perhaps not a great one. The RAII pattern. It's a code type of 
design/solution used to manage resources, and specifically to prevent 
resource leaks, rather than anything in particular to do with a problem 
that is being solved. e.g. That of reading and processing a file.

So we end up with
(a) solution to some problem
(b) solution to the method of expressing the solution to the problem

as you have put above:
while( std::getline(is, line), (line.size() != 0) ) {

There is a strong component of (b), rather than just (a), which ideally 
in utopia we don't want to spend time on thinking about.





More information about the Digitalmars-d mailing list