side-effects

Why is “volatileQualifiedExpr + volatileQualifiedExpr” not necessarily UB in C but in C++?

五迷三道 提交于 2019-12-05 15:57:21
问题 When I today read the C Standard, it says about side effects Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects and the C++ Standard says Accessing an object designated by a volatile glvalue (3.10), modifying an object, calling a library I/O function, or calling a function that does any of those operations are all side effects Hence because both forbid unsequenced side effects to occur on the same

How to Document Java Side Effects

主宰稳场 提交于 2019-12-05 10:32:47
Is there a standard or best practice for writing javadocs for Java/JVM language methods which contain side effects? I have a void method defined, which modifies one of the method parameters, but do not know how to document the actual return value (since there is no actual return). /** * @param obj - reference object * @return obj - obj.name is changed to 'hello' //TODO figure out javadoc annotation */ void methodName(Object obj) { if (obj != null) { obj.name = "hello"; } } It just seems that there is no good way to tag the side effects on the object, since the @param and @return annotations do

PSR-1 2.3 Side Effects Rule

梦想与她 提交于 2019-12-05 09:53:41
问题 I have a question Regarding PHP Basic Coding Standards PSR1. PSR 1 Rule 2.3 states: Rule 2.3 Side Effects A file SHOULD declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it SHOULD execute logic with side effects, but SHOULD NOT do both. The phrase "side effects" means execution of logic not directly related to declaring classes, functions, constants, etc., merely from including the file . "Side effects" include but are not limited to: generating

How are side effects and observable behavior related in C++?

霸气de小男生 提交于 2019-12-04 23:25:30
C++03 Standard 1.9/6 defines observable behavior : The observable behavior of the abstract machine is its sequence of reads and writes to volatile data and calls to library I/O functions. and then and then 1.9/7 defines side effects : Accessing an object designated by a volatile lvalue (3.10), modifying an object, calling a library I/O function, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. Is a side effect an observable behavior or not? How are they related to each other? No, a side effect is not

How to handle bidirectional relationships when constructing hibernate entities?

扶醉桌前 提交于 2019-12-04 11:08:59
I want to model the relationship between two entities, a group and an account with JPA/Hibernate. An account can have several groups, but not vice versa, so we have a OneToMany relationship between account and group. My working colleague suggested to model the entities Account and Group like public class Account { private List<Group> groups = new ArrayList<Group>(); public Account() {} public void setGroups(List<Group> usergroups) { this.groups = groups; } @OneToMany(mappedBy = "account") public List<Group> getGroups() { return groups; } } and public class Group { private String name; private

Functional programming construct for composing identity and side effect

南笙酒味 提交于 2019-12-04 08:03:14
Does functional programming have a standard construct for this logic? const passAround = (f) => (x) => { f(x); return x; }; This enables me to compose functions that have side effects and no return values, like console.log . It's not like a Task because I don't want to represent the state of the side effect. The SKI combinator calculus might interest you. Let's pretend that f is always a pure function: const S = g => f => x => g(x)(f(x)); // S combinator of SKI combinator calculus const K = x => y => x; // K combinator of SKI combinator calculus const passAround = S(K); // Yes, the passAround

When exactly does a method have side effects?

梦想与她 提交于 2019-12-04 05:01:00
As I always understood it, any change to the programs state (or anything to do with IO) is a side effect. It does not matter, whether the change occurs in a global variable or in a private field of the object the method is called on. It follows that all methods which do not return anything either do nothing at all or have a side effect. My confusion comes from one of our university's instructors (who is still a student and thus not omniscient yet;) ) telling me setters don't have side effects. runako Your instructor is mistaken. With apologies to the SO editors for not pasting the entire

Why is “volatileQualifiedExpr + volatileQualifiedExpr” not necessarily UB in C but in C++?

对着背影说爱祢 提交于 2019-12-04 01:38:37
When I today read the C Standard, it says about side effects Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects and the C++ Standard says Accessing an object designated by a volatile glvalue (3.10), modifying an object, calling a library I/O function, or calling a function that does any of those operations are all side effects Hence because both forbid unsequenced side effects to occur on the same scalar object, C allows the following, but C++ makes it undefined behavior int a = 0; volatile int *pa =

PSR-1 2.3 Side Effects Rule

99封情书 提交于 2019-12-04 00:03:29
I have a question Regarding PHP Basic Coding Standards PSR1. PSR 1 Rule 2.3 states: Rule 2.3 Side Effects A file SHOULD declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it SHOULD execute logic with side effects, but SHOULD NOT do both. The phrase "side effects" means execution of logic not directly related to declaring classes, functions, constants, etc., merely from including the file . "Side effects" include but are not limited to: generating output, explicit use of 'require' or 'include', connecting to external services, modifying ini settings,

Why are assignments not allowed in Python's `lambda` expressions?

戏子无情 提交于 2019-12-03 23:48:46
问题 This is not a duplicate of Assignment inside lambda expression in Python, i.e., I'm not asking how to trick Python into assigning in a lambda expression. I have some λ-calculus background. Considering the following code, it looks like Python is quite willing to perform side-effects in lambda expressions: #!/usr/bin/python def applyTo42(f): return f(42) def double(x): return x * 2 class ContainsVal: def __init__(self, v): self.v = v def store(self, v): self.v = v def main(): print('==