Search Results

Search found 15316 results on 613 pages for 'coding style'.

Page 72/613 | < Previous Page | 68 69 70 71 72 73 74 75 76 77 78 79  | Next Page >

  • CSS button not styling

    - by o-logn
    Hey, I must be missing something obvious, but can someone explain what I'm doing wrong with my CSS? I would like all buttons to have a certain format, except a few. I was expecting to use CssClass in order to override the few that should be different, but they all seem to use the standard one. My CSS: .btn { border:none; background-color:red; } input[type="submit"] { border: 2px solid black; background-color:green; } All the buttons take the second value (green background, with a border). However, I have this button: <asp:Button ID="btnAdd" CssClass="btn" runat="server" Text="Add" /> I was expecting this to have no border, and a red background, but it's the same as every other button. Any ideas what I'm doing wrong? Thanks

    Read the article

  • Java: repetition, overuse -- ?

    - by HH
    I try to be as minimalist as possible. Repetition is a problem. I hate it. When is it really a problem? what is static-overuse? what is field-method overuse? what is class-overuse? are there more types of overuse? Problem A: when it is too much to use of static? private static class Data { private static String fileContent; private static SizeSequence lineMap; private static File fileThing; private static char type; private static boolean binary; private static String name; private static String path; } private static class Print { //<1st LINE, LEFT_SIDE, 2nd LINE, RIGHT_SIDE> private Integer[] printPositions=new Integer[4]; private static String fingerPrint; private static String formatPrint; } Problem B: when it is too much to get field data with private methods? public Stack<Integer> getPositions(){return positions;} public Integer[] getPrintPositions(){return printPositions;} private Stack<String> getPrintViews(){return printViews;} private Stack<String> getPrintViewsPerFile(){return printViewsPerFile;} public String getPrintView(){return printView;} public String getFingerPrint(){return fingerPrint;} public String getFormatPrint(){return formatPrint;} public String getFileContent(){return fileContent;} public SizeSequence getLineMap(){return lineMap;} public File getFile(){return fileThing;} public boolean getBinary(){return binary;} public char getType(){return type;} public String getPath(){return path;} public FileObject getData(){return fObj;} public String getSearchTerm(){return searchTerm;} Related interface overuse

    Read the article

  • How much of STL is too much?

    - by Darius Kucinskas
    I am using a lot of STL code with std::for_each, bind, and so on, but I noticed that sometimes STL usage is not good idea. For example if you have a std::vector and want to do one action on each item of the vector, your first idea is to use this: std::for_each(vec.begin(), vec.end(), Foo()) and it is elegant and ok, for a while. But then comes the first set of bug reports and you have to modify code. Now you should add parameter to call Foo(), so now it becomes: std::for_each(vec.begin(), vec.end(), std::bind2nd(Foo(), X)) but that is only temporary solution. Now the project is maturing and you understand business logic much better and you want to add new modifications to code. It is at this point that you realize that you should use old good: for(std::vector::iterator it = vec.begin(); it != vec.end(); ++it) Is this happening only to me? Do you recognise this kind of pattern in your code? Have you experience similar anti-patterns using STL?

    Read the article

  • When is JavaScript's eval() not evil?

    - by Richard Turner
    I'm writing some JavaScript to parse user-entered functions (for spreadsheet-like functionality). Having parsed the formula I could convert it into JavaScript and run eval() on it to yield the result. However, I've always shied away from using eval() if I can avoid it because it's evil (and, rightly or wrongly, I've always thought it is even more evil in JavaScript because the code to be evaluated might be changed by the user). Obviously one has to use eval() to parse JSON (I presume that JS libraries use eval() for this somewhere, even if they run the JSON through a regex check first), but when else, other than when manipulating JSON, it is OK to use eval()?

    Read the article

  • XML: When to use attributes instead of child nodes?

    - by Rosarch
    For tree leaves in XML, when is it better to use attributes, and when is it better to use descendant nodes? For example, in the following XML document: <?xml version="1.0" encoding="utf-8" ?> <savedGame> <links> <link rootTagName="zombies" packageName="zombie" /> <link rootTagName="ghosts" packageName="ghost" /> <link rootTagName="players" packageName="player" /> <link rootTagName="trees" packageName="tree" /> </links> <locations> <zombies> <zombie> <positionX>41</positionX> <positionY>100</positionY> </zombie> <zombie> <positionX>55</positionX> <positionY>56</positionY> </zombie> </zombies> <ghosts> <ghost> <positionX>11</positionX> <positionY>90</positionY> </ghost> </ghosts> </locations> </savedGame> The <link> tag has attributes, but it could also be written as: <link> <rootTagName>trees</rootTagName> <packageName>tree</packageName> </link> Similarly, the location tags could be written as: <zombie positionX="55" positionY="56" /> instead of: <zombie> <positionX>55</positionX> <positionY>56</positionY> </zombie> What reasons are there to prefer one over the other? Is it just a stylistic issue? Any performance considerations?

    Read the article

  • [PHP] Invalid argument supplied for foreach()

    - by Roberto Aloi
    It often happens to me to handle data that can be either an array or a null variable and to feed some foreach with these data. $values = get_values(); foreach ($values as $value){ ... } When you feed a foreach with data that are not an array, you get a warning: Warning: Invalid argument supplied for foreach() in [...] Assuming it's not possible to refactor the get_values() function to always return an array (backward compatibility, not available source code, whatever other reason), I'm wondering which is the cleanest and most efficient way to avoid these warnings: Casting $values to array Initializing $values to array Wrapping the foreach with an if Other (please suggest)

    Read the article

  • Checkstyle for Python

    - by oneself
    Is there an application similar to Java's Checkstyle for Python? By which I mean, I tool that analyzes Python code, and can be run as part of continuous integration (e.g. CruiseControl or Hudson). After analyzing it should produce an online accessible report which outlines any problems found in the code. Thank you,

    Read the article

  • C#: Easy access to the member of a singleton ICollection<> ?

    - by Rosarch
    I have an ICollection that I know will only ever have one member. Currently, I loop through it, knowing the loop will only ever run once, to grab the value. Is there a cleaner way to do this? I could alter the persistentState object to return single values, but that would complicate the rest of the interface. It's grabbing data from XML, and for the most part ICollections are appropriate. // worldMapLinks ensured to be a singleton ICollection<IDictionary<string, string>> worldMapLinks = persistentState.GetAllOfType("worldMapLink"); string levelName = ""; //worldMapLinks.GetEnumerator().Current['filePath']; // this loop will only run once foreach (IDictionary<string, string> dict in worldMapLinks) // hacky hack hack hack { levelName = dict["filePath"]; } // proceed with levelName loadLevel(levelName); Here is another example of the same issue: // meta will be a singleton ICollection<IDictionary<string, string>> meta = persistentState.GetAllOfType("meta"); foreach (IDictionary<string, string> dict in meta) // this loop should only run once. HACKS. { currentLevelName = dict["name"]; currentLevelCaption = dict["teaserCaption"]; } Yet another example: private Vector2 startPositionOfKV(ICollection<IDictionary<string, string>> dicts) { Vector2 result = new Vector2(); foreach (IDictionary<string, string> dict in dicts) // this loop will only ever run once { result.X = Single.Parse(dict["x"]); result.Y = Single.Parse(dict["y"]); } return result; }

    Read the article

  • debugging scaffolding contingent upon degbugging boolean (java)

    - by David
    Recently i've found myself writing a lot of methods with what i can only think to call debugging scaffolding. Here's an example: public static void printArray (String[] array, boolean bug) { for (int i = 0; i<array.lenght; i++) { if (bug) System.out.print (i) ; //this line is what i'm calling the debugging scaffolding i guess. System.out.println(array[i]) ; } } in this method if i set bug to true, wherever its being called from maybe by some kind of user imput, then i get the special debugging text to let me know what index the string being printed as at just in case i needed to know for the sake of my debugging (pretend a state of affairs exists where its helpful). All of my questions more or less boil down to the question: is this a good idea? but with a tad bit more objectivity: Is this an effective way to test my methods and debug them? i mean effective in terms of efficiency and not messing up my code. Is it acceptable to leave the if (bug) stuff ; code in place after i've got my method up and working? (if a definition of "acceptability" is needed to make this question objective then use "is not a matter of programing controversy such as ommiting brackets in an if(boolean) with only one line after it, though if you've got something better go ahead and use your definition i won't mind) Is there a more effective way to accomplish the gole of making debugging easier than what i'm doing? Anything you know i mean to ask but that i have forgotten too (as much information as makes sense is appreciated).

    Read the article

  • Best practice - When to evaluate conditionals of function execution

    - by Tesserex
    If I have a function called from a few places, and it requires some condition to be met for anything it does to execute, where should that condition be checked? In my case, it's for drawing - if the mouse button is held down, then execute the drawing logic (this is being done in the mouse movement handler for when you drag.) Option one says put it in the function so that it's guaranteed to be checked. Abstracted, if you will. public function Foo() { DoThing(); } private function DoThing() { if (!condition) return; // do stuff } The problem I have with this is that when reading the code of Foo, which may be far away from DoThing, it looks like a bug. The first thought is that the condition isn't being checked. Option two, then, is to check before calling. public function Foo() { if (condition) DoThing(); } This reads better, but now you have to worry about checking from everywhere you call it. Option three is to rename the function to be more descriptive. public function Foo() { DoThingOnlyIfCondition(); } private function DoThingOnlyIfCondition() { if (!condition) return; // do stuff } Is this the "correct" solution? Or is this going a bit too far? I feel like if everything were like this function names would start to duplicate their code. About this being subjective: of course it is, and there may not be a right answer, but I think it's still perfectly at home here. Getting advice from better programmers than I is the second best way to learn. Subjective questions are exactly the kind of thing Google can't answer.

    Read the article

  • Return enum instead of bool from function for clarity ?

    - by Moe Sisko
    This is similar to : http://stackoverflow.com/questions/2908876/net-bool-vs-enum-as-a-method-parameter but concerns returning a bool from a function in some situations. e.g. Function which returns bool : public bool Poll() { bool isFinished = false; // do something, then determine if finished or not. return isFinished; } Used like this : while (!Poll()) { // do stuff during wait. } Its not obvious from the calling context what the bool returned from Poll() means. It might be clearer in some ways if the "Poll" function was renamed "IsFinished()", but the method does a bit of work, and (IMO) would not really reflect what the function actually does. Names like "IsFinished" also seem more appropriate for properties. Another option might be to rename it to something like : "PollAndReturnIsFinished" but this doesn't feel right either. So an option might be to return an enum. e.g : public enum Status { Running, Finished } public Status Poll() { Status status = Status.Running; // do something, then determine if finished or not. return status; } Called like this : while (Poll() == Status.Running) { // do stuff during wait. } But this feels like overkill. Any ideas ?

    Read the article

  • Why use infinite loops?

    - by Moishe
    Another poster asked about preferred syntax for infinite loops. A follow-up question: Why do you use infinite loops in your code? I typically see a construct like this: for (;;) { int scoped_variable = getSomeValue(); if (scoped_variable == some_value) { break; } } Which lets you get around not being able to see the value of scoped_variable in the for or while clause. What are some other uses for "infinite" loops?

    Read the article

  • Which syntax is better for return value?

    - by Omar Kooheji
    I've been doing a massive code review and one pattern I notice all over the place is this: public bool MethodName() { bool returnValue = false; if (expression) { // do something returnValue = MethodCall(); } else { // do something else returnValue = Expression; } return returnValue; } This is not how I would have done this I would have just returned the value when I knew what it was. which of these two patterns is more correct? I stress that the logic always seems to be structured such that the return value is assigned in one plave only and no code is executed after it's assigned.

    Read the article

  • "Verbose Dictionary" in C#, 'override new' this[] or implement IDictionary

    - by Benjol
    All I want is a dictionary which tells me which key it couldn't find, rather than just saying The given key was not present in the dictionary. I briefly considered doing a subclass with override new this[TKey key], but felt it was a bit hacky, so I've gone with implementing the IDictionary interface, and passing everything through directly to an inner Dictionary, with the only additional logic being in the indexer: public TValue this[TKey key] { get { ThrowIfKeyNotFound(key); return _dic[key]; } set { ThrowIfKeyNotFound(key); _dic[key] = value; } } private void ThrowIfKeyNotFound(TKey key) { if(!_dic.ContainsKey(key)) throw new ArgumentOutOfRangeException("Can't find key [" + key + "] in dictionary"); } Is this the right/only way to go? Would newing over the this[] really be that bad?

    Read the article

  • What do you need to implement to provide a Content Set for an NSArrayController?

    - by whuuh
    Heys, I am writing something in Xcode. I use Core Data for persistency and link the view and the model together with Cocoa Bindings; pretty much your ordinary Core Data application. I have an array controller (NSArrayController) in my Xib. This has its managedObjectContext bound to the AppDelegate, as is convention, and tracks an entity. So far so good. Now, the "Content Set" biding of this NSArrayController limits its content set (as you'd expect), by a keyPath from the selection in another NSArrayController (otherAc.selection.detailsOfMaster). This is the usual way to implement a Master-Detail relationship. I want to variably change the key path at runtime, using other controls. This way, I sould return a content set that includes several other content sets, which is all advanced and beyond Interface Builder. To achieve this, I think I should bind the Content Set to my AppDelegate instead. I have tried to do this, but don't know what methods to implement. If I just create the KVC methods (objectSet, setObjectSet), then I can provide a Content Set for the Array Controller in the contentSet method. However, I don't think I'm binding this properly, because it doesn't "refresh". I'm new to binding; what do I need to implement to properly update the Content Set when other things, like the selection in the master NSArrayController, changes?

    Read the article

  • WPF datagrid template

    - by MadSeb
    Hi, I want to make a WPF datagrid look similar to the HTML grid in the following picture: http://img443.imageshack.us/img443/2563/saltoftheearth.jpg Does anyone know an easy way to do this ? Regards, S.

    Read the article

  • Way to get VS 2008 to stop forcing indentation on namespaces?

    - by Earlz
    I've never really been a big fan of the way most editors handle namespaces. They always force you to add an extra pointless level of indentation. For instance, I have a lot of code in a page that I would much rather prefer formatted as namespace mycode{ class myclass{ void function(){ foo(); } void foo(){ bar(); } void bar(){ //code.. } } } and not something like namespace mycode{ class myclass{ void function(){ foo(); } void foo(){ bar(); } void bar(){ //code.. } } } Honestly, I don't really even like the class thing being indented most of the time because I usually only have 1 class per file. And it doesn't look as bad here, but when you get a ton of code and lot of scopes, you can easily have indentation that forces you off the screen, and plus here I just used 2-space tabs and not 4-space as is used by us. Anyway, is there some way to get Visual Studio to stop trying to indent namespaces for me like that?

    Read the article

  • Checklist for Launching public beta

    - by Vinayak
    I am developing a web app that is about to be opened for public beta. Does anyone know of or has prepared a checklist of the various steps that one needs to take to ensure a smooth beta implementation? The web app is coded using Java, MySQL on the server side and HTML, Javascript on the client side with a little Flash in one or two screens. I know this question is very non-specific, but I am looking for best practices/guidelines here. Thanks in advance.

    Read the article

  • Recommendations for 'C' Project architecture guidelines?

    - by SiegeX
    Now that I got my head wrapped around the 'C' language to a point where I feel proficient enough to write clean code, I'd like to focus my attention on project architecture guidelines. I'm looking for a good resource that coves the following topics: How to create an interface that promotes code maintainability and is extensible for future upgrades. Library creation guidelines. Example, when should I consider using static vs dynamic libraries. How to properly design an ABI to cope with either one. Header files: what to partition out and when. Examples on when to use 1:1 vs 1:many .h to .c Anything you feel I missed but is important when attempting to architect a new C project. Ideally, I'd like to see some example projects ranging from small to large and see how the architecture changes depending on project size, function or customer. What resource(s) would you recommend for such topics?

    Read the article

  • Observing an NSMutableArray for insertion/removal

    - by Adam Ernst
    A class has a property (and instance var) of type NSMutableArray with synthesized accessors (via @property). If you observe this array using: [myObj addObserver:self forKeyPath:@"theArray" options:0 context:NULL]; And then insert an object in the array like this: [[myObj theArray] addObject:[NSString string]]; An observeValueForKeyPath... notification is not sent. However, the following does send the proper notification: [[myObj mutableArrayValueForKey:@"theArray"] addObject:[NSString string]]; This is because mutableArrayValueForKey returns a proxy object that takes care of notifying observers. But shouldn't the synthesized accessors automatically return such a proxy object? What's the proper way to work around this--should I write a custom accessor that just invokes [super mutableArrayValueForKey...]?

    Read the article

  • Css attribute selector for input type="button" not working on IE7

    - by Cesar Lopez
    Hi all, I am working on a big form and it contains a lot of buttons all over the form, therefore I am trying to get working input[type="button"] in my main css file so it would catch all buttons with out having to add a class to every single one, for some reason this is not working on IE7, after checking on the web it says that IE7 should be supporting this. Also it has to be type="button" and not type="submit" as not all buttons will submit the form. Could anybody give a hint what am I doing wrong? input[type="button"]{ text-align:center; } I have also tried input[type=button] Any help would be very much apreciated.

    Read the article

  • 'AND' vs '&&' as operator

    - by ts
    Actually, i am facing a codebase where developpers decided to use 'AND' and 'OR' instead of '&&' and '||'. I know that there is difference in operators precedence (&& goes before 'and'), but with given framework (prestashop to be precise) is clearly not a reason. So, my question: which version are you using? Is 'and' more readable than '&&'? || there is ~ difference?

    Read the article

< Previous Page | 68 69 70 71 72 73 74 75 76 77 78 79  | Next Page >