Expression parser broken for Python objects

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
chrisb
Veteran
Posts: 53928
Joined: Tue Mar 17, 2015 9:14 am

Re: Expression parser broken for Python objects

Post by chrisb »

I expect the same, but from what I learned here, it is not possible.
It is correct and sensible to keep the unit shown, when a value is entered via GUI. And we expect the same from an expression.

Alas, the expression doesn't know the GUI and doesn't know how the value was before.

If we had before a value given in V an we enter a unitless value, then we expect the result in V.
If we had before a value given in mV an we enter a unitless value, then we expect the result in mV.

We cannot have both of these with expressions. If in doubt, enter the unit in the expression and everything is ok.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Expression parser broken for Python objects

Post by wmayer »

I asked about forcing them to enter "3V" but this would not only be a keystroke more but is error-prone. One might hit the wrong key, so e.g. enter "3C", then get an error and annoyed since one loose time to read the error message.
This example doesn't sound very convincing and looks like too devised to me. If you hit the wrong key your input is really invalid and you cannot expect the parser to fix this automatically. That's why the result label shows the red error text "Unit mismatch between result and required unit" and the OK button is disabled in order to avoid to accept the wrong input.

Because the error is shown immediately I don't see how you would lose time. IMO, it's even a time saver because what would happen if the expression parser were too permissive and accepted some invalid input? Sooner or later you will run into a situation where the invalid expression will produce total nonsense as the result of an operation or will raise weird error message without having a clue where it comes from. Then it may become really time consuming to find the root of the problem.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Expression parser broken for Python objects

Post by uwestoehr »

wmayer wrote: Thu Sep 08, 2022 12:43 pm
I asked about forcing them to enter "3V" but this would not only be a keystroke more but is error-prone. One might hit the wrong key, so e.g. enter "3C", then get an error and annoyed since one loose time to read the error message.
This example doesn't sound very convincing and looks like too devised to me. If you hit the wrong key your input is really invalid and you cannot expect the parser to fix this automatically. That's why the result label shows the red error text "Unit mismatch between result and required unit" and the OK button is disabled in order to avoid to accept the wrong input.
You know how it is in stressy daily work. In my example entering accidentally "3C" "steals time":
- you get an error message that must be read
. you need to understand what is written there
- you must reenter the value

From the user's perspective, the value is a voltage, why is there a need to input the unit when it is obviously "V"?
When the unit is always volt, why is there an accidental input of "3C" possible at all?
I know that this is difficult to answer and we have our technical reasons but as user who has to work with a dozen programs every day, I understand these questions.

---------------------------

Important is in my opinion, if we can improve the situation and how? I feel meanwhile guilty to changed for FEM some inputs to be expressions when people obviously don't want to be bothered with that when it is clear what the unit. is. So i can change the expressions to a FloatSpinEdit. Should i?
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Expression parser broken for Python objects

Post by GeneFC »

uwestoehr wrote: Sun Sep 11, 2022 1:56 pm From the user's perspective, the value is a voltage, why is there a need to input the unit when it is obviously "V"?
As a user of Imperial Decimal units I learned a long time ago to check *every* input for correct units. It quickly becomes completely transparent and automatic. No time wasted at all.

Gene
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Expression parser broken for Python objects

Post by wmayer »

- you get an error message that must be read
It's a single line and it shouldn't take more than a second to read it. The error message is very clear about what the problem is.
you need to understand what is written there
If it happens the very first time it may take a while to get it. But if it happens more often you immediately see the problem.
- you must reenter the value
Since the dialog disables the OK button the incorrect input won't be accepted. You don't have to enter again the whole expression but fix the wrong part.
When the unit is always volt, why is there an accidental input of "3C" possible at all?
How does the expression parser know that your input is complete? For more complex expressions it can happen that you have a quantity in Joule and another quantity in Coulomb: 12J / 3C
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Expression parser broken for Python objects

Post by uwestoehr »

wmayer wrote: Mon Sep 12, 2022 10:00 am How does the expression parser know that your input is complete? For more complex expressions it can happen that you have a quantity in Joule and another quantity in Coulomb: 12J / 3C
Sure, complex expressions with mixed units should be possible and are useful. The two questions I raised are examples of what I got as feedback. As I stated, we have good reasons for the current feature.

My proposal was that when the user did not enter any unit, if we can then automatically add the default unit. Can this somehow be done?

(I want to improve the situation since I understand the daily stress well and learned that average users don't care much about the specialties of a certain program. For example I recently wrote a laboratory equipment control software for a customer and the users all have a university degree. Nevertheless they don't read docs, nor even the messages I issue in the program. They just click OK and then call me why it is not working as they expect, despite the message dialog they confirmed with pressing OK describes exactly what will happen when clicking OK :( . Sometimes one has to live with this. However, since every call to me costs them money, it became better 8-).)
Post Reply