traits, interface, inheritance

http://stackoverflow.com/questions/9205083/traits-vs-interfaces

Prefer interface to inheritance
use trait for inheritance
If have to use inheritance, use abstract class

is_a => interface

has properties => composition (traits, mixins)

template pattern => abstract class implements interface

inheritance is outdated, should be avoided these days

NS_ASSUME_NONNULL_BEGIN

It’s a convenience macro to save you typing nonnull in your headers. From the Swift blog detailing how new safety features have been incorporated back in Objective-C:

To ease adoption of the new annotations, you can mark certain regions of your Objective-C header files as audited for nullability. Within these regions, any simple pointer type will be assumed to be nonnull.

See Nullability and Objective-C – https://developer.apple.com/swift/blog/?id=25

difference between span and div

http://stackoverflow.com/questions/183532/what-is-the-difference-between-html-tags-div-and-span

  • is a block tag, while is an inline tag.
  • Note that it is illegal to place a block level element within an inline element, so:
Some text that
I want
to mark</span> up</div>

…is illegal.

    • There are lots of block elements (linebreaks before and after) defined in HTML, and lots of inline tags (no linebreaks).
    • But in modern HTML all elements are supposed to have meanings: a <p> is a paragraph, an <li> is a list item, etc., and we’re supposed to use the right tag for the right purpose — not like in the old days when we indented using <blockquote> whether the content was a quote or not.
    • So, what do you do when there is no meaning to the thing you’re trying to do? There’s nomeaning to a 400px-wide column, is there? You just want your column of text to be 400px wide because that suits your design.
    • For this reason, they added two more elements to HTML: the generic, or meaningless elements <div> and <span>, because otherwise, people would go back to abusing the elements which do have meanings.

difference padding/margin

To me the biggest difference between padding and margin is that margins auto-collapse, and padding doesn’t. Consider two elements next to each other each with padding of 1em. This padding is considered to be part of the element, and is always preserved. So you will end up with the content of the first element, followed by the padding of the first element, followed by the padding of the second, followed by the content of the second element. Thus content of the two elements will end up being 2em apart.

Now replace that padding with 1em margin. Margins are considered to be outside of the element, and margins of adjacent items will overlap. So in this example you will end up with the content of the first element followed by 1em of combined margin followed by the content of the second element. So the content of the two elements is only 1em apart.

This can be really useful when you know that you want say 1em of spacing around an element, regardless of what element it is next to.

The other two big differences is that padding is included in the click region and background color/image, but not the margin.

By default I use margin everywhere, except when I have a border or background and want to increase the space inside that visible box.

http://stackoverflow.com/questions/2189452/when-to-use-margin-vs-padding-in-css

new static and new self

http://stackoverflow.com/questions/5197300/new-self-vs-new-static

What is the difference between new self and new static?

self refers to the same class in which the new keyword is actually written.

static, in PHP 5.3’s late static bindings, refers to whatever class in the hierarchy you called the method on.

In the following example, B inherits both methods from A. The self invocation is bound to Abecause it’s defined in A‘s implementation of the first method, whereas static is bound to the called class (also see get_called_class()).

class A {
    public static function get_self() {
        return new self();
    }

    public static function get_static() {
        return new static();
    }
}

class B extends A {}

echo get_class(B::get_self());  // A
echo get_class(B::get_static()); // B
echo get_class(A::get_static()); // A