language-agnostic

What should an escape character do if the following character doesn't need escaping?

强颜欢笑 提交于 2019-12-23 19:57:36
问题 An application I'm working on has a field where a string can be entered. Special characters in the string cause different things to be inserted when the string is evaluated, but these special characters can be preceded by an escape character (a backslash) which cause the special character to be output literally rather than its special meaning. Think of it as similar to a regular expression: . matches any character but \. matches a dot. What is the most intuitive thing to happen when the

Error recovery algorithms? [closed]

荒凉一梦 提交于 2019-12-23 19:27:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am doing a software that grabs in the end a numeric string, that string encodes important data, and any error destroy the contents. Worse: It is VERY prone for errors, because of how data is transmitted (and I can do nothing about it). So I decided to add a verification digit of sorts... After some research, I

How do you create your Factories?

廉价感情. 提交于 2019-12-23 18:43:58
问题 So, coming upon the subject of Factories, I'm wondering how they are set up. From where I stand, I can see 3 types of Factories: All In One A factory that basically contains all of the classes used in an application. It feels like it is just having a factory for the sake of having a factory, and doesn't really feel structured. Example (Where ClassA, Class B, and ClassC have nothing in common except being in the same App) : class Factory { public static function buildClassA() public static

Ratio of real code to supporting code

≯℡__Kan透↙ 提交于 2019-12-23 15:28:11
问题 I'm finding only about 30% of my code actually solves problems, the rest is taken up by logging, tests, parameter checking, exceptions, error handling and so on. Do you find that in your code, and is there an IDE/Editor that allows you to hide code that's not interesting? OTOH are there languages which make the support code more manageable and smaller in size? Edit - I think we're all aware of the difference between business logic and other code. I'm not saying that the logging etc is not

Should hardcoded passwords be salted/hashed?

两盒软妹~` 提交于 2019-12-23 14:41:35
问题 There are many questions on StackOverflow about simple, database-less login systems. I was about to suggest a salted hash approach on a recent one, when I thought: "does it really make sense to do that?". I have been storing salted hashes on databases for years, and I understand why it's more secure: if the database is compromised, the information it contains won't allow anyone to log into my system (unlike if I were storing plain text passwords in the db). But in a setup that does not

Are assertions redundant when you have unit tests?

混江龙づ霸主 提交于 2019-12-23 13:25:19
问题 I'm not used yet to write unit tests and I want to do this on a full framework of little tools (making it more secure to use). That way I'll certainly learn more about unit tests than what I learnt until now. However I'm really used to add assertions systematically everywhere I see there is a context to be sure about (that are removed in the final release). Mostly as preconditions in functions implementations and each time I retrieve informations that have to be correct (like C/C++ pointers

How do you set specific properties to a class created by an abstract factory?

纵饮孤独 提交于 2019-12-23 12:20:06
问题 Is it possible to have concrete factories create concrete classes with type specific parameters for them, using the abstract factory pattern? Or do the different concrete classes created by their respective concrete factories need to to have the same fields? Ex) In the image below how would you go about to instantiate the WinButton and the OSXButton with different set of arguments given by the client (Application)? 回答1: One of the approaches to address such problems is to send object

What techniques have you actually used successfully to improve code coverage?

谁说我不能喝 提交于 2019-12-23 09:57:47
问题 I regularly achieve 100% coverage of libraries using TDD, but not always, and there always seem to be parts of applications left over that are untested and uncovered. Then there are the cases when you start with legacy code that has very few tests and very little coverage. Please say what your situation is and what has worked that at least improved coverage. I'm assuming that you are measuring coverage during unit testing, but say if you are using other techniques. 回答1: Delete code. This isn

Moving a bit within a byte using bitfield or bitwise operators

╄→гoц情女王★ 提交于 2019-12-23 09:50:55
问题 Is there an elegant way of moving a bit within a byte (or word/long). For simplicity, lets use a simple 8-bit byte and just one bit to move within the byte. Given a bit number, based on 0-7 Least-sig-bit to most-sig-bit, (or bits 1-8 if you'd rather), I would like to move a bit from one position to another: 7654 3210 <bit position 0101 1010 <some binary value --x- --y- <move bit from x to y 0111 0100 <new value with x moved to y and intervening bits shifted left So, x at bit position 5 moves

When should a thread generally yield?

不打扰是莪最后的温柔 提交于 2019-12-23 09:35:02
问题 In most languages/frameworks, there exists a way for a thread to yield control to other threads. However, I can't really think of a time when yielding from a thread was the correct solution to a given problem. When, in general, should one use Thread.yield() , sleep(0) , etc? 回答1: One use case could be for testing concurrent programs, try to find interleavings that reveal flaws in your synchronization patterns. For instance in Java: A useful trick for increasing the number of interleavings,