Search Results

Search found 4835 results on 194 pages for 'coding hero'.

Page 26/194 | < Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >

  • Best way to integrate StyleCop with TFS CI

    - by Slavo
    I've been doing research on how to enable source analysis for the project I'm working on and plan to use StyleCop. The setup I have is a TFS Server for source control, using TFS Continuous Integration. I want to enable source analysis for CI builds and daily builds run on the build machine, and not only for those run on developers' machines. Here's an article from the documentation of StyleCop that I read on the subject: http://blog.newagesolution.net/2008/07/how-to-use-stylecop-and-msbuild-and.html. It basically modifies the csproj file for the purpose. I've also read other opinions about how StyleCop should be integrated with build automation, which advise doing the same thing using build tasks: http://blog.newagesolution.net/2008/07/how-to-use-stylecop-and-msbuild-and.html http://freetodev.spaces.live.com/blog/cns!EC3C8F2028D842D5!400.entry. What are you opinions? Have you had similar projects and done something like this?

    Read the article

  • Integrate StyleCop in NAnt buildscript

    - by stmax
    Is there a way to integrate StyleCop in a NAnt script such that the build fails if there are too many style violations? There doesn't seem to be a NAnt task for StyleCop, but we've found StyleCopCmd. However this only seems to generate an XML file as output that we'd have to parse. Is there some easier solution?

    Read the article

  • How to integrate KVC in MVC?

    - by Paperflyer
    So I have an MVC-application in Cocoa. There are some custom views, a controller and a model. Of course, the views need to know some stuff, so they get their data from the controller. However, they do not use accessors in the controller, they use KVC with a keypath that calls right through to the model: // In view.m time = [timeSource valueForKeyPath:@"theModel.currentTime"]; // timeSource is a pseudo-delegate of the view that holds the controller This simplifies things a great deal and technically, the views still don't know the model in person (that is, in pointer). But of course, they access it directly. Is that a usual (or at least sensible) usage of KVC and MVC? Or how would you implement this kind of communication?

    Read the article

  • Javascript file as an anonymous function

    - by Andrew Kou
    I have been reading a lot of Javascript lately and I have been noticing that the whole file is wrapped like the following in the .js files to be imported. (function() { ... code ... })() What is the reason for doing this rather than a simple set of constructor functions?

    Read the article

  • Why use short-circuit code?

    - by Tim Lytle
    Related Questions: Benefits of using short-circuit evaluation, Why would a language NOT use Short-circuit evaluation?, Can someone explain this line of code please? (Logic & Assignment operators) There are questions about the benefits of a language using short-circuit code, but I'm wondering what are the benefits for a programmer? Is it just that it can make code a little more concise? Or are there performance reasons? I'm not asking about situations where two entities need to be evaluated anyway, for example: if($user->auth() AND $model->valid()){ $model->save(); } To me the reasoning there is clear - since both need to be true, you can skip the more costly model validation if the user can't save the data. This also has a (to me) obvious purpose: if(is_string($userid) AND strlen($userid) > 10){ //do something }; Because it wouldn't be wise to call strlen() with a non-string value. What I'm wondering about is the use of short-circuit code when it doesn't effect any other statements. For example, from the Zend Application default index page: defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); This could have been: if(!defined('APPLICATION_PATH')){ define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); } Or even as a single statement: if(!defined('APPLICATION_PATH')) define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); So why use the short-circuit code? Just for the 'coolness' factor of using logic operators in place of control structures? To consolidate nested if statements? Because it's faster?

    Read the article

  • Using Objective-C Blocks

    - by Sean
    Today I was experimenting with Objective-C's blocks so I thought I'd be clever and add to NSArray a few functional-style collection methods that I've seen in other languages: @interface NSArray (FunWithBlocks) - (NSArray *)collect:(id (^)(id obj))block; - (NSArray *)select:(BOOL (^)(id obj))block; - (NSArray *)flattenedArray; @end The collect: method takes a block which is called for each item in the array and expected to return the results of some operation using that item. The result is the collection of all of those results. (If the block returns nil, nothing is added to the result set.) The select: method will return a new array with only the items from the original that, when passed as an argument to the block, the block returned YES. And finally, the flattenedArray method iterates over the array's items. If an item is an array, it recursively calls flattenedArray on it and adds the results to the result set. If the item isn't an array, it adds the item to the result set. The result set is returned when everything is finished. So now that I had some infrastructure, I needed a test case. I decided to find all package files in the system's application directories. This is what I came up with: NSArray *packagePaths = [[[NSSearchPathForDirectoriesInDomains(NSAllApplicationsDirectory, NSAllDomainsMask, YES) collect:^(id path) { return (id)[[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil] collect:^(id file) { return (id)[path stringByAppendingPathComponent:file]; }]; }] flattenedArray] select:^(id fullPath) { return [[NSWorkspace sharedWorkspace] isFilePackageAtPath:fullPath]; }]; Yep - that's all one line and it's horrid. I tried a few approaches at adding newlines and indentation to try to clean it up, but it still feels like the actual algorithm is lost in all the noise. I don't know if it's just a syntax thing or my relative in-experience with using a functional style that's the problem, though. For comparison, I decided to do it "the old fashioned way" and just use loops: NSMutableArray *packagePaths = [NSMutableArray new]; for (NSString *searchPath in NSSearchPathForDirectoriesInDomains(NSAllApplicationsDirectory, NSAllDomainsMask, YES)) { for (NSString *file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:searchPath error:nil]) { NSString *packagePath = [searchPath stringByAppendingPathComponent:file]; if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:packagePath]) { [packagePaths addObject:packagePath]; } } } IMO this version was easier to write and is more readable to boot. I suppose it's possible this was somehow a bad example, but it seems like a legitimate way to use blocks to me. (Am I wrong?) Am I missing something about how to write or structure Objective-C code with blocks that would clean this up and make it clearer than (or even just as clear as) the looped version?

    Read the article

  • Are endless loops in bad form?

    - by rlbond
    So I have some C++ code for back-tracking nodes in a BFS algorithm. It looks a little like this: typedef std::map<int> MapType; bool IsValuePresent(const MapType& myMap, int beginVal, int searchVal) { int current_val = beginVal; while (true) { if (current_val == searchVal) return true; MapType::iterator it = myMap.find(current_val); assert(current_val != myMap.end()); if (current_val == it->second) // end of the line return false; current_val = it->second; } } However, the while (true) seems... suspicious to me. I know this code works, and logically I know it should work. However, I can't shake the feeling that there should be some condition in the while, but really the only possible one is to use a bool variable just to say if it's done. Should I stop worrying? Or is this really bad form. EDIT: Thanks to all for noticing that there is a way to get around this. However, I would still like to know if there are other valid cases.

    Read the article

  • Lisp Style question label local functions or not?

    - by Andrew Myers
    I was wondering if there is a standard practice regarding the use of labels in Lisp. I've been messing around with a Lisp implementation of the algorithm described in the first answer here http://stackoverflow.com/questions/352203/generating-permutations-lazily My current version uses labels to break out portions of functionality. (defun next-permutation (pmute) (declare (vector pmute)) (let ((len (length pmute))) (if (> len 2) (labels ((get-pivot () (do ((pivot (1- len) (1- pivot))) ((or (= pivot 0) (< (aref pmute (1- pivot)) (aref pmute pivot))) pivot))) (get-swap (pivot) (let ((swp (1- len))) (loop for i from (1- len) downto pivot do (if (or (and (> (aref pmute i) (aref pmute (1- pivot))) (< (aref pmute i) (aref pmute swp))) (< (aref pmute swp) (aref pmute (1- pivot)))) (setf swp i))) swp)) (next (swp pivot) (rotatef (aref pmute (1- pivot)) (aref pmute swp)) (reverse-vector pmute pivot (1- len)))) (let ((piv (get-pivot))) (if (> piv 0) (next (get-swap piv) piv) nil)))))) Since each label is only called once I was wondering if this is considered bad practice since the only reason to do it in this case is for aesthetic reasons. I would argue that the current version with labels is clearer but that may go against common wisdom that I'm not aware of, being new to Lisp.

    Read the article

  • What is the C# static fields naming convention?

    - by Matt
    I have recently started using ReSharper which is a fantastic tool. Today I came across a naming rule for static fields, namely prefixing with an underscore ie. private static string _myString; Is this really the standard way to name static variables? If so is it just personal preference and style, or does it have some sort of lower level impact? Eg Compilation JIT etc? Where does this style originate from? I have always associated it with C++, is that correct?

    Read the article

  • When should I use Perl's AUTOLOAD?

    - by Robert S. Barnes
    In "Perl Best Practices" the very first line in the section on AUTOLOAD is: Don't use AUTOLOAD However all the cases he describes are dealing with OO or Modules. I have a stand alone script in which some command line switches control which versions of particular functions get defined. Now I know I could just take the conditionals and the evals and stick them naked at the top of my file before everything else, but I find it convenient and cleaner to put them in AUTOLOAD at the end of the file. Is this bad practice / style? If you think so why, and is there a another way to do it? As per brian's request I'm basically using this to do conditional compilation based on command line switches. I don't mind some constructive criticism. sub AUTOLOAD { our $AUTOLOAD; (my $method = $AUTOLOAD) =~ s/.*:://s; # remove package name if ($method eq 'tcpdump' && $tcpdump) { eval q( sub tcpdump { my $msg = shift; warn gf_time()." Thread ".threads->tid().": $msg\n"; } ); } elsif ($method eq 'loginfo' && $debug) { eval q( sub loginfo { my $msg = shift; $msg =~ s/$CRLF/\n/g; print gf_time()." Thread ".threads->tid().": $msg\n"; } ); } elsif ($method eq 'build_get') { if ($pipelining) { eval q( sub build_get { my $url = shift; my $base = shift; $url = "http://".$url unless $url =~ /^http/; return "GET $url HTTP/1.1${CRLF}Host: $base$CRLF$CRLF"; } ); } else { eval q( sub build_get { my $url = shift; my $base = shift; $url = "http://".$url unless $url =~ /^http/; return "GET $url HTTP/1.1${CRLF}Host: $base${CRLF}Connection: close$CRLF$CRLF"; } ); } } elsif ($method eq 'grow') { eval q{ require Convert::Scalar qw(grow); }; if ($@) { eval q( sub grow {} ); } goto &$method; } else { eval "sub $method {}"; return; } die $@ if $@; goto &$method; }

    Read the article

  • How to use Python list comprehension (or such) for retrieving rows when using MySQLdb?

    - by Erik Nygren
    Hey all, I use MySQLdb a lot when dealing with my webserver. I often find myself repeating the lines: row = cursor.fetchone() while row: do_processing(row) row = cursor.fetchone() Somehow this strikes me as somewhat un-pythonic. Is there a better, one-line way to accomplish the same thing, along the lines of inline assignment in C: while (row = do_fetch()) { do_processing(row); } I've tried figuring out the syntax using list comprehensions, but I can't seem to figure it out. Any recommendations? Thanks, Erik

    Read the article

  • indentation preference and personality

    - by dreftymac
    This question is similar in spirit to : http://stackoverflow.com/questions/492178/links-between-personality-types-and-language-technology-preferences But it is based specifically on indentation (spaces vs tabs and the number of spaces). The reason I am asking here instead of searching is because I remember seeing a specific document writing about this. If I remember correctly, it also talked about why Linus prefers eight spaces.

    Read the article

  • Is this good C# style?

    - by burnt1ce
    Consider the following method signature: public static bool TryGetPolls(out List<Poll> polls, out string errorMessage) This method performs the following: accesses the database to generate a list of Poll objects. returns true if it was success and errorMessage will be an empty string returns false if it was not successful and errorMessage will contain an exception message. Is this good style? Update: Lets say i do use the following method signature: public static List<Poll> GetPolls() and in that method, it doesn't catch any exceptions (so i depend the caller to catch exceptions). How do i dispose and close all the objects that is in the scope of that method? As soon as an exception is thrown, the code that closes and disposes objects in the method is no longer reachable.

    Read the article

  • Style: Dot notation vs. message notation in Objective-C 2.0

    - by groundhog
    In Objective-C 2.0 we got the "dot" notation for properties. I've seen various back and forths about the merits of dot notation vs. message notation. To keep the responses untainted I'm not going to respond either way in the question. What is your thought about dot notation vs. message notation for property accessing? Please try to keep it focused on Objective-C - my one bias I'll put forth is that Objective-C is Objective-C, so your preference that it be like Java or JavaScript aren't valid. Valid commentary is to do with technical issues (operation ordering, cast precedence, performance, etc), clarity (structure vs. object nature, both pro and con!), succinctness, etc. Note, I'm of the school of rigorous quality and readability in code having worked on huge projects where code convention and quality is paramount (the write once read a thousand times paradigm).

    Read the article

  • Should all public methods of an API be documented?

    - by cynicalman
    When writing "library" type classes, is it better practice to always write markup documentation (i.e. javadoc) in java or assume that the code can be "self-documenting"? For example, given the following method stub: /** * Copies all readable bytes from the provided input stream to the provided output * stream. The output stream will be flushed, but neither stream will be closed. * * @param inStream an InputStream from which to read bytes. * @param outStream an OutputStream to which to copy the read bytes. * @throws IOException if there are any errors reading or writing. */ public void copyStream(InputStream inStream, OutputStream outStream) throws IOException { // copy the stream } The javadoc seems to be self-evident, and noise that just needs to be updated if the funcion is changed at all. But the sentence about flushing and not closing the stream could be valuable. So, when writing a library, is it best to: a) always document b) document anything that isn't obvious c) never document (code should speak for itself!) I usually use b), myself (since the code can be self-documenting otherwise)...

    Read the article

  • Quick question - how to comment if-else structure?

    - by serg555
    Lets say you have: if(condition) { i = 1; } else { i = 2; } and you need to put comments explaining if and else blocks. What's the most readable way of doing it so someone can easily pick them up at first glance? I usually do it like this: //check for condition if(condition) { i = 1; } else { //condition isn't met i = 2; } which I find not good enough as comments are located at different levels, so at quick glance you would just pick up if comment and else comment would look like it belongs to some inner structure. Putting them like this: if(condition) { //check for condition i = 1; } else { //condition isn't met i = 2; } doesn't look good to me either as it would seem like the whole structure is not commented (condition might be big and take multiple lines). Something like that: //check for condition if(condition) { i = 1; //condition isn't met } else { i = 2; } would be probably the best style from comments point of view but confusing as a code structure. How do you comment such blocks?

    Read the article

  • Code Golf: Numeric Equivalent of an Excel Column-Name

    - by Vivin Paliath
    Can you figure out the numeric equivalent of an Excel column string in the shortest-possible way, using your favorite language? For example, the A column is 1, B is 2, so on and so forth. Once you hit Z, the next column becomes AA, then AB and so on. Rules: Here is some sample input and output: A: 1 B: 2 AD: 30 ABC: 731 WTF: 16074 ROFL: 326676 I don't know if the submitter is allowed to post a solution, but I have a Perl solution that clocks in at 125 characters :).

    Read the article

  • Is it proper to get and especially set Perl module's global variables directly?

    - by DVK
    I was wondering what the best practice in Perl is regarding getting - or, more importantly, setting - a global variable of some module by directly accessing $Module::varName in case the module didn't provide getter/setter method for it. The reason it smells bad to me is the fact that it sort of circumvents encapsulation. Just because I can do it in Perl, I'm not entirely certain I should (assuming there actually is an alternative such as adding a getter/setter to the module). I'm asking this because I'm about to request an addition of a getter/setter for a global variable in one of the core Perl modules, and I would like to avoid it soundly and unanimously rejected on the grounds of "Why the heck do you need one when you can access the variable in the package directly?" - in case doing the latter is actually considered perfectly OK by the community.

    Read the article

  • Recommendations for 'C' Project architecture guidlines?

    - 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? Thanks

    Read the article

  • Fluent API Style Usage

    - by Chris Dwyer
    When programming against a fluent API, I've seen the style mostly like this: var obj = objectFactory.CreateObject() .SetObjectParameter(paramName, value) .SetObjectParameter(paramName, value) .DoSomeTransformation(); What is the reasoning behind putting the dot at the beginning of the line instead of the end of the line like this: var obj = objectFactory.CreateObject(). SetObjectParameter(paramName, value). SetObjectParameter(paramName, value). DoSomeTransformation(); Or, is it merely a style thing that a team makes a consensus on?

    Read the article

  • Where should JavaScript be put?

    - by NessDan
    I've been doing a little JavaScript (well, more like jQuery) for a while now and one thing I've always been confused about is where I should put my scripts, in the <head> tag or in the <body> tag. If anyone could clarify this issue, that'd be great. An example of what should go where would be perfect.

    Read the article

  • if (condition) continue; OR if (!condition) { ... }? (style preference)

    - by Hosam Aly
    I know this is a matter of style, hence the subjective tag. I have a small piece of code, with two nested conditions. I could code it in two ways, and I'd like to see how more experienced developers think it should look like. Style 1: while (!String.IsNullOrEmpty(msg = reader.readMsg())) { RaiseMessageReceived(); if (parseMsg) { ParsedMsg parsedMsg = parser.parseMsg(msg); RaiseMessageParsed(); if (processMsg) { process(parsedMsg); RaiseMessageProcessed(); } } } Style 2: while (!String.IsNullOrEmpty(msg = reader.readMsg())) { RaiseMessageReceived(); if (!parseMsg) continue; ParsedMsg parsedMsg = parser.parseMsg(msg); RaiseMessageParsed(); if (!processMsg) continue; process(parsedMsg); RaiseMessageProcessed(); } (Side question: how do I put empty lines in the source code sample?)

    Read the article

< Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >