Skip to content

Behaviour to know

Mamba hides a lot of detail, and some of that detail shows up as behaviour you would not guess from reading the code. This page lists it. Each item has caused a real bug.

Missing values are handled quietly

Mamba is null-tolerant. Instead of failing when a value is missing, it reads a default:

  • Reading a member of a missing object gives a missing value, not an error.
  • A missing number counts as 0 in arithmetic.
  • A missing string counts as "".
  • A missing boolean counts as false in a condition.

A page does not crash on a missing reference. It quietly shows 0 or nothing. That is friendly for users, and it can hide a mistake: a required value that was never set looks the same as a value of zero. Check required data explicitly, and report the problem with a BusinessException.

A declared object is not null

Domain.Customer customer;     // a new, empty Customer
if customer == null { }       // never true

A variable of a business object type that you declare without a value gets a new, empty object. A comparison with null is then always false. To ask whether a record exists, use Find(...).First(), which returns null when nothing matches, and check the result:

var customer = Domain.Customer.Find(c => c.Email == email).First();
if customer == null { /* not found */ }

Collections that you declare start empty. Arrays start as null.

Time is UTC

DateTime.Now() returns the current time in UTC, and DateTime.Create(...) builds a UTC date. Convert explicitly when you show local time to a user, and when you compare calendar days across time zones.

Where code runs

Most Mamba runs on the server. Some expressions run in the browser, because they update as the user types:

  • calculated expressions on forms
  • conditional formatting
  • the display name of a menu item

These are compiled into the client. They can use the data of the form, but they cannot call your Domain helpers or query the database. If the build says Success and the screen does not update, check whether such an expression calls something that only exists on the server. Pass the data in through the form's model instead, set in the form's controller.

HTML containers and braces

The raw HTML of an HTML container is read by the Angular client, which treats { and } specially. Write them as { and }, or the page will fail to compile.

Finding one record

GetByKey throws when the key does not exist. When a key can come from outside, such as a URL, use Find(x => x.Id == id).First() and check for null.

Queries run in the database

The lambda you give to Find becomes a database query, so it must be simple. Call your own operations on the result, in memory. See Working with data.

Saving

  • A new object is not stored until you call Save().
  • Saving a parent saves its children when the children belong to it (a composition). Other links need their own Save().
  • Delete() follows the delete rules of the association. A restricted association blocks the delete.

Check loop limits

A loop that runs for (int i = 0; i < 23; i++) stops at 22. When you loop over hours of the day, you need i < 24.

Validation proves structure, not meaning

Validation checks that names, types and relationships are correct. It cannot know that a discount should be at most 50 percent. Write unit tests for your rules.

Things that pass validation and fail the build

A few constructs are accepted by Validation but fail when the generated code is compiled. When an application keeps showing Setting up your private environment after a build, open the build output or the backend log. A compile error there points at the model operation that caused it. See The engine.