I wasn''t going to say anything more, but you''ve raised some interesting points...
quote:Original post by Anonymous Poster
A thought that I have on the topic which I find interesting (but not terribly surprising) is that nobody has mentioned the principles of software engineering at all anywhere in the thread
I did make a vague reference to symmetry earlier on, but I think it got lost in the noise (or I didn''t emphasise it very much). I''ve said some more about it since.
quote:
to use approaches like not closing things that are open complicate the debugging and maintenance of the project for future coders.
I''m gonna have to say it again: it''s not a case of not closing things, it''s a case of understanding that the dtor deals with closing the file, and arranging your surrounding concepts to take advantage of that. If implicitly closing a file makes a system harder to understand, then I suspect that''s as a symptom of the enclosing scope being badly organised. I think you''re taking the rule "always be explicit" and failing to offset it against other ideas.
quote:
There are several principles that apply here which come to mind - localization, readability, maintainability, and perhaps uniformity seem very relavent.
Yup, but apparently not self-evident as I have exactly the opposite view to you whilst considering these same concepts.
quote:
Can the principles be applied and still follow the technique whereas some contributors would rely on the compiler to close files (in this instance) implicitly?
I don''t think I understand this sentence.
quote:
Perhaps, but then we begin to assume a lot about the skills and knowledge of the coders that we work with and any future coders that work on the project. That''s a fairly hefty gamble. It can be effectively disregarded by a blanket statement in which one holds all of the programmers in an organization to a minimal level of mastery of their environment, but that''s not terribly realistic.
This is a good point, but I can''t resist poking it a bit. Firstly, if you''re talking about incompetence, that can work both ways. When writing code, you have an intended audience. Or rather, two intended audiences: other people and the computer. Other people means competent programmers who are familiar with the language. If the actual audience ends up being incompetent programmers then that is a problem of the organisation''s hiring policy, not a problem with the way you''ve written the code. You cannot write s/w for incompetent programmers - you simply can''t second guess what they will be able to understand. The last point on this is to remember what we are talking about: we''re discussing closing a filestream object. It''s not an esoteric subject.
quote:
Nor is it realistic or fair to dismiss the concern by simply stating that one should have intimate knowledge of the environment that they''re working in - people have to develop the experience from somewhere, and not everyone will have that express knowledge even with years of experience if they''ve never worked with a specifically related problem.
They can RTFM. Remember, this is only an ofstream. Surely you''re not saying only highly competent programmers know how to read something like Josuttis, are you?
quote:
I suspect I''m probably severely biased in that I''m a programming teacher in a school where software engineering is heavily emphasized. Now after a few years teaching here it''s really become part of my techniques and habits.
Software engineering is a fast-moving target. Many designs that would have been good 10 years ago are shunned today. Witness pre-STL container frameworks.
quote:
the overhead would be negligable if any, but the understandability of what was written would increase significantly.
That depends. If you break symmetry, you hamper human understanding. In addition, an explicit close() also introduces coupling into your design. OK, so it''s only export coupling, but it''s still avoidable coupling, no?
quote:
Perhaps if explicitly closing files was a technique that bothers some who feel it would be wasted time, would it be just as evil to perhaps place a comment at the end of the message processing stating that the file is not explicitly closed due to the fact that it is closed by the destructor at the loss of scope and call it a compromise?
That would be worse. I''d even favour explicit closing over that suggestion. You would both be adding a needless comment, thus introducing another maintenance point, whilst explicitly stating you are programming for an incompetent audience. Since you are interested in s/w engineering, you should realise how much damage an incompetent programmer can cause.
Anecdotal evidence leads me to believe the s/w industry would be better off with *less* people, by getting rid of the incompetents and thus improving the average ability. Certainly, I''ve been in jobs where the majority of my time has been spent dealing with the accidental complexity created by idiots. Time which would have been better spent responding to business needs, thus making the organisation more competitive.