language-agnostic

When to use unsigned values over signed ones?

丶灬走出姿态 提交于 2019-12-27 12:20:47
问题 When is it appropriate to use an unsigned variable over a signed one? What about in a for loop? I hear a lot of opinions about this and I wanted to see if there was anything resembling a consensus. for (unsigned int i = 0; i < someThing.length(); i++) { SomeThing var = someThing.at(i); // You get the idea. } I know Java doesn't have unsigned values, and that must have been a concious decision on Sun Microsystems' part. 回答1: I was glad to find a good conversation on this subject, as I hadn't

When to use unsigned values over signed ones?

折月煮酒 提交于 2019-12-27 12:20:12
问题 When is it appropriate to use an unsigned variable over a signed one? What about in a for loop? I hear a lot of opinions about this and I wanted to see if there was anything resembling a consensus. for (unsigned int i = 0; i < someThing.length(); i++) { SomeThing var = someThing.at(i); // You get the idea. } I know Java doesn't have unsigned values, and that must have been a concious decision on Sun Microsystems' part. 回答1: I was glad to find a good conversation on this subject, as I hadn't

Is there a difference between foreach and map?

最后都变了- 提交于 2019-12-27 12:11:38
问题 Ok this is more of a computer science question, than a question based on a particular language, but is there a difference between a map operation and a foreach operation? Or are they simply different names for the same thing? 回答1: Different. foreach iterates over a list and applies some operation with side effects to each list member (such as saving each one to the database for example) map iterates over a list, transforms each member of that list, and returns another list of the same size

Is there a difference between foreach and map?

醉酒当歌 提交于 2019-12-27 12:11:08
问题 Ok this is more of a computer science question, than a question based on a particular language, but is there a difference between a map operation and a foreach operation? Or are they simply different names for the same thing? 回答1: Different. foreach iterates over a list and applies some operation with side effects to each list member (such as saving each one to the database for example) map iterates over a list, transforms each member of that list, and returns another list of the same size

Modulus power of big numbers

旧时模样 提交于 2019-12-27 12:09:11
问题 I am trying to implement the SAFER+ algorithm. The algorithm requires finding the modulus of a power function as follows: pow(45, x) mod 257 The variable x is a byte, and thus can range from 0 to 255. Accordingly, the result of the power function can be VERY big resulting in incorrect values if implemented using 32- or 64-bit integers. How can I perform this calculation? 回答1: some pseudo code function powermod(base, exponent, modulus) { if (base < 1 || exponent < 0 || modulus < 1) return -1

Do write-only properties have practical applications?

一世执手 提交于 2019-12-27 12:06:07
问题 I don't know why I started thinking about this, but now I can't seem to stop. In C# - and probably a lot of other languages, I remember that Delphi used to let you do this too - it's legal to write this syntax: class WeirdClass { private void Hello(string name) { Console.WriteLine("Hello, {0}!", name); } public string Name { set { Hello(name); } } } In other words, the property has a setter but no getter , it's write-only . I guess I can't think of any reason why this should be illegal , but

Do write-only properties have practical applications?

瘦欲@ 提交于 2019-12-27 12:03:09
问题 I don't know why I started thinking about this, but now I can't seem to stop. In C# - and probably a lot of other languages, I remember that Delphi used to let you do this too - it's legal to write this syntax: class WeirdClass { private void Hello(string name) { Console.WriteLine("Hello, {0}!", name); } public string Name { set { Hello(name); } } } In other words, the property has a setter but no getter , it's write-only . I guess I can't think of any reason why this should be illegal , but

Detecting a stale pid file in a Unix environment

自古美人都是妖i 提交于 2019-12-25 14:14:12
问题 What is the standard, cross-platform way to detect stale pid file in a Unix environment? Say I would like to kill an old instance of my application, but I certainly don't want to disrupt an unrelated process with the same PID if that application has already exited. Now I found a way to do it on my Ubuntu (and thus probably other GNU/Linux based systems) - pseudocode below: if ( mtime(pid_file) < mtime( "/proc/"+pid ) ) { /* process started AFTER the file creation */ /* so it's not what we're

Detecting a stale pid file in a Unix environment

寵の児 提交于 2019-12-25 14:12:50
问题 What is the standard, cross-platform way to detect stale pid file in a Unix environment? Say I would like to kill an old instance of my application, but I certainly don't want to disrupt an unrelated process with the same PID if that application has already exited. Now I found a way to do it on my Ubuntu (and thus probably other GNU/Linux based systems) - pseudocode below: if ( mtime(pid_file) < mtime( "/proc/"+pid ) ) { /* process started AFTER the file creation */ /* so it's not what we're

Webservice test isolation - but when to verify the webservice itself?

妖精的绣舞 提交于 2019-12-25 13:08:12
问题 I am isolating my webservice-related tests from the actual webservices with Stubs. How do you/should i incorporate tests to ensure that my crafted responses match the actual webservice ones (i don't have control over it)? I don't want to know how to do it, but when and where? Should i create a testsuite-testsuite for testdata testing?... 回答1: I would use something like this excellent tool Storm 回答2: If you can, install the service in a small, completely controlled environment. Drawback: You