Search Results

Search found 724 results on 29 pages for 'constants'.

Page 19/29 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • Use of private constructor to prevent instantiation of class?

    - by cringe
    Hi guys! Right now I'm thinking about adding a private constructor to a class that only holds some String constants. public class MyStrings { // I want to add this: private MyString() {} public static final String ONE = "something"; public static final String TWO = "another"; ... } Is there any performance or memory overhead if I add a private constructor to this class to prevent someone to instantiate it? Do you think it's necessary at all or that private constructors for this purpose are a waste of time and code clutter?

    Read the article

  • -1 as a return value

    - by dimadima
    This question is specifically about PHP, but I'm guessing it might be applicable to other languages as well. I've noticed that between PHP4 and PHP5, the designers of the language shifted away from using -1 as a return value to using constants or other forms of output. This makes sense, as -1 is not particularly evocative, and I'm guessing this practice led to confusion. That said, I am sometimes inclined to return -1 when I want to quickly add another return option to a function, and -1 often seems like a perfectly valid way to express the outcome I am coding for. So here are my questions: Is my observation generally correct, regarding the move away from -1 as a return value in PHP5 vs PHP4? What are the cons of returning -1, beyond for the reason I mentioned above, wherein the -1 return value doesn't contribute positively to code clarity?

    Read the article

  • PHP How to access constant defined outside class?

    - by Ashley Ward
    I have defined some constants eg: define('DB_HOSTNAME', 'localhost', true); define('DB_USERNAME', 'root', true); define('DB_PASSWORD', 'root', true); define('DB_DATABASE', 'authtest', true); now when I try to do this: class Auth{ function AuthClass() { $this->db_link = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD) or die(mysql_error()); } } I get an error. Why is this and what do I need to do? See, I've tried using (for example) global DB_HOSTNAME but this fails with an error.

    Read the article

  • determine from where the function being called in php

    - by Avinash
    I have one function on my code. say its xyz(). This function is being called from different files of my project. Is there any way than I can get from where the function is being called. I want below infromation: File name from where its called. Line number of that file. if call is from inside the function then that function name. Class name Class method name. I know about use of magic constants like FILE and all that. but i don't want to pass all that in function call. like below: xyz('msg',__FILE__,__CLASS__); is there any way that i have to pass just my error related data only. and it will find the above details from where the function is called. let me know if anything is not clear.

    Read the article

  • Why can't I have static public fields in my managed beans?

    - by AlanObject
    I just started using the Netbeans 7.1 beta and it is calling out errors of a type which I have never seen before. Specifically: A managed bean with a public field should not declare any scope other than @Dependent. The fields it is complaining about are public static final. I can understand the restriction on non-static fields, but I can't think of a good reason this would not be allowed for a static field. Unfortunately I use a lot of them since I don't like having constants in my code. I note that even though I get the red dot in the margin in the editor, the maven-driven build still works and GlassFish still runs my application the way I would expect. So what is my denoument on this issue? Am I going to have to move my static fields elsewhere or is there another way of handling this?

    Read the article

  • Is it kEatSpeed or kSpeedEat?

    - by bobobobo
    I have a bunch of related constants that are not identical. What's the better way to name them? way #1 kWalkSpeed kRunSpeed kEatSpeed kDrinkSpeed Or, way #2 kSpeedWalk kSpeedRun kSpeedEat kSpeedDrink If we evaluate these based on readability understandability not bug prone with subtle errors due to using wrong variable name I think way #1 wins readability, they tie for understandability, and way #2 wins for not bug prone. I'm not sure how often it happens to others, but when variable names like this get long, then its easy to write kSpeedEatingWhenInAHurry when you really meant kSpeedEatingWhenInHome, especially when using autocomplete. Any perspectives?

    Read the article

  • VB.NET logical expression evaluator

    - by Tim
    I need to test a logical expression held in a string to see if it evaluate to TRUE or FALSE.(the strig is built dynamically) For example the resulting string may contain "'dog'<'cat' OR (14 AND 4<6)". There are no variables in the string, it will logically evaluate. It will only contain simple operators = < < = <= and AND , OR and Open and Close Brackets, string constants and numbers. (converted to correct syntax && || etc.) I currently acheive this by creating a jscipt function and compiling it into a .dll. I then reference the .dll in my VB.NET project. class ExpressionEvaluator { function Evaluate(Expression : String) { return eval(Expression); } } Is there a simpler method using built in .NET functions or Lamdba expressions.

    Read the article

  • How to change code settings in eclipse

    - by Maven
    Sorry if the question title is confusing. Let me explain further. I am building a Java project with Eclipse. In my Java product I have conditionals that determine what code is included in the product and relies on static final constants for dead stripping. class BuildFlags { public static final boolean SOME_FLAG = true; // Need to set this programmatically } class SomeOtherClass { public void someMethod() { if (BuildFlags.SOME_FLAG) { // flag specific code } } } My question is how can I change BuildFlags.SOME_FLAG (above) so that I can run a special build without changing the source? Is there some way I can pass flags to the jvm (from eclipse) which I can then access to set this flag programatically?

    Read the article

  • Reference table values in a war against magic numbers

    - by Alex N.
    This question bugged me for years now and can't seem to find good solution still. I working in PHP and Java but it sounds like this maybe language-agnostic :) Say we have a standard status reference table that holds status ids for some kind of entity. Further let's assume the table will have just 5 values, and will remain like this for a long time, maybe edited occasionally with addition of a new status. When you fetch a row and need to see what status it is you have 2 options(as I see it at least) - put it straight ID values(magic numbers that is) or use a named constant. Latter seem much cleaner, the question though is where those named constants should leave? In a model class? In a class that uses this particular constant? Somewhere else?

    Read the article

  • Can anyone explain why this behaviour might be happening in Windows Forms?

    - by gizgok
    I'm developing a Windows Forms Application. See attached image for the Interface. Now I've put a close button (X) in the Panel(say Panel2) which has Application Constants as label.The first combo box is in another panel(say Panel1). Now when I click on the X button in Panel 2 I want the Panel to be invisible and the combo box text to be blank. Simple enough. So I write Panel2.visible=false; comboBox1.SelectedIndex=-1; When I click on X, the text in combo box goes blank, then I have to click again for the Panel2 to go invisible. Then I changed the sequence comboBox1.SelectedIndex=-1; Panel2.visible=fasle; and this works smooth. Not sure why this might be happening? Is there anything that I might be doing with my form design/code to have such a behaviour?

    Read the article

  • <= vs < when proving big-o notation

    - by user600197
    We just started learning big-o in class. I understand the general concept that f(x) is big-o of g(x) if there exists two constants c,k such that for all xk |f(x)|<=c|g(x)|. I had a question whether or not it is required that we include the <= to sign or whether it is just sufficient to put the < sign? For example: suppose f(x)=17x+11 and we are to prove that this is O(x^2). Then if we take c=28 and xk=1 we know that 17x+11<=28x^2. So since we know that x will always be greater than 1 this implies that 28x^2 will always be greater than 17x+11. So, do we really need to include the equal sign (<=) or is it okay if we just write (<)? Thanks in advance.

    Read the article

  • Optional parens in Ruby for method with uppercase start letter?

    - by RasmusKL
    I just started out using IronRuby (but the behaviour seems consistent when I tested it in plain Ruby) for a DSL in my .NET application - and as part of this I'm defining methods to be called from the DSL via define_method. However, I've run into an issue regarding optional parens when calling methods starting with an uppercase letter. Given the following program: class DemoClass define_method :test do puts "output from test" end define_method :Test do puts "output from Test" end def run puts "Calling 'test'" test() puts "Calling 'test'" test puts "Calling 'Test()'" Test() puts "Calling 'Test'" Test end end demo = DemoClass.new demo.run Running this code in a console (using plain ruby) yields the following output: ruby .\test.rb Calling 'test' output from test Calling 'test' output from test Calling 'Test()' output from Test Calling 'Test' ./test.rb:13:in `run': uninitialized constant DemoClass::Test (NameError) from ./test.rb:19:in `<main>' I realize that the Ruby convention is that constants start with an uppercase letter and that the general naming convention for methods in Ruby is lowercase. But the parens are really killing my DSL syntax at the moment. Is there any way around this issue?

    Read the article

  • Can't use static const as param in function call within binding tags in Flex 3

    - by buzzer
    I'm having a problem in flex 3 where if a static const I have defined is used as the parameter to a function call within binding tags I get a "1120: Access of undefined property NodePropertyMatrix". _propMtx is a ArrayCollection. <mx:HBox visible="{_propMtx.getItemAt(NodePropertyMatrix.srcParent)}"> Above code throws the error, but the following code does not <mx:HBox visible="{NodePropertyMatrix.srcParent}"> NodePropertyMatrix is an AS class as follows: package model.constants { import mx.collections.ArrayCollection; public class NodePropertyMatrix { public static const srcParent:Number = 0; } } Anyone know what is wrong here?

    Read the article

  • Add static const data to a struct already defined

    - by Kyle
    Since static const data inside a class is really just namespace sugar for constants I would think that struct A { float a; struct B { static const int b = a; }; }; would be equivalent to struct A { float a; }; struct A::B { static const int b = a; }; or something similar. Is something like this possible in C++? It would be useful for me to be able to tag class definitions that I'm pulling in from third party libraries with information like this.

    Read the article

  • How can I find all the supported weights of a Font in Java?

    - by William
    How can I find all the available font weights for a given font in Java? The TextAttribute for font weight lists 11 different weight constants, way more than just Font.PLAIN and Font.BOLD. I'd like to know which ones actually exist for a given font family, so I can make sure I'm only using weights for which a font face exists. The getAttributes() and getAvailableAttributes() methods in Font will only show me whether or not the Font supports the FONT_WEIGHT attribute, not which weight values it supports. If I just pass in a particular value to see what I get back, I don't have any guarantee that I'll get what I asked for. The TextAttribute class says "The values for WEIGHT, WIDTH, and POSTURE are interpolated by the system, which can select the 'nearest available' font or use other techniques to approximate the user's request."

    Read the article

  • Scala's tuple unwrapping nuance

    - by Paul Milovanov
    I've noticed the following behavior in scala when trying to unwrap tuples into vals: scala> val (A, B, C) = (1, 2, 3) <console>:5: error: not found: value A val (A, B, C) = (1, 2, 3) ^ <console>:5: error: not found: value B val (A, B, C) = (1, 2, 3) ^ <console>:5: error: not found: value C val (A, B, C) = (1, 2, 3) ^ scala> val (u, v, w) = (1, 2, 3) u: Int = 1 v: Int = 2 w: Int = 3 Is that because scala's pattern matching mechanism automatically presumes that all identifiers starting with capitals within patterns are constants, or is that due to some other reason? Thanks!

    Read the article

  • How can I keep doxygen from documenting #defines in a C file?

    - by Chris Nelson
    I have #define values in headers that I certainly want Doxygen to document but I have others in C files that I treat as static constants and I don't want Doxygen to document them. Something as simple and stupid as #define NUMBER_OF(a) (sizeof((a))/sizeof((a)[0])) #define MSTR(e) #e How can I keep Doxygen from putting those #defines in the documentation it creates? I've tried marking it with @internal but that didn't seem to help. A somewhat-related question on Doxygen and #define, how can I get: #define SOME_CONSTANT 1234 /**< An explanation */ to put "SOME_CONSTANT" and "An explanation" but not "1234" in the output?

    Read the article

  • Anyone using a web service as a data source in Excel 2007?

    - by Scott
    Can I use a web service as a data soruce for Excel pivot tables? Currently, the soure data for the pivot table is being exported from the DB to a CSV file. Then the CSV file is loaded into a worksheet in the workbook. From there, a pivot table is created in the same workbook. We are looking to streamline this process. The SQL db and pivot tables are the constants. The pivot tables are generated dynamically from a public-facing website. This is not an internal app so the preference is to not connect directly to the DB.

    Read the article

  • why this with excel sheet reading?

    - by Lalit
    Hi, I am reading the excel sheet from c# interop services cell by cell. where as my excel sheet have Date cells. It generates some double values , I am converting them in date by : double dbl = Convert.ToDouble(((Excel.Range)worksheet.Cells[iRowindex, colIndex_q17]).Value2); string strDate3 = DateTime.FromOADate(dbl).ToShortDateString(); drRow[dtSourceEXLData.Columns[constants.VisualDate]] = strDate3; ok? but some time happening the value of ((Excel.Range)worksheet.Cells[iRowindex,colIndex_q17]).Value2 getting date formate.why this is happeing? plaease guide me. it throws excepion of "input string not in correct format".why it is not generating double value like other cell of same column?

    Read the article

  • Why is the value of __name__ changing after assignment to sys.modules[__name__]?

    - by martineau
    While trying to do something similar to what's in the ActiveState recipe titled Constants in Python by Alex Martelli, I ran into an unexpected side-effect that assigning a class instance to an entry in sys.modules apparently has in Python 2.7 -- namely that doing so apparent changes the value of __name__ to None as illustrated in the following code fragment: class _test(object): pass import sys print '__name__: %r' % __name__ # __name__: '__main__' sys.modules[__name__] = _test() print '__name__: %r' % __name__ # __name__: None if __name__ == '__main__': # never executes... import test print "done" I'd like to understand why this is happening. I don't believe it was that way in Python 2.6 and earlier versions since I have some older code where apparently the if __name__ == '__main__': conditional worked as expected following the assignment (but no longer does). FWIW, I also noticed that the name _class is getting rebound from a class object to None, too, after the assignment. Also seems odd to me that they're being rebound to 'None' rather than disappearing altogether... Update: I'd like to add that any workarounds for achieving the effect of if __name__ == '__main__':, given what happens would be greatly appreciated. TIA!

    Read the article

  • Why are Objective-C instance variables declared in an interface?

    - by Chase
    I'm just getting into Objective-C (Java is my primary OO language). Defining an object's instance variables in the interface instead of the class seems strange. I'm used to an interface being a public API definition with nothing besides method signatures (not counting constants here). Is there some reason that state is defined in an interface (even if it is private) and behaviour is defined in a class. It just seems odd that since objects are state+behavior that the definition would be split into two separate places. Is it a design benefit is some way? A pain in the rear issue that you are just forced to deal with in Objective-C? A non-issue, just different? Any background on why it's done this way? Or can you put object state in a class and I just haven't hit that part in my book yet?

    Read the article

  • How can I declare constant strings for use in both an unmanaged C++ dll and in a C# application?

    - by Surfbutler
    Curently I'm passing my const string values up from my C++ into my C# at startup via a callback, but I'm wondering if there's a way of defining them in a C++ header file that I can then also refer to in C#. I already do this with enums as they are easy. I include a file in both my C++ library project (via a .h file with a pragma once at the top), and my C# application (as a link): #if _NET public #endif enum ETestData { First, Second }; I know it sounds messy, but it works :) But...how can I do the same with string constants - I'm initially thinking the syntax is too different between the platforms, but maybe there's a way? Using clever syntax involving #if _NET, #defines etc? Using resource files? Using a C++/CLI library? Any ideas?

    Read the article

  • How to send files along with parameters over http

    - by achie
    I am trying to send a zipfile from my android application to our server and I keep getting a 411 length required error. Here is the code that I am using to do that. HttpPost post = new HttpPost("http://www.xyz.org/upload.json"); post.setHeader(C.constants.HTTP_CONTENT_TYPE, "application/octet-stream"); try { FileInputStream fis = new FileInputStream("/data/data/org.myapp.appname/app_content.zip"); InputStreamEntity reqEntity = new InputStreamEntity(fis, -1); post.setEntity(reqEntity); String response = doPost(post); Log.v(tag, "response from server " + response); } catch (FileNotFoundException e) { e.printStackTrace(); } What am I doing wrong here and may I also know how I can add more parameters with this post to send them to the server.

    Read the article

  • In SQL how do I get the maximum value for an integer?

    - by CoffeeMonster
    Hi, I am trying to find out the maximum value for an integer (signed or unsigned) from a MySQL database. Is there a way to pull back this information from the database itself? Are there any built-in constants or functions I can use (either standard SQL or MySQL specific). At http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html it lists the values - but is there a way for the database to tell me. The following gives me the MAX_BIGINT - what I'd like is the MAX_INT. SELECT CAST( 99999999999999999999999 AS SIGNED ) as max_int; # max_int | 9223372036854775807 Thanks in advance,

    Read the article

  • How do you specify a 64 bit unsigned int const 0x8000000000000000 in VS2008?

    - by Mark Franjione
    I read about the Microsoft specific suffix "i64" for integer constants. I want to do an UNsigned shift to a ULONGLONG. ULONGLONG bigNum64 = 0x800000000000000i64 >> myval; In normal C, I would use the suffix "U", e.g. the similar 32 bit operation would be ULONG bigNum32 = 0x80000000U >> myval; I do NOT want the 2's complement sign extension to propogate through the high bits. I want an UNSIGNED shift on a 64 bit const number. I think my first statement is going to do a SIGNED shift right. I tried 0x800000000000000i64U and 0x800000000000000u64 but got compiler errors.

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >