-1

Let’s say that we want to encode recipes or dishes for x days in the form of a string. There can be an arbitrary number of days. Each day, we can have 0–3 of the following: breakfast, lunch, dinner. For each meal, there are multiple possible options ordered by preference (preferred option, fallback option etc.).

For example, let’s say that in our list there are 2 days: Day 1 and Day 2. On Day 1, we have breakfast, lunch and dinner, so 3 meals. On Day 2, there is only 1 meal, lunch. For Day 1, the options, in order of preference are [eggs,muesli] for breakfast, [fish,lentils,pasta] for lunch, and [veggies] for dinner. For Day 2 lunch, there is only 1 option: [burger].

We need to use 3 different separators in order to encode this information as a string. For example, in top-down order, these can be ;, - and ,. In which case, the final string will be like this: eggs,muesli-fish,lentils,pasta-veggies;-burger-.

However, I am looking for an intuitive manner or established convention to pick the symbols. Any existing software documentation or known instance of a multi-level list using separators will work as an answer. I am looking for symbols that will be more easily identifiable as “top-level” and “bottom-level” respectively.

PS: I know that this information can be defined as a nested array but I would like for it to be a kind of configuration which can be input by a user with computer knowledge but who is not familiar with coding.

9

4

Sorry but this

eggs,muesli-fish,lentils,pasta-veggies;-burger-

is a train wreck of noise. It’s far to difficult to see the structure here.

This is data. You need a data language. I’m a fan of JSON.

There can be an arbitrary number of days. Each day, we can have 0–3 of the following: breakfast, lunch, dinner. For each meal, there are multiple possible options ordered by preference (preferred option, fallback option etc.).

For example, let’s say that in our list there are 2 days: Day 1 and Day 2. On Day 1, we have breakfast, lunch and dinner, so 3 meals. On Day 2, there is only 1 meal, lunch. For Day 1, the options, in order of preference are [eggs,muesli] for breakfast, [fish,lentils,pasta] for lunch, and [veggies] for dinner. For Day 2 lunch, there is only 1 option: [burger].

{ 
  "days": [
    { 
      "day": "1",
      "breakfast": ["eggs", "muesli"],
      "lunch": ["fish", "lentils", "pasta"],
      "dinner": ["veggies"]
    },
    {
      "day": "2",
      "lunch": ["burger"]
    }   
  ]
}

You can pack all that into a single string. It is far easier on the eyes than your one liner. Normal humans can produce this if you provide them with an example to work from and quick feedback when they break it.

Or just give them a GUI to build this for them. Should save them from syntax errors and lets you keep them out of trouble.

P.S. If it’s too much trouble to parse heterogeneous data then try this:

{ 
  "days": [
    { 
      "day": "1",
      "breakfast": ["eggs", "muesli"],
      "lunch": ["fish", "lentils", "pasta"],
      "dinner": ["veggies"]
    },
    {
      "day": "2",
      "breakfast": [""],
      "lunch": ["burger"],
      "dinner": [""]
    }   
  ]
}

2

2

If you want to make this accessible to non-programmers, I think it’s best to use something that they’re familiar with: parentheses. You don’t have to document anything new or surprising, just let parentheses do what they do:

((eggs muesli) (fish lentils pasta) (veggies))
(() (burger) ())

If you want to make it even more natural, you could add a few labels, which lets you get rid of the “dummy” empty values as well:

((day 1
      (breakfast eggs muesli)
      (lunch fish lentils pasta)
      (dinner veggies))
 (day 2
      (lunch fish lentils pasta)))

This also has the benefit of being very easy to parse.

3

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *