nim-wiki/Unofficial-FAQ.md

77 lines
5.6 KiB
Markdown
Raw Normal View History

2015-02-03 07:59:41 +00:00
If you are looking for the official FAQ then you can find it [here](http://nim-lang.org/question.html)
2013-04-05 16:23:33 +00:00
2013-12-07 15:42:55 +00:00
# How can I help?
2010-09-14 10:11:18 +00:00
2011-11-09 00:46:57 +00:00
For beginners I suggest to implement missing parts of the standard library or some other more specialized libraries:
2010-09-14 10:11:18 +00:00
* locale support
* a lean GUI library
2011-11-09 00:46:57 +00:00
* libraries for scientific computing
2011-12-31 06:48:02 +00:00
* libraries that deal with multi-media
2011-11-09 00:46:57 +00:00
* etc.
2010-09-14 10:11:18 +00:00
2015-02-03 07:59:41 +00:00
# How does the Nim compiler's versioning scheme work?
Versions with a trailing odd number are considered to be "in-development", these are unstable "bleeding-edge" versions of the compiler which you can get from Github. Versions with an even number are releases. E.g. 0.9.0 is a release version, 0.9.1 is an in-development version.
2015-12-14 12:35:07 +00:00
# Why is it case/underscore insensitive?
2010-09-14 10:11:18 +00:00
2011-12-30 18:59:04 +00:00
* Identifiers which only differ in case are bad style. If the programming language treats them the same the programmer needs to come up with different names for different things.
2010-09-14 10:11:18 +00:00
* Case insensitivity is widely considered to be more user friendly. This holds for file systems, configuration files, and programming languages.
2015-12-14 12:35:07 +00:00
* Many programming languages are case insensitive: Lisp, Basic, Pascal, Ada, Eiffel, Fortran. Since software for aircrafts and power plants has been written in Ada, it seems reasonable to assume that case insensitivity will not destroy civilization.
* Note that most people confuse case sensitivity with case consistency (which is indeed good style). However, case consistency is easier to achieve with case insensitivity and a properly configured IDE than with case sensitivity.
2015-12-14 12:35:07 +00:00
* It prevents bugs: in large applications in other languages it's not uncommon to see bugs introduced by an incorrect completion, e.g. updatePlayerstatus / updatePlayerStatus / update_player_status. With case/underscore insensitivity you know in advance that there can be only one "updateplayerstatus" in your code (and write it in a consistent manner, e.g. always update_player_status)
2013-12-07 15:42:55 +00:00
# Where can I find code examples?
2015-06-04 14:44:13 +00:00
You can find examples in the [examples/](https://github.com/Araq/Nim/tree/master/examples) directory. There are also many other examples available on [Rosetta Code](http://rosettacode.org/wiki/Nim) and [Nim by Example](http://nim-by-example.github.io)
2013-12-07 15:41:42 +00:00
2013-12-07 15:42:55 +00:00
# Why are unsigned types discouraged?
2013-12-07 15:41:42 +00:00
2014-01-04 16:16:08 +00:00
* http://critical.eschertech.com/2010/04/07/danger-unsigned-types-used-here/
2015-02-03 07:59:41 +00:00
* http://forum.nim-lang.org/t/313#1631
2015-04-15 22:12:10 +00:00
* http://forum.nim-lang.org/t/892#5303
2014-03-02 13:39:29 +00:00
# Why are tabs forbidden?
2015-02-03 07:59:41 +00:00
Tabs are treated differently by different tools and editors. Because indentation is so important in Nim it is much simpler to outright forbid tabs in source code than to risk the mixing of tabs and spaces. Guido van Rossum of Python himself has said that if he were to design Python again he would forbid tabs.
2014-03-02 13:39:29 +00:00
2015-02-03 07:59:41 +00:00
Nim is certainly not unique in forbidding tabs. [YAML](http://www.yaml.org/faq.html) does the same.
2014-06-09 20:47:41 +00:00
2016-03-07 21:36:19 +00:00
However, if you insist on using tabs in your code, putting this at the top of your code will change the tabs into spaces when compiling `#? replace(sub = "\t", by = " ")`
2015-06-04 14:53:45 +00:00
2015-02-03 07:59:41 +00:00
# I get an error trying to compile Nim on Windows.
2014-06-09 20:47:41 +00:00
If this error looks something like the following:
```
c_code/nimbase.h:382:13: error: size of array 'assert_numbits' is negative
typedef int assert_numbits[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof
(NI)*8 ? 1 : -1];
```
Then you are likely trying to compile the C sources with a 64bit version of GCC. If you are trying to do this then you should note that there is a ``build64.bat`` file which you should execute instead of the ``build.bat`` file.
2015-06-05 14:54:02 +00:00
If the error does not resemble the above then the problem is likely with the C sources. Ask for help on IRC or submit an issue on github!
2015-06-05 18:42:35 +00:00
# Is Nim unsafe?
2015-06-05 14:54:02 +00:00
Usually this comes from Nim's ability to dereference null pointers and it's deal with compiling to C IR. Nim strives to generate C IR that won't cause undefined behavior as easy as how it can be caused by hand written C code. But when there is hand-written Nim code that contains errors like dereferencing a null pointer, there are ways to avoid this:
- `not nil` Annotation:
- You can use this annotation on any nilable type in your code and the compiler statically checks at compile time that your code can't possibly have a null pointer for that var
- Compiler flags:
2015-06-06 06:08:08 +00:00
- you can pass flags like `-fsanitize`, or `-fsanitize=null` for nil checks, which provide minimal overhead.
2015-06-05 14:54:02 +00:00
- In the near future, `-nilChecks:On|Off` will be available for explicit nil checking and instead of Segmentation Faults, when a null pointer is dereferenced, it will be a NilError Exception
- Also in the near future, `-d:safety` will be available to use along with `-d:release` for performance _and_ safety (see: [#2809](https://github.com/Araq/Nim/issues/2809))
- `-d:release` config
- by default, `-d:release` turns safety checks off, but if you configure `config/nim.cfg`, you can allow the checks you want enabled when invoking `-d:release`
- Thread Safety
- shared memory via lockable heaps is a feature Nim seems will implement soon.
You should also keep in mind these 5 points:
1. It's not a problem in practice in the real world, where people have access to a very good debug mode that catches all sorts of things at compile-time and at run-time.
2. It's not a problem with the right C compiler configurations.
3. It's not hard to "fix" this issue anyway. Where "fixing" means "pretending Nim created Ansi C code in the first place" (which it doesn't).
4. It's furthermore entirely deterministic in debug mode. It's nothing like a data race which you can never effectively test against.
5. Nim already encourages you to give the type a name and then 'not nil' can be part of the type definition easily