order-of-operations

Excel VBA Boolean expression order of operations

I have a test in Excel VBA: If (test1) And (test2) And (test3) Then 'do something End If In C, Java, etc. test1 would be run first, then test2, then test3. Critically, if test1 is false the whole test is false so the remaining tests aren't run. Does that happen in this case? If so, which order are the tests running? ...

What is the order of operations with this concatenation?

x = "hello" " world".to_sym puts x.class This works and allows me to concatenate the two strings into a symbol, producing the output: Symbol But if I change it slightly to use a + instead of a space separating the hello and world strings, I get an error: x = "hello" + " world".to_sym puts x.class This produces the following e...

Why does "**" bind more tightly than negation?

I was just bitten by the following scenario: >>> -1 ** 2 -1 Now, digging through the Python docs, it's clear that this is intended behavior, but why? I don't work with any other languages with power as a builtin operator, but not having unary negation bind as tightly as possible seems dangerously counter-intuitive to me. Is there a ...

What good are right-associative methods in Scala?

I've just started playing around with Scala, and I just learned about how methods can be made right-associative (as opposed to the more traditional left-associativity common in imperative object-oriented languages). At first, when I saw example code to cons a list in Scala, I had noticed that every example always had the List on the rig...

Python String Formatting And String Multiplication Oddity

Python is doing string multiplication where I would expect it to do numeric multiplication, and I don't know why. >>> print('%d' % 2 * 4) 2222 >>> print('%d' % (2 * 4)) 8 Even forcing the type to integer does nothing. (I realize this is redundant, but it's an idiot-check for me: >>> print('%d' % int(2) * int(4)) 2222 Obviously I ...

Why does C give me a different answer than my calculator?

I've run into an odd problem with this code: legibIndex = 206.385 - 84.6 * (countSylb / countWord) - 1.015 * (countWord / countSent); This is the calculation for the legibility index of a given text file. Since this is a homework assignment, we were told what the Index should be (80, or exactly 80.3) My syllable count, word count, and...

Following an anchor to content on another page that isn't created until after the DOM is ready.

Hi all. To boil it down, I have two pages. Simplified, they could be represented this way. Page 1 <html> <a href="page-2.html#section-A">Link to section A</a> </html> Page 2 <html> <script> // Assume jQuery $(document).ready(function(){ $('#wrapper').append($('<a name="section-A">Here is S...

PHP Order of operations

I wanted to know how PHP would execute this. Order of operations addslashes(strip_tags($record['value'])); Is addslashes called first or strip_tags? In other words, does it execute from the inside out or from the outside in? ...

EntLib Validation Rules Order of Operations?

What determines the order of execution of an EntLib validation rule: Given the following: <ValidatorComposition(CompositionType.And, Ruleset:="Default")> _ <NotNullValidator(MessageTemplate:="Transaction ID is required.", Ruleset:="Default")> _ <TypeConversionValidator(GetType(Int64), MessageTemplate:="Transaction ID must be numeric.",...

Will this if statment cause bad things to happen?

int expenseCode; if (int.TryParse(sourceRecord.ExpenseCode, out expenseCode) && _ExpenseCodeLookup.ContainsKey(expenseCode)) { destRow.PROFIT_CENTER_NAME = _ExpenseCodeLookup[expenseCode]; } else destRow.PROFIT_CENTER_NAME = "Unknown"; The thing I am conerned about is will the first expression always be run (setting expenseC...

Order of operations question in Ruby

I'm initializing an instance of a class that tests the equality of two formulas. The formula's calculated values are in fact equal: RubyChem::Chemical.new("SOOS").fw => 96.0 RubyChem::Chemical.new("OSSO").fw = 96.0 When I created a new class to check the equality of these two instances I'm a bit surprised by the results: x = RubyCh...