C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

syntax simplification for very short functions

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Jan Ringo¹
Guest





PostPosted: Fri Apr 20, 2007 2:17 am    Post subject: syntax simplification for very short functions Reply with quote



Let me introduce this small thing I have in mind for some time.

The direction of modern programming emphasize mostly short and

single-purpose functions. Most of them are predicates and we can't

completely avoid writting forwarding functions. With const_expr comming

into standard, there will be a lot more of them.



Over time, I started formatting such functions like this:



int func () { return *simple equation here*; };



or, when reaching often demanded imaginary 80-column limit, like this:



int func ()

{ return *simple equation here*; };



The reasons for this formatting is to have more of code on the screen, and

to have the code tabular for better orientation in packs of similar

functions. But actually because heavy use of qualifiers and C++-style

casts, this formatting exceeds the "row length" as well.





So the idea is, when we already have the function-try-blocks, why couldn't

we be able to write just:



int func ()

return *simple equation here*;



At least 4 characters saved Wink The function-try-blocks were lattest, but

are probably not last, thing I discovered in C++. I can see (but I may be

wrong) that they were introduced merely because of contructor initializer

lists, but when the foundation is already in there why not to build on in?



I am really interesting in what do you think about this.

Is there a problem with described syntactic simplification that I don't

see?





Advantages:

+ No existing code get broken. I don't have very wide experiences with

various compilers but none I work with accept such code today.

+ Less "noise" characters and shorter rows allows more transparent code to

be written

+ Will probably need not more than two short paragraphs of normative

wording



Subjective:

* A little prettier syntax for predicates and forwarding functions

* Could walk hand in hand with const_expr



Disadvantages:

- Not at all suitable for long expressions

- More programming for compiler vendors



--

Jan Ringo¹, Tringi@MX-3.cz

http://Tringi.MX-3.cz

http://www.ringos.cz


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.