Boolean Questions

0 views
Skip to first unread message

Leto Corrales

unread,
Aug 3, 2024, 5:58:37 PM8/3/24
to idanoron

Boolean Algebra questions and answers will assist students in quickly understanding the basics of the concept. These questions can be used by students to acquire a quick overview of the topics and to try answering them in order to improve their knowledge. Learn the complete solutions for each question to check your answers. To understand more about Boolean Algebra, click here.

The algebra of logic is a Boolean algebra. It works with variables with two different values, such as 0 (False) and 1 (True), as well as logically significant operations. George Boole invented the first way of manipulating symbolic logic, which later became known as Boolean Algebra. Because of its vast applications in switching theory, developing basic electronic circuits, and designing digital computers, Boolean algebra has become a vital tool in computer science.

The boolean is a system control (from the system palette) and as such inherits these cosmetics from the OS. It will look different depending on your OS version and windows theme setting. You have very little control over this.

You can create a key down event for the control. Have it contain a case structure. Create a case for the delete key and in it write a zero to a local variable of the control. Seems to work as your description requires. (see attached, the zero will appear once the control loses focus).

Regarding the numeric control, this is the same idea that I had also had but wanted to know if it was possible to do without any extra code so just with the data entry settings to coerce to zero. I guess not but its not a lot of code to implement the functionality in fairness.

In your case the buttton is associated with the key, thus it has focus when the VI starts running. You can associate the key to a different boolean button from the system palette and you will see the same behavior.

The only confusion I'm getting is, this doesn't return boolean like I originally anticipated by putting the question mark on the end of the method name. I was under the impression that when evaluating an object as conditional it returns true if not nil.

Adding a ? to the end of a method name does not in any way change the return value of the method, but instead only indicates that it is a predicate method. That is, that the method's return value should be treated as a boolean, but does not need to be strictly boolean (i.e. true or false).

Many of the other answers state that it should return a value that is truthy or falsy. This is rather redundant, since everything can be either truthy or falsy, and since all methods in Ruby return something (unless they raise an exception), the return value is always truthy or falsy.

It should a 'truthy' or 'falsy' value, that can be used safely in predicates, but does not have to return literal true or false. There are even methods like this, like File.size?, in the standard library.

Avoid prefixing predicate methods with theauxiliary verbs such as is, does, or can. These words are redundantand inconsistent with the style of boolean methods in the Ruby corelibrary, such as empty? and include?.

Then, what Javascript will do is type coerce true to match the type of someVar and then compare the two variables. There are lots of situations where this is likely not what one would intend. Because of this, in most cases you want to avoid == because there's a fairly long set of rules on how Javascript will type coerce two things to be the same type and unless you understand all those rules and can anticipate everything that the JS interpreter might do when given two different types (which most JS developers cannot), you probably want to avoid == entirely.

For the value 2, you would think that 2 is a truthy value so it would compare favorably to true, but that isn't how the type coercion works. It is converting the right hand value to match the type of the left hand value so its converting true to the number 1 so it's comparing 2 == 1 which is certainly not what you likely intended.

So, it really depends upon the expected values for booleanValue and how you want the code to work. If you know in advance that it's only ever going to have a true or false value, then comparing it explicitly with

For example, if you look at the implementation of .on() in jQuery, it has an optional return value. If the callback returns false, then jQuery will automatically stop propagation of the event. In this specific case, since jQuery wants to ONLY stop propagation if false was returned, they check the return value explicity for === false because they don't want undefined or 0 or "" or anything else that will automatically type-convert to false to also satisfy the comparison.

I think that this kind of code is not uncommon. It handles cases where getInput() returns undefined, null, or an empty string. Due to the two boolean evaluations submitInput() is only called if the given input is a string that contains non-whitespace characters.

In JavaScript && returns its first argument if it is falsy or its second argument if the first argument is truthy; so normalized will be undefined if someString was undefined and so forth. That means that none of the inputs to the boolean expressions above are actually boolean values.

I know that a lot of programmers who are accustomed to strong type-checking cringe when seeing code like this. But note applying strong typing would likely require explicit checks for null or undefined values, which would clutter up the code. In JavaScript that is not needed.

So when you're using an if statement, (or any other control statement), one does not have to use a "boolean" type var. Therefore, in my opinion, the "=== true" part of your statement is unnecessary if you know it is a boolean, but absolutely necessary if your value is an ambiguous "truthy" var. More on booleans in javscript can be found here.

This depends. If you are concerned that your variable could end up as something that resolves to TRUE. Then hard checking is a must. Otherwise it is up to you. However, I doubt that the syntax whatever == TRUE would ever confuse anyone who knew what they were doing.

Hi there guys. I'm using Maya 2016. I know a lot of people have problems using booleans in Maya and I'm one of them.
I tried to find an answer in the forum, looked up like 10+ threads, but didn't see an answer to my question.
So I tried to use 3-4 different boolean plugins, one of which I paid for (Crease+), others were free or trial and the same problem persists.

When I use Difference and then Add Divisions to that object, this happens

From to

Problem N.2. When I duplicate object Ctrl + D then press Ctrl + G and then write -1 on the Scale X ...it mirror's my object on the other side, no problem with that. But when I try to Boolean Union the 3 objects...the mirrored one goes black and the others disappear like this. I tried to delete history before the Union, but didn't help...maybe I'm doing something wrong

From this to this

So can someone help with those? I'm kinda new to Maya, even tho I watched tutorials I still don't know many things. They don't say anything about how to avoid my problems in the Booleans Tutorials. Maybe you can tell me which boolean Plugin to use?

Then I tried to print it with Serial.println(state); but nothing comes out of the serial monitor. I got around it by just declaring state to be an int, but why should I have to? What am I doing wrong?

Regarding your print statement, by default serial.print() will try to print one byte data as ASCII. Something is actually coming out, but it's ASCII 0 which is probably not what you want. You can force the output to be numeric like this:

Could be a library that you have installed. Could be a holdover from Wiring. It is probably a method to a class, so using it as a variable probably doesn't matter. The IDE isn't very sophisticated about highlighting. All keywords are stored in a file called "keywords.txt". Each library comes with its own keywords.txt file.

When I have booleans, I find it kind of useless to just get a "true" or "false" response. To get anything useful, you'd need to do a Serial.print() before printing the value anyway. So instead I do this:

Oh I get it now...the IDE reads all the libraries keywords.txt on startup, not just when you #include a library. I changed 'status' to 'stptus' in the Ethernet keywords.txt and restarted the IDE and you're right it wasn't highlighted.

A developer defines a method with a boolean as one of its parameters, and that method calls another, and so on, and eventually that boolean is used, solely to determine whether or not to take a certain action. This might be used, for example, to allow the action only if the user has certain rights, or perhaps if we are (or aren't) in test mode or batch mode or live mode, or perhaps only when the system is in a certain state.

Well there is always another way to do it, whether by querying when it is time to take the action (rather than passing the parameter), or by having multiple versions of the method, or multiple implementations of the class, etc. My question isn't so much how to improve this, but rather whether or not it really is wrong (as I suspect), and if it is, what is wrong about it.

As other posters have noted context is everything (don't go in heavy-handed if it's a one off or if the practice has been acknowledged as deliberately incurred technical debt to be re-factored later) but broadly speaking if there is a parameter passed into a function that selects specific behaviour to be executed then further step-wise refinement is required; Breaking up this function in to smaller functions will produce more highly cohesive ones.

The problem with a parameter passed in as you describe, is that the function is doing more than two things; it may or may not check the users access rights depending on the state of the Boolean parameter, then depending on that decision tree it will carry out a piece of functionality.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages