coding-style

Nested case statements in SML

一笑奈何 提交于 2019-12-06 17:18:45
问题 This is more of a stylistic question than anything else. Given the following piece of code: case e1 of (* datatype type_of_e1 = p1 | p2 *) p1 => case e11 of (* datatype type_of_e11 = NONE | SOME int *) NONE => expr11 | SOME v => expr12 v | p2 => case e21 of (* datatype type_of_e21 = NONE | SOME string *) NONE => expr21 | SOME v => expr22 v Is there a way to resolve the types of rules don't agree error caused by trying to pattern match e11 to p2 , other than enclosing p1 's expression in

can I change the look and feel of the clickablespan

和自甴很熟 提交于 2019-12-06 17:12:42
问题 I have to embed a clickable text in a paragraph text, clickablespan can do it. But instead of using the default focus/press/unfocus style, can I change those style ? Like when focus, the background color is blue, text color is white, when unfocus, the background color is white, text color is blue. 回答1: Here is the example bottomMsg = (TextView) findViewById(R.id.bottom_msg); int start = bottomMsg.getText().toString().indexOf(terms); MovementMethod movementMethod = LinkMovementMethod

Refer to data files from within C++ project

三世轮回 提交于 2019-12-06 16:06:23
I have a C++ project with a folder structure something like so: root/trunk root/trunk/src/... root/trunk/include/... root/trunk/utils/... <-- this has the `main` programs which are compiled root/trunk/bin/... compiled binaries root/data/... data used in the programs In my source files, I sometimes refer to files included in the data subfolders. I want the paths I use to be relative paths (because I am sharing this project with someone else). How can I ensure that the data files can always be found? Currently I use paths such as the following: std::string my_data("../../../data/path/to/file.txt

More methods in derived classes than base class

与世无争的帅哥 提交于 2019-12-06 15:35:39
I would like to ask a question about programming style in this case of derived class: class A { public: virtual foo1()=0; } class B: public A { public: virtual foo1(); virtual foo2(); } class C: public A { public: virtual foo1(); } int main() { B mB(); C mC(); mB.foo2() //OK! mC.foo2() // obviously, it is not correct return 0;} Therefore, should a derived class have less or equal public methods than the abstract base class? If the derived classes require more methods, should these be private? There is nothing wrong with this class structure. There is nothing wrong with a derived class having

How to clear screen from simple C program?

雨燕双飞 提交于 2019-12-06 15:31:03
问题 #include <stdio.h> #include <cstdlib> rec(); main() { int a, fact; char q, n, y; printf("\nEnter any number "); scanf("%d", & a); fact = rec(a); printf("Factorial value = %d\n", fact); printf("do you want to exit.....(y/n):"); scanf("%s" ,&q); if (q == 'n') { system("cls"); main(); } else return 0; } rec(int x) { int f; if (x == 1) return 1; else f = x * rec(x - 1); return f; } I'm using code blocks but I don't know how to clear the screen. I searched then found system("cls"); within header

JSON usage in Python

与世无争的帅哥 提交于 2019-12-06 15:29:22
I'm looking through the json documentation and I'm trying to understand how to actually convert a Python object into JSON data, and then convert that data back into a Python object. I understand you can pass lists, dicts, and tuples of "primitives" like in the example at the top, but I tried creating a very minimal object and passing it to json.dumps() and got "object is not JSON serializable". What is the proper way to make an object JSON serializable? I'm currently imagining writing a method which converts my object into a dictionary then passes it to json.dump() and a parallel method to

Dealing with ugly SQL in Java

允我心安 提交于 2019-12-06 14:52:46
问题 Here goes a SQL-Java coding style question... How do others here deal with creating complex custom queries in Java cleanly ? I am speaking of the seemingly simple task of preparing a string which is the SQL statement to be executed. I am aware of HQL, and also of stored procedures, but honestly I don't really love these solutions. Perhaps I can be convinced differently. Stored procedures are annoying to deploy/maintain, and parsing performance is not such a huge issue in my case --

Missing Term Arithmetic Progression - Clean up my code

廉价感情. 提交于 2019-12-06 14:05:14
问题 I just tried a little online programming quiz that asked me to solve this problem as quickly as possible. I got the right answer but I know it isn't pretty. I'm trying to become a better programmer and write cleaner, more efficient code so please give me some tips. I've included the description below. PS I think this algorithm fails for the case N=3 # Enter your code here. Read input from STDIN. Print output to STDOUT import sys N= int(sys.stdin.readline()) stringdata = sys.stdin.readline()

Endianness conversion and g++ warnings

有些话、适合烂在心里 提交于 2019-12-06 13:37:20
I've got the following C++ code : template <int isBigEndian, typename val> struct EndiannessConv { inline static val fromLittleEndianToHost( val v ) { union { val outVal __attribute__ ((used)); uint8_t bytes[ sizeof( val ) ] __attribute__ ((used)); } ; outVal = v; std::reverse( &bytes[0], &bytes[ sizeof(val) ] ); return outVal; } inline static void convertArray( val v[], uint32_t size ) { // TODO : find a way to map the array for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++) v[i] = fromLittleEndianToHost( v[i] ); } }; Which work and has been tested (without the used

ASP.NET coding standards guide [closed]

会有一股神秘感。 提交于 2019-12-06 12:16:20
问题 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 yesterday . Can anyone tell me where can I find a good article on ASP.NET with C# Coding Standards. 回答1: Not exactly for ASP.NET, but you should check out the IDesign c# coding standard. 回答2: One of the most refered to is Lance Hunt's C# coding standard: C# Coding Standards document Above link is now defunct. Try https:/