language-agnostic

Should unsigned ints be used if not necessary?

我的未来我决定 提交于 2019-12-29 05:06:26
问题 Should one ever declare a variable as an unsigned int if they don't require the extra range of values? For example, when declaring the variable in a for loop, if you know it's not going to be negative, does it matter? Is one faster than the other? Is it bad to declare an unsigned int just as unsigned in C++? To reitterate, should it be done even if the extra range is not required ? I heard they should be avoided because they cause confusion (IIRC that's why Java doesn't have them). 回答1: The

Dynamic Scoping - Deep Binding vs Shallow Binding

孤街浪徒 提交于 2019-12-29 04:29:09
问题 I've been trying to get my head around shallow binding and deep binding, wikipedia doesn't do a good job of explaining it properly. Say I have the following code, what would the output be if the language uses dynamic scoping with a) deep binding b) shallow binding? x: integer := 1 y: integer := 2 procedure add x := x + y procedure second(P:procedure) x:integer := 2 P() procedure first y:integer := 3 second(add) ----main starts here--- first() write_integer(x) 回答1: Deep binding binds the

Where/what level should logging code go?

假如想象 提交于 2019-12-29 03:29:08
问题 I'm wondering where logging code should go. For example, should my repository log it's own errors? Or should I log all errors from the UI/controller? Are there any general deisgn principles about this, or does anyone have link to a good article or somesuch. 回答1: Logging and tracing is (IMO) a fine art, knowing what to log and where takes experience. I've found that the best (worst?) way of learning the art of logging is by experiencing the pain of attempting to diagnose issues with shoddy

Where/what level should logging code go?

最后都变了- 提交于 2019-12-29 03:29:07
问题 I'm wondering where logging code should go. For example, should my repository log it's own errors? Or should I log all errors from the UI/controller? Are there any general deisgn principles about this, or does anyone have link to a good article or somesuch. 回答1: Logging and tracing is (IMO) a fine art, knowing what to log and where takes experience. I've found that the best (worst?) way of learning the art of logging is by experiencing the pain of attempting to diagnose issues with shoddy

How do you share configuration information or business rules between languages

坚强是说给别人听的谎言 提交于 2019-12-28 15:34:29
问题 I'm looking for best practices for using the same data in different places without repeating yourself - this could include configuration or business rules. Example 1. Data validation rules where you want to validate on the client using javascript, but you want to make sure by validating on the server. Example 2. Database access where your web server and your cronjobs use the same password, username. Ease of processing and a human-readable solution would be a plus. 回答1: Encode your data in

Pseudo-random number generator

≡放荡痞女 提交于 2019-12-28 12:29:11
问题 What is the best way to create the best pseudo-random number generator? (any language works) 回答1: Best way to create one is to not to. Pseudo-random number generators are a very complex subject, so it's better off to use the implementations produced by the people that have a good understanding of the subject. 回答2: It all depends on the application. The generator that creates the "most random" numbers might not be the fastest or most memory-efficient one, for example. The Mersenne Twister

All minimum spanning trees implementation

本小妞迷上赌 提交于 2019-12-28 12:16:27
问题 I've been looking for an implementation (I'm using networkx library.) that will find all the minimum spanning trees (MST) of an undirected weighted graph. I can only find implementations for Kruskal's Algorithm and Prim's Algorithm both of which will only return a single MST. I've seen papers that address this problem (such as Representing all minimum spanning trees with applications to counting and generation) but my head tends to explode someway through trying to think how to translate it

how to always round up to the next integer [duplicate]

好久不见. 提交于 2019-12-28 09:32:10
问题 This question already has answers here : How can I ensure that a division of integers is always rounded up? (8 answers) Closed 2 years ago . i am trying to find total pages in building a pager on a website (so i want the result to be an integer. i get a list of records and i want to split into 10 per page (the page count) when i do this: list.Count() / 10 or list.Count() / (decimal)10 and the list.Count() =12 , i get a result of 1 . How would I code it so i get 2 in this case (the remainder

Is there a known implementation of an indexed linked list?

随声附和 提交于 2019-12-28 05:46:13
问题 My gut tells me there is no good way to achieve this, but, unlike Mr. Stephen Colbert, I'd rather trust a community of developers than my gut... Is there a known way to efficiently implement a "best of both worlds" list, one that provides random access by index and O(1) insertion/removal like a linked list? I foresee two possible outcomes: either "No, this is impossible, for the following obvious reasons..." or "Uh, yes, this has been done; see here, here, and here." 回答1: I don't believe it

Why do most system architects insist on first programming to an interface?

倖福魔咒の 提交于 2019-12-28 05:14:09
问题 Almost every Java book I read talks about using the interface as a way to share state and behaviour between objects that when first "constructed" did not seem to share a relationship. However, whenever I see architects design an application, the first thing they do is start programming to an interface. How come? How do you know all the relationships between objects that will occur within that interface? If you already know those relationships, then why not just extend an abstract class? 回答1: