Search Results

Search found 6 results on 1 pages for 'pubby'.

Page 1/1 | 1 

  • Explanation on how "Tell, Don't Ask" is considered good OO

    - by Pubby
    This blogpost was posted on Hacker News with several upvotes. Coming from C++, most of these examples seem to go against what I've been taught. Such as example #2: Bad: def check_for_overheating(system_monitor) if system_monitor.temperature > 100 system_monitor.sound_alarms end end versus good: system_monitor.check_for_overheating class SystemMonitor def check_for_overheating if temperature > 100 sound_alarms end end end The advice in C++ is that you should prefer free functions instead of member functions as they increase encapsulation. Both of these are identical semantically, so why prefer the choice that has access to more state? Example 4: Bad: def street_name(user) if user.address user.address.street_name else 'No street name on file' end end versus good: def street_name(user) user.address.street_name end class User def address @address || NullAddress.new end end class NullAddress def street_name 'No street name on file' end end Why is it the responsibility of User to format an unrelated error string? What if I want to do something besides print 'No street name on file' if it has no street? What if the street is named the same thing? Could someone enlighten me on the "Tell, Don't Ask" advantages and rationale? I am not looking for which is better, but instead trying to understand the author's viewpoint.

    Read the article

  • What are the differences between Bigloo and ECL?

    - by Pubby
    I've been looking to embed Lisp in some C++ code. Two options I'm interested in is Bigloo Scheme and ECL. Reading through the docs they seem to support a very similar feature set. Obviously Bigloo is Scheme and ECL is CLisp, but what other differences do they have? In particular I'm interested in the following criteria: Ease of embedding (for C++, not just C) Performance Style of coding Size Tail call support I'm targeting this question towards someone who has used both.

    Read the article

  • What are the differences between Bigloo and ECL from an embedding standpoint? [migrated]

    - by Pubby
    I've been looking to embed Lisp in some C++ code. Two options I'm interested in is Bigloo Scheme and ECL (Common Lisp). Reading through the docs they seem to support a very similar feature set. Obviously Bigloo is Scheme and ECL is CLisp, but what other differences do they have? In particular I'm interested in the following criteria: Ease of embedding (for C++, not just C). I don't want to write a bunch of boilerplate. Performance. Bigloo is performance based and has many compiler optimization options, although I can't find anything comparable for ECL. Style of coding. This one is more for Bigloo - is it more functional than ECL? I'm targeting this question towards someone who has used both.

    Read the article

  • How can I configure GIMP 2.8 to be a single window in XMonad?

    - by Pubby
    I'm trying to get GIMP to display as a single window in XMonad. Currently, it's floating strangely in front of every other display and I can't use it. I have tried reading this: http://www.haskell.org/haskellwiki/Xmonad/General_xmonad.hs_config_tips#Gimp But it seems this is for versions of GIMP before 2.8 when there wasn't the option to have GIMP use only 1 window. Because of this, it's an XMonad problem, not a GIMP one. How can I do this?

    Read the article

  • User defined literal arguments are not constexpr?

    - by Pubby
    I'm testing out user defined literals. I want to make _fac return the factorial of the number. Having it call a constexpr function works, however it doesn't let me do it with templates as the compiler complains that the arguments are not and cannot be constexpr. I'm confused by this - aren't literals constant expressions? The 5 in 5_fac is always a literal that can be evaluated during compile time, so why can't I use it as such? First method: constexpr int factorial_function(int x) { return (x > 0) ? x * factorial_function(x - 1) : 1; } constexpr int operator "" _fac(unsigned long long x) { return factorial_function(x); // this works } Second method: template <int N> struct factorial { static const unsigned int value = N * factorial<N - 1>::value; }; template <> struct factorial<0> { static const unsigned int value = 1; }; constexpr int operator "" _fac(unsigned long long x) { return factorial_template<x>::value; // doesn't work - x is not a constexpr }

    Read the article

  • How can variadic char template arguments from user defined literals be converted back into numeric types?

    - by Pubby
    This question is being asked because of this one. C++11 allows you to define literals like this for numeric literals: template<char...> OutputType operator "" _suffix(); Which means that 503_suffix would become <'5','0','3'> This is nice, although it isn't very useful in the form it's in. How can I transform this back into a numeric type? This would turn <'5','0','3'> into a constexpr 503. Additionally, it must also work on floating point literals. <'5','.','3> would turn into int 5 or float 5.3 A partial solution was found in the previous question, but it doesn't work on non-integers: template <typename t> constexpr t pow(t base, int exp) { return (exp > 0) ? base * pow(base, exp-1) : 1; }; template <char...> struct literal; template <> struct literal<> { static const unsigned int to_int = 0; }; template <char c, char ...cv> struct literal<c, cv...> { static const unsigned int to_int = (c - '0') * pow(10, sizeof...(cv)) + literal<cv...>::to_int; }; // use: literal<...>::to_int // literal<'1','.','5'>::to_int doesn't work // literal<'1','.','5'>::to_float not implemented

    Read the article

1