Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: a style question: |
| Date | 2015-08-31 18:42 +0200 |
| Organization | albasani.net |
| Message-ID | <20150831184244.6f9c5a81@maxa-pc> (permalink) |
| References | <8d16838c-60db-4fd2-b401-737ee2601d1d@googlegroups.com> <6e9323cb-1dff-4bff-b19a-d4b1da735ffb@googlegroups.com> <ms1bf1$peo$1@dont-email.me> <20150831174610.7d3167b0@maxa-pc> <ms1v6v$ang$1@dont-email.me> |
On Mon, 31 Aug 2015 17:27:53 +0100
Bartc <bc@freeuk.com> wrote:
> On 31/08/2015 16:46, Melzzzzz wrote:
> > On Mon, 31 Aug 2015 11:50:50 +0100
> > Bartc <bc@freeuk.com> wrote:
>
> >> On 31/08/2015 11:24, Malcolm McLean wrote:
>
> >>> Usr::Graphics::BezierPathSimple<Math::real64_t, GREEN>
>
> >> What a language! (If C++ had never
> >> been invented, and someone presented something like this, we'd all
> >> think it was a wind-up.)
> >>
> >
> > Take a look at this expressive power, how many lines of code you
> > need in C for this:
> >
> > #include <iostream>
> > #include <vector>
> > #include <list>
> > #include <string>
> > #include <type_traits>
> >
> > namespace mine {
> > using std::begin;
> > using std::end;
> > template <class T>
> > decltype(begin(std::declval<T&>()),
> > end(std::declval<T&>()),
> > std::true_type{})
> > is_container(int);
> > template <class T>
> > std::false_type is_container(...);
> > };
> >
> > template <class T>
> > using is_container = decltype(mine::is_container<T>(0));
> >
> > template <class T>
> > void print(const T& cnt,std::true_type)
> > {
> > for(auto i:cnt)std::cout<<i<<'\n';
> > }
> >
> > template <class T>
> > void print(const T& cnt,std::false_type)
> > {
> > std::cout<<cnt<<'\n';
> > }
> >
> > void print(){}
> >
> > template <class K,class ...T>
> > void print(const K&k, const T&...t)
> > {
> > print(k,is_container<K>{});
> > print(t...);
> > }
> >
> > struct Prt1 {
> > std::string prt = "famous";
> > Prt1(){}
> > const char* begin()const
> > {
> > return prt.data();
> > }
> >
> > const char* end()const
> > {
> > return prt.data()+prt.size();
> > }
> >
> > };
> >
> > struct Prt2 {
> > int a = 5;
> > float b = 3.4;
> > Prt2(){}
> > friend std::ostream& operator<<(std::ostream& os, const
> > Prt2& p2) { os<<p2.a<<' '<<p2.b;
> > return os;
> > }
> > };
> >
> > int main(){
> > std::list<std::string> a={"a","b","c"};
> > std::vector<float> b = {1.1,1.2};
> > int arr[10]={0};
> > print(a,' ',200,b,arr,Prt1{},Prt2{});
> > }
> >
>
> I don't even know what you're trying to express here; I'm completely
> lost.
This is all it takes to implement print function (and there are
examples as well).
>
> What does Prt2(){} mean inside the struct for example?
Default constructor definition.
What does
> Prt2{} mean inside the call to print()?
Default constructing.
>
> In my dynamic language, if it's just a question of printing out all
> these different kinds of data, it's very straightforward:
>
> a := ("a","b","c")
> b := (1.1, 1.1)
> arr := (0,)*10
> prt2 := (5,3.4)
>
> println a, 200, b, arr, "?",prt1
Yes, but how many lines of code? ;)
>
> No classes, no templates, no iterators, no sub-classing, no traits,
> no 'friends', no nothing. It just works. There's some support
> machinery in the background, but it's hidden away; the programmer
> needs to know nothing about it.
Well, in C++ you have to know ;)
>
> This could have been the same inside a supposedly more advanced
> language such as C++, but they decided to make it complicated instead!
Few lines of code...
>
> Even if it has the capability of overriding various default
> behaviours, then sorry I'm not interested, not if it looks like the
> above.
It's not nice looking but you can understand it I'm sure ;)
>
> The thing is, there are plenty of languages with lots of expressive
> power already built-in. And they generally have far cleaner syntax
> than C++. And they are simpler to learn. And have a quicker
> development cycle. And ... If they were all as fast as C++, who would
> ever want to use C++ again?
Exactly.
>
> (BTW all these examples require me to compile them using
> '-std=c++11'. It makes you wonder what exactly C++ was capable of
> before 2011!)
C++ is now very good language. c++98 is ugly...
>
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
a style question: G G <gdotone@gmail.com> - 2015-08-31 02:30 -0700
Re: a style question: Ian Collins <ian-news@hotmail.com> - 2015-08-31 21:40 +1200
Re: a style question: jt@toerring.de (Jens Thoms Toerring) - 2015-08-31 09:52 +0000
Re: a style question: Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-31 03:24 -0700
Re: a style question: Bartc <bc@freeuk.com> - 2015-08-31 11:50 +0100
Re: a style question: Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-31 13:21 +0100
Re: a style question: Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-31 05:41 -0700
Re: a style question: Bartc <bc@freeuk.com> - 2015-08-31 14:55 +0100
Re: a style question: Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-31 15:50 +0100
Re: a style question: Bartc <bc@freeuk.com> - 2015-08-31 18:40 +0100
Re: a style question: Melzzzzz <mel@zzzzz.com> - 2015-08-31 17:46 +0200
Re: a style question: Bartc <bc@freeuk.com> - 2015-08-31 17:27 +0100
Re: a style question: Melzzzzz <mel@zzzzz.com> - 2015-08-31 18:42 +0200
Re: a style question: Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-08-31 17:41 +0000
Re: a style question: Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-31 15:33 -0700
Re: a style question: Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-09-01 08:34 +0000
Re: a style question: Ian Collins <ian-news@hotmail.com> - 2015-09-01 07:40 +1200
Re: a style question: Bartc <bc@freeuk.com> - 2015-08-31 21:36 +0100
Re: a style question: Ian Collins <ian-news@hotmail.com> - 2015-09-01 08:51 +1200
Re: a style question: Bartc <bc@freeuk.com> - 2015-08-31 22:37 +0100
Re: a style question: Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-31 15:24 -0700
Re: a style question: Ian Collins <ian-news@hotmail.com> - 2015-09-02 19:37 +1200
Re: a style question: jt@toerring.de (Jens Thoms Toerring) - 2015-08-31 23:33 +0000
Re: a style question: Bartc <bc@freeuk.com> - 2015-09-01 01:13 +0100
Re: a style question: Ian Collins <ian-news@hotmail.com> - 2015-09-01 18:21 +1200
Re: a style question: jt@toerring.de (Jens Thoms Toerring) - 2015-09-01 15:23 +0000
Re: a style question: Bartc <bc@freeuk.com> - 2015-09-01 18:06 +0100
Re: a style question: Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-09-01 20:39 +0000
Re: a style question: jt@toerring.de (Jens Thoms Toerring) - 2015-09-01 20:45 +0000
Re: a style question: Bartc <bc@freeuk.com> - 2015-09-01 22:53 +0100
Re: a style question: Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-31 17:51 -0700
csiph-web