Skip to content

Instantly share code, notes, and snippets.

Nicolas Payette nicolaspayette

Block or report user

Report or block nicolaspayette

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
nicolaspayette /
Created Aug 4, 2016
Why you should probably avoid global variables in NetLogo

In my experience, a disproportionate amount of bugs in NetLogo models are caused by the mismanagement of global variables.

Here are a few reasons why I think that is the case, in (roughly) decreasing order of importance:

  • Code is not just a way of getting the computer to do what you want it to do—it is a way of conveying meaning to the reader of your code. When you declare a global variable, the meaning you convey is: “Hey! This thing is important throughout the whole program. You should always be paying attention to it.”

    Sometimes it’s justified , but very often, it is not. An unjustified global is not only failing to convey the right message: it’s actively misleading.

    When I approach a model’s code for the first time, the first thing I do is look at the declarations on top: what breeds do we have, what agent variables do we have, and what global variables do we have? That gives me the “big picture” and tells me what I should be paying attention to when trying to understand what the code is do

View max-one-of-list
to-report max-one-of-list [ the-list reporter-task ]
let results map reporter-task the-list
let highest max results
let indices n-values length the-list [ ? ]
let indices-with-highest filter [ item ? results = highest ] indices
report item (one-of indices-with-highest) the-list
View gist:f604060baa1d534a8dd3
[info] Running org.nlogo.models.CodeComplexity
[info] Exponential Growth, 0.002638522427440633
[info] Wolf Sheep Predation (System Dynamics), 0.002638522427440633
[info] Logistic Growth, 0.002638522427440633
[info] Life Simple, 0.03663177758433025
[info] Voting, 0.040667324754022724
[info] Mousetraps, 0.05816919018768013
[info] 3D Surface, 0.06135069069780657
[info] Urban Suite - Structure from Randomness 2, 0.06436046177967228
[info] GenDrift P global, 0.06930239379042409
nicolaspayette / FizzBuzzUsingEither.scala
Last active Aug 29, 2015
Scala FizzBuzz using Either
View FizzBuzzUsingEither.scala
object FizzBuzz extends App {
def check[A](properties: (A Boolean, String)*)(x: A): String =
.foldLeft(Left(x.toString): Either[String, String]) {
case (acc, (p, s))
if (p(x)) Right(acc.fold(_ s, _ + s))
else acc
nicolaspayette / gist:1260949
Created Oct 4, 2011
Genetic Algorithm for choosing players in a hockey pool...
View gist:1260949
object Pool {
abstract sealed class Pos
case object Forwards extends Pos
case object Defensemen extends Pos
case object Goaltenders extends Pos
val posCounts: Map[Pos, Int] = Map(
Forwards -> 9,
Defensemen -> 6,
Goaltenders -> 2)
You can’t perform that action at this time.