code-maintainability

code management: generate source files with slight variations of various rules

别来无恙 提交于 2020-01-26 03:33:09
问题 I have a source file in a declarative language ( twolc , actually) that I need to write many variations on: a normative version and many non-normative versions, each with one or more variations from the norm. For example, say the normative file has three rules: Rule A: Do something A-ish Rule B: Do something B-ish Rule C: Do something C-ish Then one variation might have the exact same rules as the norm for A and C , but a different rule for B , which I will call B-1 : Rule A: Do something A

Inputs for improving code debuggability apart from logs and error codes

丶灬走出姿态 提交于 2019-12-29 08:52:11
问题 Apart from error codes, error strings and logs, are there any other features which can be incorporated in the code to increase getting debug / trace information during code runtime which can help debug issues (or let us know what is going on) at runtime? 回答1: Here's an example of the code that sends a stacktrace to a file upon a segmentation fault #include <stdio.h> #include <signal.h> #include <stdlib.h> #include <stdarg.h> static void signal_handler(int); static void dumpstack(void); static

Can I create a named default constraint in an add column statement in SQL Server?

不羁的心 提交于 2019-12-18 10:06:10
问题 In SQL Server, I have a new column on a table: ALTER TABLE t_tableName ADD newColumn NOT NULL This fails because I specify NOT NULL without specifying a default constraint. The table should not have a default constraint. To get around this, I could create the table with the default constraint and then remove it. However, there doesn't appear to be any way to specify that the default constraint should be named as part of this statement, so my only way to get rid of it is to have a stored

Too many if statements

吃可爱长大的小学妹 提交于 2019-12-17 16:28:30
问题 I have some topic to discuss. I have a fragment of code with 24 if s/ elif s. Operation is my own class that represents functionality similar to Enum. Here is a fragment of code: if operation == Operation.START: strategy = strategy_objects.StartObject() elif operation == Operation.STOP: strategy = strategy_objects.StopObject() elif operation == Operation.STATUS: strategy = strategy_objects.StatusObject() (...) I have concerns from readability point of view. Is is better to change it into 24

Generic reflective helper method for equals and hashCode

亡梦爱人 提交于 2019-12-13 14:26:34
问题 I'm thinking about to create a reflective helper method for equals and hashCode. In case of equals the helper method looks over the reflection API to the fields of objectA and compares them with fields of objectB. In case of hashCode the helper method looks over the reflection API to the fields and calculates a hashCode in a iteration loop. The good thing is that I don't to be worry about missing fields in my equals or hashCode implementation. The bad thing is I guess performance. What do you

How to implement and mantain multiple actionListener

点点圈 提交于 2019-12-06 04:14:19
问题 Ok, I have one class (let's call it: MenuBarClass) that contain multiple Menu and MenuItem. I whant assign to every MenuItem an actionlistener, but.. instead of doing something like: menuitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); menuitem_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); menuitem_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); // ...

How to implement and mantain multiple actionListener

ぃ、小莉子 提交于 2019-12-04 11:23:52
Ok, I have one class (let's call it: MenuBarClass) that contain multiple Menu and MenuItem. I whant assign to every MenuItem an actionlistener, but.. instead of doing something like: menuitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); menuitem_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); menuitem_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); // ... menuitem_N.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); I

JQuery class selector vs id selector

梦想与她 提交于 2019-11-30 08:08:46
问题 I have 7 different buttons that all perform the same javascript function on click. should i use class selector or id selector. $("input.printing").on("click", function(event) { printPdf(event); }); or $("#package1Pdf").click(function(event) { printPdf(event); }); $("#package2Pdf").click(function(event) { printPdf(event); }); $("#package3Pdf").click(function(event) { printPdf(event); }); $("#package4Pdf").click(function(event) { printPdf(event); }); What are the advantage and disadvantage of

Is 100% code coverage a really good thing when doing unit tests? [closed]

邮差的信 提交于 2019-11-29 23:59:11
I always learned that doing maximum code coverage with unit tests is good . I also hear developers from big companies such as Microsoft saying that they write more lines of testing code than the executable code itself. Now, is it really great? Doesn't it seem sometimes like a complete loss of time which has an only effect to making maintenance more difficult ? For example, let's say I have a method DisplayBooks() which populates a list of books from a database. The product requirements tell that if there are more than one hundred books in the store, only one hundred must be displayed . So,

Inputs for improving code debuggability apart from logs and error codes

瘦欲@ 提交于 2019-11-29 14:47:56
Apart from error codes, error strings and logs, are there any other features which can be incorporated in the code to increase getting debug / trace information during code runtime which can help debug issues (or let us know what is going on) at runtime? Here's an example of the code that sends a stacktrace to a file upon a segmentation fault #include <stdio.h> #include <signal.h> #include <stdlib.h> #include <stdarg.h> static void signal_handler(int); static void dumpstack(void); static void cleanup(void); void init_signals(void); void panic(const char *, ...); struct sigaction sigact; char