Why would you use an assignment in a condition?
In many languages assignments are legal in conditions. I never understood the reason behind this. Why would you write: if (var1 = var2) { ... } instead of: var1 = var2; if (var1) { ... } ...
In many languages assignments are legal in conditions. I never understood the reason behind this. Why would you write: if (var1 = var2) { ... } instead of: var1 = var2; if (var1) { ... } ...
Imagine I have a chunk of initialisation code at the top of a stored procedure with a number of variable assignments: SET @proc = 'sp_madeupname' SET @magic_number = 42 SET @tomorrows_date = DATEADD(dd, 1, GETDATE()) ... Clearly doing all of the above as one SELECT would be faster: SELECT @proc = 'sp_madeupname' ,@magic_numb...
As can be seen in the Mozilla changlog for JavaScript 1.7 they have added destructuring assignment. Sadly I'm not very fond of the syntax (why write a and b twice?): var a, b; [a, b] = f(); Something like this would have been a lot better: var [a, b] = f(); That would still be backwards compatible. Python-like destructuring would...
What is the most unpleasant programming task you've ever had to do? This could be an assignment from a job, or a project or homework assignment for a class. Dimensions of unpleasantness can include annoying, boring, tedious, being uncreative, requiring no thought but lots of menial coding. ...
Hi There... I have created a class to dynamically put together SQL function statements within a project. I have found this class to be pretty useful and would like to incorporate into future projects namespace connectionClass { public class connClass { NpgsqlConnection conn = new NpgsqlConnection(projectName.Properties...
Under what circumstances should I expect memcpys to outperform assignments on modern INTEL/AMD hardware? I am using GCC 4.2.x on a 32 bit Intel platform (but am interested in 64 bit as well). ...
Hello guys... I have been developing an event handler to clean up the RolesAssignments of the new item of a document library in MOSS. I’ve searched for a method that could clean all the RolesAssignments efficiently, although the best way I found seams to be loop through the RolesAssignments and delete one by one. ¿Is there another way ...
I'm using the CPoint class from MFC. There is no explicitly defined assignment operator or copy constructor (AFAIK). Yet, this works: CPoint p1(1, 2), p2; p2 = p1; // p2 now is equal to p1 I'm assuming this is working automagically because of a compiler generated assignment operator. Correct? If so, can I be confident that this isn'...
It's the weirdest thing. When I ran the Rails WEBrick debugger yesterday I could do things like cookies[uid] = s.session_id where 'uid' is a passed argument that has a user id in it, and then expect cookies[uid] to give me back, say: 29b93443d9ec18168a26e1ab12957b0dd0b799ff Today, I always get back 'nil'. I can read existing va...
Consider the following: int ival = 1.01; int &rval = 1.01; // error: non-const reference to a const value. int &rval = ival; rval = 1.01; The first assignment of &rval to a literal value fails as expected. If I comment out that line the code compiles and runs. I understand why the initialization fails, but I'm confused why the assi...
Hello, I have a question about the use of "this" in Java. If I write the following class: public class Example { int j; int k; public Example(int j, int k) { j = j; k = k; } public static void main(String[] args) { Example exm = new Example(1,2); System.out.p...
Given: -A set of items that each have costs for being placed into a given container type. -A set of container types that each have a number of available containers. Example: Amount*Container-Type : 5 * A, 3 * B, 2 * C Items(Costs) : 3 * X (A=2, B=3, C=1) 2 * Y (A=5, B=2, C=2) 1 * Z (A=3, B=3, C=1) Problem: Find the best placem...
Just a simple program to get used to pointers. The program is supposed to put the contents of a portion of my memory into a character array in reverse order of how the memory is read. I.E. looking at descending memory address, and I want to store it in descending order in a character array. My compiler keeps telling me: "error incompa...
Template: <form method="POST" action="/Bycategory/"> <input type="radio" name="andor1" value=1 checked> <input type="radio" name="andor1" value=2> <select id="pathology_id" name="pathology_id"> {% for pathology in pathology_list %} <option value="{{ pathology.id }}">{{ pathology.pathology }}</option> {% endfor %} </selec...
I've started reading Algorithms and I keep wondering, when dealing with primitives of the same type, which is the more expensive operation, assignment or comparison? Does this vary a great deal between languages? ...
I have recently started using Zend Studio which has reported as warning the following type of code: $q = query("select * from some_table where some_condition"); while ($f = fetch($q)) { // some inner workings } To stop the warning the code needs to be written like this: $q = query("select * from some_table where some_condition"); $...
I am having issues manipulating deeply nested lists in OCaml in the below context. class foo (pIn:int)= object (self) val p = pIn val even = if (pIn mod 2) = 0 then true else (false) method doIt = "doIt" method isEven = even method getP = p end;; let rec createListOfElements howMany = ( Random.self_init (); ...
Hi everyone I've got a bit of a problem with a somewhat simple wrapper class I have. It looks something like this: public class Wrapper<T> { private T _value; public Wrapper<T>(T value) { _value = value; } public static implicit operator Wrapper<T>(T value) { return new Wrapper<T>(value); } public static imp...
Just a quick and simple question, but couldn't find it in any documentation. template <class T> T* Some_Class<T>::Some_Static_Variable = NULL; It compiles with g++, but I am not sure if this is valid usage. Is it? ...
I tend to use the words define, declare and assign interchangeably but this seems to cause offense to some people. Is this justified? Should I only use the word declare for the first time I assign to a variable? Or is there more to it than that? ...