[LOOK] 李老师群课之 再谈元编程

[复制链接]
11600|79
缥缈九哥 发表于 2013-8-29 15:49 | 显示全部楼层
其实,古董对于有钱人也许值钱,对于一个叫花子,不能吃不能穿。不是垃圾是什么?李老师的代码也是如此。在需要的人眼里是好东西,在不需要的人眼里,一无用处,当然认为是垃圾了。
haiyuan254 发表于 2013-8-29 18:39 | 显示全部楼层
乡村男孩 发表于 2013-8-29 15:45
如果你认为是垃圾请指出垃圾之处,如果大家都认为你说得有理,那才是真正的交流,而不是无理放纵,如果客 ...

给你10000行这种代码让你维护,你试试~~~??就这程序10000行中出1个Bug看能不能弄死维护的人,维护的人每天骂死你。你编写的程序是要给其它人看的,要有继承性,有规范性,可维护!这种程序都是为了显示自己水平搞出来的。如果你要真有水平请把程序的详细设计的流程图给出来,看有几个人拿着你的流程图不会编程?所以不要把垃圾拿出来看!

评论

严重同意...  发表于 2013-9-7 15:43
aihe 发表于 2013-8-29 22:45 | 显示全部楼层
haiyuan254 发表于 2013-8-29 18:39
给你10000行这种代码让你维护,你试试~~~??就这程序10000行中出1个Bug看能不能弄死维护的人,维护的人 ...

人家是举例讲方法,看不明白就说人家垃圾,一点条理也没有
还以为你能贴出更好的代码来让我们欣赏呢
缥缈九哥 发表于 2013-8-29 22:51 | 显示全部楼层
唉,一万行代码要怎么写才好维护?一万行汇编?一万行A?一万行B?一万行C?一万行C++?一万行C#?我觉得都好难。给我1000行我都觉得难。我只想维护100行。最好是还拿着高薪并且不干活。

评论

连这个都不知道怎么写可维护,你还是先去看书吧.别闭门造车了.推荐<重构-改善既有代码的设计>  发表于 2013-9-7 15:44
zhangli019 发表于 2013-9-4 09:25 | 显示全部楼层
:L if i am not coding,then i am debugging;i have no time to think of this
icecut 发表于 2013-9-6 16:10 | 显示全部楼层
丧失了c++的可读性.低等代码....

我写过十万行c++,也没写过这么难读的东西
john_lee 发表于 2013-9-6 21:38 | 显示全部楼层
icecut 发表于 2013-9-6 16:10
丧失了c++的可读性.低等代码....

我写过十万行c++,也没写过这么难读的东西

十万行,不错,那倒要请教一下了,下面这段是不是你所谓的低等代码:
  1. template<std::size_t _Idx, typename _Head, typename... _Tail>
  2. struct _Tuple_impl<_Idx, _Head, _Tail...>
  3. : public _Tuple_impl<_Idx + 1, _Tail...>,
  4.   private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
  5. {
  6.   template<std::size_t, typename...> friend class _Tuple_impl;

  7.   typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
  8.   typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;

  9.   static constexpr _Head&  
  10.   _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }

  11.   static constexpr const _Head&
  12.   _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }

  13.   static constexpr _Inherited&
  14.   _M_tail(_Tuple_impl& __t) noexcept { return __t; }

  15.   static constexpr const _Inherited&
  16.   _M_tail(const _Tuple_impl& __t) noexcept { return __t; }

  17.   constexpr _Tuple_impl()
  18.   : _Inherited(), _Base() { }

  19.   explicit
  20.   constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
  21.   : _Inherited(__tail...), _Base(__head) { }

  22.   template<typename _UHead, typename... _UTail, typename = typename
  23.            enable_if<sizeof...(_Tail) == sizeof...(_UTail)>::type>
  24.     explicit
  25.     constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
  26.     : _Inherited(std::forward<_UTail>(__tail)...),
  27.       _Base(std::forward<_UHead>(__head)) { }

  28.   constexpr _Tuple_impl(const _Tuple_impl&) = default;

  29.   constexpr
  30.   _Tuple_impl(_Tuple_impl&& __in)
  31.   noexcept(__and_<is_nothrow_move_constructible<_Head>,
  32.                   is_nothrow_move_constructible<_Inherited>>::value)
  33.   : _Inherited(std::move(_M_tail(__in))),
  34.     _Base(std::forward<_Head>(_M_head(__in))) { }

  35.   template<typename... _UElements>
  36.     constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
  37.     : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
  38.       _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }

  39.   template<typename _UHead, typename... _UTails>
  40.     constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  41.     : _Inherited(std::move
  42.                  (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  43.       _Base(std::forward<_UHead>
  44.             (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }

  45.   template<typename _Alloc>
  46.     _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
  47.     : _Inherited(__tag, __a),
  48.       _Base(__use_alloc<_Head>(__a)) { }

  49.   template<typename _Alloc>
  50.     _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  51.                 const _Head& __head, const _Tail&... __tail)
  52.     : _Inherited(__tag, __a, __tail...),
  53.       _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }

  54.   template<typename _Alloc, typename _UHead, typename... _UTail,
  55.            typename = typename enable_if<sizeof...(_Tail)
  56.                                          == sizeof...(_UTail)>::type>
  57.     _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  58.                 _UHead&& __head, _UTail&&... __tail)
  59.     : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
  60.       _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  61.             std::forward<_UHead>(__head)) { }

  62.   template<typename _Alloc>
  63.     _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  64.                 const _Tuple_impl& __in)
  65.     : _Inherited(__tag, __a, _M_tail(__in)),
  66.       _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }

  67.   template<typename _Alloc>
  68.     _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  69.                 _Tuple_impl&& __in)
  70.     : _Inherited(__tag, __a, std::move(_M_tail(__in))),
  71.       _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  72.             std::forward<_Head>(_M_head(__in))) { }

  73.   template<typename _Alloc, typename... _UElements>
  74.     _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  75.                 const _Tuple_impl<_Idx, _UElements...>& __in)
  76.     : _Inherited(__tag, __a,
  77.                  _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
  78.       _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
  79.             _Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }

  80.   template<typename _Alloc, typename _UHead, typename... _UTails>
  81.     _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
  82.                 _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  83.     : _Inherited(__tag, __a, std::move
  84.                  (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
  85.       _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
  86.             std::forward<_UHead>
  87.             (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }

  88.   _Tuple_impl&
  89.   operator=(const _Tuple_impl& __in)
  90.   {
  91.     _M_head(*this) = _M_head(__in);
  92.     _M_tail(*this) = _M_tail(__in);
  93.     return *this;
  94.   }

  95.   _Tuple_impl&
  96.   operator=(_Tuple_impl&& __in)
  97.   noexcept(__and_<is_nothrow_move_assignable<_Head>,
  98.                   is_nothrow_move_assignable<_Inherited>>::value)
  99.   {
  100.     _M_head(*this) = std::forward<_Head>(_M_head(__in));
  101.     _M_tail(*this) = std::move(_M_tail(__in));
  102.     return *this;
  103.   }

  104.   template<typename... _UElements>
  105.     _Tuple_impl&
  106.     operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
  107.     {
  108.       _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
  109.       _M_tail(*this) = _Tuple_impl<_Idx, _UElements...>::_M_tail(__in);
  110.       return *this;
  111.     }

  112.   template<typename _UHead, typename... _UTails>
  113.     _Tuple_impl&
  114.     operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
  115.     {
  116.       _M_head(*this) = std::forward<_UHead>
  117.         (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
  118.       _M_tail(*this) = std::move
  119.         (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in));
  120.       return *this;
  121.     }

  122. protected:
  123.   void
  124.   _M_swap(_Tuple_impl& __in)
  125.   noexcept(noexcept(swap(std::declval<_Head&>(),
  126.                          std::declval<_Head&>()))
  127.            && noexcept(_M_tail(__in)._M_swap(_M_tail(__in))))
  128.   {
  129.     using std::swap;
  130.     swap(_M_head(*this), _M_head(__in));
  131.     _Inherited::_M_swap(_M_tail(__in));
  132.   }
  133. };
icecut 发表于 2013-9-6 23:32 | 显示全部楼层
我说你可读性差.对于应用就是低等代码.
你复制那段代码做基础代码平台代码都没问题,就是不能做应用层.明白?
不要弄个stdc++的lib来忽悠大家.
我们写的是application,不是lib,不一样的思路的.把大家忽悠傻了不好.
上面代码我不认识.百度不可能不认识,谷歌不可能不认识,因为我一看就不是你自己写的.

john_lee 发表于 2013-9-7 00:36 | 显示全部楼层
icecut 发表于 2013-9-6 23:32
我说你可读性差.对于应用就是低等代码.
你复制那段代码做基础代码平台代码都没问题,就是不能做应用层.明白? ...

你从哪儿看出来我写的这段代码是应用层的?
  1. namespace crc32 {
  2. template <uint32_t CRC, uint8_t BIT = 0>
  3. struct byte : byte <(CRC >> 1) ^ (-int32_t (CRC & 1) & 0xedb88320), BIT + 1> { };

  4. template <uint32_t CRC>
  5. struct byte <CRC, 8> { uint32_t value{ CRC }; };

  6. template <uint16_t I = 0>
  7. struct array : byte <I>, array <I + 1> { };

  8. template <>
  9. struct array <256> { };

  10. struct table : private array <> {
  11.   const uint32_t& operator [] (int i) const
  12.   {
  13.     return reinterpret_cast<const uint32_t*>(this);
  14.   }
  15. };
  16. }
如果你不知道,那我告诉你,这段代码是生成 crc32 的查找表,你觉得应该放在基础代码还是应用代码?
再者,这段代码,是为了讲解C++元编程而写的示例程序,后面有详细的讨论,你说要怎么写才可读性好?要不你来写个让我学习一下?
 楼主| mahui843 发表于 2013-9-7 10:56 | 显示全部楼层
icecut 发表于 2013-9-6 23:32
我说你可读性差.对于应用就是低等代码.
你复制那段代码做基础代码平台代码都没问题,就是不能做应用层.明白? ...

  有争议啊,呵呵。有些东西本来就是仁者见仁智者见智,但乱贴标签却不是技术人员该有的态度。不调查就没有发言权。这是讲元编程的,建议了解一下c++元编程。
  c++最新的标准是C++11,http://zh.wikipedia.org/wiki/C%2B%2B11,这里有详细的介绍。和C相比,C++对技术人员的软件功底要求更高。class好理解,泛型,就不那么容易了。元编程理解起来更困难。
  C++能写出更加优雅的代码,不过,也得看阅读者的功底了,以下代码摘自老师的lestl 的sfr.hpp(先声明:版权属于john lee老师所有),我觉得非常的巧妙,不知道你觉得如何?
  1. /*
  2.   Copyright (c) 2012-2013  John Lee (j.y.lee@yeah.net)
  3.   All rights reserved.

  4.   Redistribution and use in source and binary forms, with or without
  5.   modification, are permitted provided that the following conditions are met:

  6.   * Redistributions of source code must retain the above copyright
  7.   notice, this list of conditions and the following disclaimer.

  8.   * Redistributions in binary form must reproduce the above copyright
  9.   notice, this list of conditions and the following disclaimer in
  10.   the documentation and/or other materials provided with the
  11.   distribution.

  12.   * Neither the name of the copyright holders nor the names of
  13.   contributors may be used to endorse or promote products derived
  14.   from this software without specific prior written permission.

  15.   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16.   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17.   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18.   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19.   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20.   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21.   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22.   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23.   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24.   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN If ADVISED OF THE
  25.   POSSIBILITY OF SUCH DAMAGE.
  26. */

  27. #ifndef __LESTL_SFR_HPP
  28. #define __LESTL_SFR_HPP

  29. #include <cstdint>
  30. #include <attribute.h>

  31. namespace sfr {
  32. template <typename R, uint8_t S, uint8_t W>
  33. struct sfb_t {                      // Special Function Bit
  34.   enum {
  35.     LSB = S,
  36.     WIDTH = W,
  37.     MASK = (((1LL << W) - 1) << S)
  38.   };

  39.   __INLINE sfb_t () {}
  40.   __INLINE uintptr_t
  41.   lsb ()
  42.   { return LSB; }

  43.   __INLINE uintptr_t
  44.   lsb () const
  45.   { return LSB; }

  46.   __INLINE uintptr_t
  47.   width ()
  48.   { return WIDTH; }

  49.   __INLINE uintptr_t
  50.   width () const
  51.   { return WIDTH; }

  52.   __INLINE typename R::type
  53.   mask ()
  54.   { return MASK; }

  55.   __INLINE typename R::type
  56.   mask () const
  57.   { return MASK; }

  58.   __INLINE typename R::type
  59.   read ()
  60.   { return (reinterpret_cast<R*>(this)->val & MASK) >> LSB; }

  61.   __INLINE typename R::type
  62.   read () const
  63.   { return (reinterpret_cast<const R*>(this)->val & MASK) >> LSB; }

  64.   __INLINE operator typename R::type ()
  65.   { return read (); }

  66.   __INLINE operator typename R::type () const
  67.   { return read (); }

  68.   __INLINE R&
  69.   read (typename R::type& v)
  70.   {
  71.     v = read ();
  72.     return *reinterpret_cast<R*>(this);
  73.   }

  74.   __INLINE R&
  75.   read (typename R::type& v) const
  76.   {
  77.     v = read ();
  78.     return *reinterpret_cast<R*>(this);
  79.   }

  80.   __INLINE R&
  81.   write (typename R::type v, bool safe = true)
  82.   {
  83.     register R* p = reinterpret_cast<R*>(this);
  84.     typename R::type _v = v;
  85.     p->changed |= MASK;
  86.     _v <<= LSB;
  87.     if (!__builtin_constant_p (v)
  88.         || ((~_v & MASK) != 0 && (p->zero_mask & MASK) != 0))
  89.       p->val &= ~MASK;
  90.     if (safe)
  91.       _v &= MASK;
  92.     p->val |= _v;
  93.     p->zero_mask |= __builtin_constant_p (v) ? _v : (~0 & MASK);
  94.     return *p;
  95.   }

  96.   __INLINE R&
  97.   operator () (typename R::type v, bool safe = true)
  98.   { return write (v, safe); }

  99.   __INLINE R&
  100.   operator = (typename R::type v)
  101.   { return write (v, true).apply (); }

  102.   template <typename T>
  103.   __INLINE R&
  104.   lambda (T v)
  105.   {
  106.     register R* p = reinterpret_cast<R*>(this);                //强制类型转换
  107.     register typename R::type data = (p->val & MASK) >> LSB;        //读取位域
  108.     register auto res = v (data);
  109.     if (data != res)
  110.       write (res);
  111.     return *p;
  112.   }

  113.   template <typename T>
  114.   __INLINE R&
  115.   lambda (T v) const
  116.   {
  117.     register R* p = reinterpret_cast<R*>(this);
  118.     register typename R::type data = (p->val & MASK) >> LSB;
  119.     register auto res = v (data);
  120.     return *p;
  121.   }

  122.   __INLINE R&
  123.   operator &= (typename R::type v)
  124.   {
  125.     register R* p = reinterpret_cast<R*>(this);
  126.     register typename R::type data = (v << LSB) | ~MASK;
  127.     if (data != typename R::type (~0)) {
  128.       p->changed |= MASK;
  129.       p->val &= data;
  130.     }
  131.     return *p;
  132.   }

  133.   __INLINE R&
  134.   operator ^= (typename R::type v)
  135.   {
  136.     register R* p = reinterpret_cast<R*>(this);
  137.     if (v != 0) {
  138.       p->changed |= MASK;
  139.       p->val ^= (v << LSB) & MASK;
  140.     }
  141.     return *p;
  142.   }

  143.   __INLINE R&
  144.   rol (uint_fast8_t n)
  145.   {
  146.     register R* p = reinterpret_cast<R*>(this);
  147.     p->changed |= MASK;
  148.     register typename R::type v = p->val & MASK;
  149.     p->val &= ~MASK;
  150.     p->val |= ((v << n) | (v >> W - n)) & MASK;
  151.     return *p;
  152.   }

  153.   __INLINE R&
  154.   ror (uint_fast8_t n)
  155.   {
  156.     return rol(W - n);
  157.   }
  158. };

  159. template <typename SFR>
  160. class sfr_t {                       // Special Function Register
  161. public:
  162.   __INLINE constexpr sfr_t () { }
  163.   __INLINE sfr_t (typename SFR::type v) : val{ v } { }
  164.   __INLINE operator typename SFR::type () { return val; }
  165.   __INLINE operator typename SFR::type () const { return val; }
  166.   __INLINE operator typename SFR::type () volatile { return val; }
  167.   __INLINE operator typename SFR::type () const volatile { return val; }

  168.   __INLINE sfr_t <SFR>
  169.   operator = (SFR v)
  170.   {
  171.     val = v.val;
  172.     return *this;
  173.   }

  174.   __INLINE sfr_t <SFR>
  175.   operator = (SFR v) volatile
  176.   {
  177.     val = v.val;
  178.     return *this;
  179.   }

  180.   __INLINE typename SFR::type
  181.   operator = (typename SFR::type v)
  182.   {
  183.     val = v;
  184.     return v;
  185.   }

  186.   __INLINE typename SFR::type
  187.   operator = (typename SFR::type v) volatile
  188.   {
  189.     val = v;
  190.     return v;
  191.   }

  192.   __INLINE SFR operator () () { return SFR (val); }
  193.   __INLINE SFR operator () () const { return SFR (val); }
  194.   __INLINE SFR operator () () volatile { return SFR (val); }
  195.   __INLINE SFR operator () () const volatile { return SFR (val); }
  196.   __INLINE SFR operator () (typename SFR::type v) { return SFR (val, v); }
  197.   __INLINE SFR
  198.   operator () (typename SFR::type v) volatile
  199.   { return SFR (val, v); }

  200.   volatile typename SFR::type val;
  201. };
  202. }

  203. #define __SFR(SFR, TYPE, WRITE)                                     \
  204.   typedef TYPE type;                                                \
  205.   __INLINE SFR (type volatile& r)                                   \
  206.   : ref(r), val(r), changed(0), zero_mask(~0) { }                   \
  207.   __INLINE SFR (type const volatile& r)                             \
  208.   : ref(const_cast<type volatile&>(r)), val(r),                     \
  209.     changed(0), zero_mask(~0) { }                                   \
  210.   __INLINE SFR (type volatile& r, type v)                           \
  211.   : ref(r), val(v), changed(~0),                                    \
  212.     zero_mask(__builtin_constant_p (v) ? v : ~0) { }                \
  213.   __INLINE ~SFR ()                                                  \
  214.   {                                                                 \
  215.     if (changed != 0)                                               \
  216.       apply ();                                                     \
  217.   }                                                                 \
  218.   template <uint8_t S, uint8_t W>                                   \
  219.   __INLINE sfr::sfb_t <SFR, S, W>& field ()                         \
  220.   {                                                                 \
  221.     return *reinterpret_cast<sfr::sfb_t <SFR, S, W>*>(this);        \
  222.   }                                                                 \
  223.   __INLINE SFR& apply ()                                            \
  224.   {                                                                 \
  225.     if ((WRITE & 1) != 0 && (changed & 0xffffff00) == 0)            \
  226.       reinterpret_cast<volatile uint8_t*>(&ref)[0] = val;           \
  227.     else if ((WRITE & 1) != 0 && (changed & 0xffff00ff) == 0)       \
  228.       reinterpret_cast<volatile uint8_t*>(&ref)[1] = val >> 8;      \
  229.     else if ((WRITE & 1) != 0 && (changed & 0xff00ffff) == 0)       \
  230.       reinterpret_cast<volatile uint8_t*>(&ref)[2] = val >> 16;     \
  231.     else if ((WRITE & 1) != 0 && (changed & 0x00ffffff) == 0)       \
  232.       reinterpret_cast<volatile uint8_t*>(&ref)[3] = val >> 24;     \
  233.     else if ((WRITE & 2) != 0 && (changed & 0xffff0000) == 0)       \
  234.       reinterpret_cast<volatile uint16_t*>(&ref)[0] = val;          \
  235.     else if ((WRITE & 2) != 0 && (changed & 0xffff) == 0)           \
  236.       reinterpret_cast<volatile uint16_t*>(&ref)[1] = val >> 16;    \
  237.     else                                                            \
  238.       ref = val;                                                    \
  239.     __asm__ __volatile__("" ::: "memory");                          \
  240.     changed = 0;                                                    \
  241.     return *this;                                                   \
  242.   }                                                                 \
  243.   struct {                                                          \
  244.     type volatile& ref;                                             \
  245.     type val;                                                       \
  246.     type changed;                                                   \
  247.     type zero_mask;                                                 \
  248.   };

  249. #endif  // __LESTL_SFR_HPP

wkei007 发表于 2013-9-7 11:04 | 显示全部楼层
那家伙,居然说代码是老师复制贴粘过来的,真是无语了,是他以自个的水平去揣摩别人的水平,这也太自以为是了,真是井底之蛙,Lee老师别跟他这种人计较!
icecut 发表于 2013-9-7 15:41 | 显示全部楼层
如果c++变成这个样子,我想c++ primer之类的书就可以点火烧了....
icecut 发表于 2013-9-7 16:11 | 显示全部楼层
c++元编程真不是你这么玩的.....

送你四个字:邯郸学步
kseeker 发表于 2013-9-7 16:43 | 显示全部楼层
icecut 发表于 2013-9-7 16:11
c++元编程真不是你这么玩的.....

送你四个字:邯郸学步

这东西诞生之初很多人,甚至包括Bjarne Strou-strup,都认为是“过于聪明”的东西。结果经过多年的演变,诞生出了一批相当优秀的库。至今为止,这玩意还处于半学术研究状态,各种磕磕绊绊自然是少不了。
按你的意思就是,不能做应用层,那就是垃圾。这样想,你永远只是做一些简单的应用层。
在我看来,邯郸学步的人是有未来的,固步自封的人一辈子也就那么回事了。

PS:说实话,C++ primer这书已经有点跟不上时代了。
kseeker 发表于 2013-9-7 17:26 | 显示全部楼层
haiyuan254 发表于 2013-8-29 18:39
给你10000行这种代码让你维护,你试试~~~??就这程序10000行中出1个Bug看能不能弄死维护的人,维护的人 ...

虽然确实很容易被滥用,但元编程是基础库的一个利器。能维护基础库的人本来就很少,Boost里的代码比这热闹多了,那也是垃圾?写那些代码的人哪个都不是省油的灯。关键在于,总有些问题本身就足够复杂,以至于必须用复杂的代码才能表达。

天天写随便抓个人就能维护的代码,意味着你永远没有机会接触只有少数人才能维护的代码,你的水平也就永远停留在大众的水平了。
john_lee 发表于 2013-9-7 17:36 | 显示全部楼层
icecut 发表于 2013-9-7 16:11
c++元编程真不是你这么玩的.....

送你四个字:邯郸学步

你这算回答我的问题了吗?我看是逃避问题、转移话题或者根本就是理屈词穷。
icecut 发表于 2013-9-7 20:51 | 显示全部楼层
本帖最后由 icecut 于 2013-9-7 21:03 编辑
kseeker 发表于 2013-9-7 16:43
这东西诞生之初很多人,甚至包括Bjarne Strou-strup,都认为是“过于聪明”的东西。结果经过多年的演变, ...

说的很对.是优秀的库.这种东西就是做库的.

不能做应用层.在国内就不能创造更大的收益.
这些东西留给老外去用.
icecut 发表于 2013-9-7 20:51 | 显示全部楼层
kseeker 发表于 2013-9-7 17:26
虽然确实很容易被滥用,但元编程是基础库的一个利器。能维护基础库的人本来就很少,Boost里的代码比这热 ...

此种编程技巧能写出优美、简洁的代码; 然而除错是此种编程技巧的弱处: 编译期的错误信息让人不知所云,运行期的除错更是困难。来自:http://zh.wikipedia.org/wiki/C%2B%2B11
icecut 发表于 2013-9-7 20:52 | 显示全部楼层
john_lee 发表于 2013-9-7 17:36
你这算回答我的问题了吗?我看是逃避问题、转移话题或者根本就是理屈词穷。 ...

我回复你的是你给我贴的代码,你然后写个crc,你已经歪曲概念了,我理你是没有意义的.
john_lee 发表于 2013-9-7 22:11 | 显示全部楼层
icecut 发表于 2013-9-7 20:52
我回复你的是你给我贴的代码,你然后写个crc,你已经歪曲概念了,我理你是没有意义的. ...

请直接回答我贴的这段crc代码不算你所谓的“低级代码”?
  • 如果算,那么你来写个“高级代码”让我们瞧一瞧,比一比;记住,功能不能变,也必须是编译时生成crc32查找表。如果你写不出,那么请不要对你不懂的知识妄加评论,否则会成为笑柄的。
  • 如果不算,你所说的“低级代码”就是指楼主位贴子里的代码了,那么拜托你把眼镜擦擦,看清楚一点,我贴的这段crc代码,正是转自楼主位贴子里的。你连帖子都不认真看就妄加评论,还是免不了成为笑柄的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 在线客服 返回列表 返回顶部