Pitfalls to avoid
Factor handbook » Factor cookbook

Prev:Factor philosophy
Next:Next steps


Factor is a very clean and consistent language. However, it has some limitations and leaky abstractions you should keep in mind, as well as behaviors which differ from other languages you may be used to.
Factor only makes use of one native thread, and Factor threads are scheduled co-operatively. C library calls block the entire VM.
Factor does not hide anything from the programmer, all internals are exposed. It is your responsibility to avoid writing fragile code which depends too much on implementation detail.
If a literal object appears in a word definition, the object itself is pushed on the stack when the word executes, not a copy. If you intend to mutate this object, you must clone it first. See Literals.
Also, dup and related shuffle words don't copy entire objects or arrays; they only duplicate the reference to them. If you want to guard an object against mutation, use clone.
For a discussion of potential issues surrounding the f object, see Booleans.
Factor's object system is quite flexible. Careless usage of union, mixin and predicate classes can lead to similar problems to those caused by "multiple inheritance" in other languages. In particular, it is possible to have two classes such that they have a non-empty intersection and yet neither is a subclass of the other. If a generic word defines methods on two such classes, various disambiguation rules are applied to ensure method dispatch remains deterministic, however they may not be what you expect. See Method precedence for details.
If run-file throws a stack depth assertion, it means that the top-level form in the file left behind values on the stack. The stack depth is compared before and after loading a source file, since this type of situation is almost always an error. If you have a legitimate need to load a source file which returns data in some manner, define a word in the source file which produces this data on the stack and call the word after loading the file.