3

NOTE: I had originally asked this question on https://softwareengineering.stackexchange.com/, but I had been asked to move it here.


I am currently developing a Simplifier for a Calculator. This allows the users to put sections of the input within brackets just like we do in a maths problem. But my question is should I (or it) allow the other kinds of brackets (or braces) as well? For example, should I allow

this : 2 [ 3 +{ 4 ^ 5 - ( 39 * 7 + 0 ) + 3 } ]

or this : 2 ( 3 +( 4 ^ 5 - ( 39 * 7 + 0 ) + 3 ) )


My reason for asking:

The pros of the 1st approach (and cons of the 2nd) are:

  • It makes it easier to read the problem. The second approach doesn't look so elegant (or does it?).
  • Since we've started practicing Simplification, we've been taught the use of distinct brackets.

The pros of the 2nd approach (and cons of the 1st) are:

  • It might make processing more difficult (detecting syntax errors, mismatched braces).
  • After preliminary maths, when we're introduced to programming where only () are allowed.

Should I optimize my program for a Programmer's approach or a Mathematician's approach?

  • 2
    "Should I optimize my program for a Programmer's approach or a Mathematician's approach?" Optimise it for whoever is going to be the user of your calculator... – zigojacko Mar 19 '14 at 8:58
  • @zigojacko actually... both :-) – Hungry Blue Dev Mar 19 '14 at 8:59
  • As a PSA - if you have a question on one site that you feel should've been asked on another site then the best process there is to flag the original for moderator attention and they can migrate it across, rather than cross-posting it. That keeps all the answers on one post rather than spread across multiple sites. – JonW Mar 19 '14 at 9:19
  • 1
    Neither approach should be difficult to process/implement. The most user friendly approach should probably include matching brace highlighting. – Danny Varod Mar 23 '14 at 13:21
5

(Already gave this answer in the chatroom, but here goes)

I think using different brackets that have the same function is confusing since people are taught to only use the ")" bracket.

I think you should use a different method of making corresponding brackets visible.

Lots of code editors highlight or underline the opening and closing brackets when one of the two is selected.

You could also use give corresponding brackets a different color, not only after selection, but standard. It might turn the input into a rainbow, but I think it will be quite more "readable".

  • This is the best so far... I'll wait for other views. (Thanks!) – Hungry Blue Dev Mar 19 '14 at 9:05
4

You can try coloring the related parentheses and highlighting the active ones, just like MS Excel does it.

MS Excel coloring

  • Also, outer brackets can be slightly larger than inner. That's how they're rendered in LaTeX, and often also written by hand. – Trang Oul May 6 '16 at 6:37
2

I would recommend the second approach

2 ( 3 +( 4 ^ 5 - ( 39 * 7 + 0 ) + 3 ) )

1) The general population are not programmers and are not used to seeing { } , in schools we are taught ( ) for mathematical equations

  • Well, in my school, I had been taught to use { in my Maths class (and so have my friends and others!) – Hungry Blue Dev Mar 19 '14 at 9:08
  • 2
    Apparently box brackets [ are used for more difficult grouping and curly brackets { are used for sets. So the latter are not used in these type of notations. – Paul van den Dool Mar 19 '14 at 9:57
  • 1
    Also, [] is used for absolute value and in matrix notation... – Austin French Mar 19 '14 at 15:31
  • 1
    @Austin: [x] as absolute value? Didn't you mean |x|? – Trang Oul May 5 '16 at 13:29
  • Good call, (two years later, @TrangOul ) ;) |x| should be absolute value, where [x] will / does have it's own uses (like matrix / max integer?) – Austin French May 5 '16 at 16:25
2

You really asked two questions here, but nevertheless:

On question #1

Should a 'Calculator' support '{' (curly braces) and '[' (box braces)?

Yes, Accessibility is the keyword here. Not as in "physically impaired" but as in "learned behaviour". Some people will just want to use curly or box braces, because that's how they're rolling on paper and you want the barrier between real life application and virtual application to be as low as possible.

Users should be able to use interaction patterns they already know (anything else is going to be frustrating), so supporting those braces is giving them more convenience and isn't going to hurt anyone who wants to use parentheses exclusively.

On question #2

Should I optimize my program for a Programmer's approach or a Mathematician's approach?

Why not both? You probably know matching brace highlighting from many IDEs and Editors, where two matching braces are highlighted if your cursor is on one of them. Another approach is colour-coding, used in Excel as pointed out by stereoactivo.

Both these approaches are applicable and ease readability for both the Programmers and the Mathematicians writing style. This is where your virtual application can top the one in real life, which is always nice.

Other than that, what do you really mean by optimisation? What were your ideas on optimising for one of the two?

On "question" #2.5

[multiple braces] might make processing more difficult (detecting syntax errors, mismatched braces).

That is certainly correct, but you care mostly about the user, not the programmer. (And let's be honest, mismatching braces aren't a though thing to implement. If we're talking about a physical calculator, you should of course consider building cost but I assume your question was meant to consider applications only.)

Also, that is exactly what these additional braces are used for in the first place: detecting errors of thoughts. If you write mismatched braces, you certainly got something twisted in your mind. Giving the user a hint upon that is certainly going to improve their experience.

School of thought to follow / TL:DR;

In general, allowing users to adapt known patterns is something to be desired in every application and known to be the key factor of intuitiveness. Therefore, supporting both writing styles, including checking for matching braces, seems to be the best solution.

2

For your specific case, you should only use round brackets ().

Mathematically speaking, different brackets have different meanings. Let's take the term f(2+n) as an example; it can have one of two meanings:

  1. It's a multiplication: f multiplied by (2 + n).
  2. It's a function: f(x): x2 -> Replace x with (2 + n).

If you exchange the round brackets for square ones f[2+n]:

  1. It's a multiplication: f multiplied by the absolute value of (2 + n).
  2. It's an array: Get element at position (2 + n) of array f.

There are other ways to improve usability:

  • Give each bracket pair a distinct color, as mentioned by @stereoactivo
  • Highlight the pair, when the cursor or mouse is resting on an opening or closing bracket1
  • Join each pair by drawing an arc above or below each group. The arcs obviously can't intersect.
  • Highlight the innermost group, when cursor goes in between a pair, or mouse hovers over the group.

I have written a fiddle to show the 4 different ways described above.


1: Highlighting both brackets makes it easier for the user to identify the pair, especially when the cursor rests in between two closing, or two opening brackets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.