constants

Best practices to define constants used in an app

北战南征 提交于 2020-01-05 05:20:09
问题 I have a ContentProvider in a provider package where a JOIN query is declared: final String ALL_DATA_FOR_AN_ANIMAL = "SELECT " + "animals._id, " + COLUMN_NAME + " AS _name, " + COLUMN_CLASSE + " AS _class, " + "IFNULL(" + COLUMN_OVERRIDE_INDIVIDU_NUMBER + ", " + COLUMN_INDIVIDU_NUMBER + ")" + " AS _ind_nb, " + "FROM " + ANIMALS_TABLE_NAME + " LEFT JOIN " + ANIMALS_OVERRIDE_TABLE_NAME + " ON " + COLUMN_NAME + " = " + COLUMN_OVERRIDE_NAME + " WHERE animals._id = ?"; All the sql aliases defined

Ruby: const_set outside block?

ε祈祈猫儿з 提交于 2020-01-04 14:20:58
问题 I want to mock a class with Ruby. How do I write a method that will take care of the boilerplate code? The following code: module Mailgun end module Acani def self.mock_mailgun(mock) temp = Mailgun const_set(:Mailgun, mock) p Mailgun yield ensure const_set(:Mailgun, temp) end end Acani.mock_mailgun('mock') { p Mailgun } prints: "mock" Mailgun What's going on here? Why is Mailgun its original value inside the block? Does this have to do with Ruby bindings? Ruby version: 2.1.1p76 回答1: Try

Why can you not declare constants in methods with Ruby?

戏子无情 提交于 2020-01-04 14:05:12
问题 Consider the following, StubFoo is a stub of Foo, which I wish to stub out for some tests. class Runner def run Foo = StubFoo foo = Foo.new # using Foo... end end This generates the following error message: Dynamic constant assignment Yet, in RSpec I can do the following, which works and is perfectly legal: it "should be an example" do Foo = StubFoo foo = Foo.new foo.to_s.should == "I am stubbed!" end A few questions regarding this. Why does this work with the RSpec test case, but not the

Checking if a variable is constant qualified

烂漫一生 提交于 2020-01-04 05:27:32
问题 I was reading about const_cast and it seemed unsafe and not very helpful. The best answer about it in SO states the it would be useful in a scenario like this: void func(const char* param, bool modify){ if(modify) //const_cast and change param // stuff that do not change param } Although this a possible use, it has its risks because you have to correctly provide the value of "modify", or else you will get an undefined behaviour since you are changing something that was supposed to be constant

Is is a good practice to store propery names in a public constant string?

走远了吗. 提交于 2020-01-03 16:57:21
问题 In order to protect ourself from failure because of any renaming of properties (Let's say you regenerate your poco classes because you have changed some column names in the relevant Db table) is it a good practice to decalre constant strings that keep the property names inside? public const string StudentCountPropertyName = "StudentCount"; public int StudentCount {get;set;} For example: Think about a DataBinding; where you type the property name in the DataFieldName attribute explicitly. Or

How long does a string constant live in c++?

柔情痞子 提交于 2020-01-03 14:16:21
问题 I've been wondering, how long does a string constant live in C++. For example, if I create some const char *str = "something" inside a function, would it be safe to return the value of str? I wrote a sample program and was really surprised to see that such returned value still stored that string. Here is the code: #include <iostream> using namespace std; const char *func1() { const char *c = "I am a string too"; return c; } void func2(const char *c = "I'm a default string") { cout << c <<

Reflecting constant properties/fields in .net [duplicate]

ε祈祈猫儿з 提交于 2020-01-03 08:52:52
问题 This question already has answers here : Type.GetFields() - only returning “public const” fields (3 answers) Closed last year . I have a class which looks like as follows: public class MyConstants { public const int ONE = 1; public const int TWO = 2; Type thisObject; public MyConstants() { thisObject = this.GetType(); } public void EnumerateConstants() { PropertyInfo[] thisObjectProperties = thisObject.GetProperties(BindingFlags.Public); foreach (PropertyInfo info in thisObjectProperties) { /

g++: array bound is not an integer constant

风流意气都作罢 提交于 2020-01-03 07:37:08
问题 With the code, const double rotationStep = 0.001; const int N = 2*int(M_PI/rotationStep) + 3; static unsigned int counts[N]; g++ gives the error: array bound is not an integer constant before »]« token I am using g++ / gcc version 4.6.1 Can anybody tell me why g++ complains about the expression? 回答1: As of the ISO C++ standard of 2003, that's not an integral constant-expression . Quoting section 5.19 of the standard: An integral constant-expression can involve only literals (2.13),

Use VBA to copy all visible and non-empty cells in a range

淺唱寂寞╮ 提交于 2020-01-03 04:32:14
问题 After filtering, I want to copy all visible and non-empty cells (the cells which contain text). For some reason, my current code isn't working. Any help would be greatly appreciated. Thanks! Sheets("Sheet1").Range("S2:S5000").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Copy 回答1: Full admission that I did not try your code, but you can also try the following With Sheets("Sheet1").Range("S2:S5000") Application.Intersect(.SpecialCells(xlCellTypeVisible), _ .SpecialCells

Circular dependency when Starting Sidekiq Queue

一笑奈何 提交于 2020-01-02 12:40:13
问题 I get the following error when loading a sidekiq queue: RuntimeError: Circular dependency detected while autoloading constant FileProcessor /Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:492:in `load_missing_constant' /Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing' /Users/johnmcauley/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:526