As peoples said, adding those word do not really offer a useful syntactic sugar, because the cost to read a while ( or a if (! is small, all C developers are used to, and using such macro you'll scary most of the C developers. Also, making a language look like an other isn't a good idea.
BUT, syntactic sugar matters. As already stated, in C++, boost add lot's of syntactic sugar through templates, and the stl also provide Somme sugar (for example, std::make_pair(a, b)
is a syntactic sugar for std::pair<decltype(a), decltype(b)>(a, b)
.
As a language improve, both functionalities and syntactic sugar are added to improve readability, writability, and efficiency of developers. For example, with the C++11 spec, the "for (elements in datastructure)" was added (see below), and also the "auto" keyword which allow a week inference of types (I say weak because you need to type a lot's of types at a lots of places where the type is actually 'obvious' and redundant).
Also, in haskell, using monads without the do notation (syntactic sugar) would be a real pain, and no-one would be using them1.
An example without syntactic sugar:
//C++ < 11
std::vector<int> v;
v.push_back(3);
v.push_back(7);
v.push_back(9);
v.push_back(12);
for (std::vector<int>::iterator it = v.begin();
it != v.end();
it++)
{
std::cout << *it << std::endl;
}
And with syntactic sugar:
//C++ >= 11
std::vector<int> v {3, 7, 9, 12};
for (auto elm : v)
{
std::cout << elm << std::endl;
}
A bit more readable, no?
An haskell example for the IO monad (from HaskellWiki) :
f :: IO String
f =
ask "What's your name ?" >>= \name ->
putStrLn "Write something." >>= \_ ->
getLine >>= \string ->
putStrLn ("Hello " ++ name ++ " you wrote " ++ string) >>= \_ ->
return name
g :: IO String
g = do
name <- ask "What's your name ?"
putStrLn "Write something."
string <- getLine
putStrLn ("Hello " ++ name ++ " you wrote " ++ string)
return name
Here is a link to ideone : http://ideone.com/v9BqiZ
1: Actually, the language is more flexible than C++ and allow creating operators (for example &^, +., :+:, ...), so we could imagine that someone would quickly introduce syntactic sugar again :).
sugar.h
containing Pascal like definitions... – Ropewayunless
with anelse
clause (I love when/unless in lisp, however). I'm not really impressed by anuntil
loop but may be because I've never used it before. – Adpwhile
can be easily implemented viaif... goto
, but the former for succinctly expresses your desire to loop. – Pitiableuntil
properly. – Millenary#define
, make a transpiler so people can still read it in C. – Instantly