29
edits
(We write in C++, not Java) |
(→Classical OOP: Added inline style.) |
||
Line 47: | Line 47: | ||
* No exceptions, so std is hard to use. There is initial work underway to make STL-like containers that mesh well with the rest of the JS engine (see js::Vector, js::HashMap, js::Pool). | * No exceptions, so std is hard to use. There is initial work underway to make STL-like containers that mesh well with the rest of the JS engine (see js::Vector, js::HashMap, js::Pool). | ||
** There are still improvements to be made to the new hash table: double-hash implementation; improve bit-mixing into multiplicative hash if the cycle costs can be supported (measurement is required and we should understand down to the bits what is going on); a js::HashSet or js::HashMap<T,void> specialization such that set-like use of hashtables do not waste any space on values. | ** There are still improvements to be made to the new hash table: double-hash implementation; improve bit-mixing into multiplicative hash if the cycle costs can be supported (measurement is required and we should understand down to the bits what is going on); a js::HashSet or js::HashMap<T,void> specialization such that set-like use of hashtables do not waste any space on values. | ||
=== Initializer lists === | |||
Initializer lists can break in one of two ways. The first may be preferable when constructors take few arguments: | |||
class Ninja : public WeaponWeilder, public Camouflagible, | class Ninja : public WeaponWeilder, public Camouflagible, | ||
public Assassinatable, public ShapeShiftable | public Assassinatable, public ShapeShiftable | ||
Line 66: | Line 69: | ||
Assassinatable(AssassinationDifficulty::HIGHLY_DIFFICULT), | Assassinatable(AssassinationDifficulty::HIGHLY_DIFFICULT), | ||
ShapeShiftable(MPCost(512)) {} | ShapeShiftable(MPCost(512)) {} | ||
} | |||
=== Inline methods === | |||
If the method in question fits on one line and is branch free, do a one liner: | |||
class Eater | |||
{ | |||
void eat(Eaten &other) { other.setConsumed(); } | |||
}; | |||
If it's too long, put the type, declarator including formals (unless they overflow), and left brace all on the first line: | |||
class Eater { | |||
Food *obtainFoodFromEatery(Eatery &eatery) { | |||
if (!eatery.hasFood()) | |||
return NULL; | |||
return eatery.purchaseFood(); | |||
} | |||
}; | |||
For out-of-line inlines (when the definitions are too unwieldy to place in the class definition) use the inline keyword as an indicator that there's an out-of-line inline definition: | |||
class SpaceGoo { | |||
inline BlobbyWrapper *enblob(Entity &other); | |||
}; | |||
inline BlobbyWrapper * | |||
SpaceGoo::enblob(Entity &other) | |||
{ | |||
/* ... */ | |||
} | } | ||
edits