nim-lang/website

Better Examples for index page code example.

amaank404 opened this issue · 3 comments

The index page of your website was the first page I visited when I ventured out to pick up a new language. Apparently, the code example that I saw at first was so confusing, I immediatly moved over to other options. This is how I would like to point out the issues with the provided example from an eye of a non-nim dev:

import std/strformat                                           # >>>Pretty Standard

type                                                           # >>>Confused the heck out of me. I mean, why is there a newline and what is Person=object really mean here.
  Person = object
    name: string
    age: Natural # Ensures the age is positive

let people = [                                                 # >>>Pretty Standard
  Person(name: "John", age: 45),
  Person(name: "Kate", age: 30)
]

for person in people:                                          # Also Standard
  # Type-safe string interpolation,
  # evaluated at compile time.
  echo(fmt"{person.name} is {person.age} years old")


# Thanks to Nim's 'iterator' and 'yield' constructs,
# iterators are as easy to write as ordinary
# functions. They are compiled to inline loops.
iterator oddNumbers[Idx, T](a: array[Idx, T]): T =            # >>> Extreme confusion, How are functions defined again? Well, you need to tell me how to define functions before iterators. This syntax came out of nowhere.
  for x in a:
    if x mod 2 == 1:
      yield x

for odd in oddNumbers([3, 6, 9, 12, 15, 18]):                 # Standard
  echo odd


# Use Nim's macro system to transform a dense
# data-centric description of x86 instructions
# into lookup tables that are used by
# assemblers and JITs.
import macros, strutils                                      # Standard

macro toLookupTable(data: static[string]): untyped =         # Macros were never meant to be easy, were they? So nvm this section.
  result = newTree(nnkBracket)
  for w in data.split(';'):
    result.add newLit(w)

const                                                        # A little help about indentation here would have helped a lot.
  data = "mov;btc;cli;xor"
  opcodes = toLookupTable(data)

for o in opcodes:                                            # No brackets for functions? I mean, you gotta explain this somewhere.
  echo o

And that is all I have to say for this example. As a sidenote, I believe we are lacking behind in terms of website design, It feels very static. No animations? I mean you must have heard of these subtle animations that fade in an object on intersection with viewport. Nvm, my main issue is with the code example.

Thank you. (My english is not good, I am not a native speaker, please correct me where possible)

Araq commented

The examples are supposed to show somewhat unique and interesting code, they are for experienced programmers. There is nothing interesting about "hello world" and function calls, every other language can do that too. If you don't immediately understand the code snippets, maybe they still work as whetting your appetite to learn more about Nim. Maybe they put you off, that's life, it's impossible to please everybody.

You are wise. But would it be possible to have somewhat pleasing example, mostly to new users? Don't get me wrong, I love Nim, it is the fastest and easiest language I know of.

By new users, I mean to say that those without nim experience but enough experience to be called proper programmers (not begginners or students).

concluding: Since Nim has comparitivly unique and different looking approach, Should we have some sort of example that is easy to understand? Could we have more comments in the example?

Well, you are right afterall. I ventured into Nim because of my curiosity afterall. :)