Search Results

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

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

  • Use continue or Checked Exceptions when checking and processing objects

    - by Johan Pelgrim
    I'm processing, let's say a list of "Document" objects. Before I record the processing of the document successful I first want to check a couple of things. Let's say, the file referring to the document should be present and something in the document should be present. Just two simple checks for the example but think about 8 more checks before I have successfully processed my document. What would have your preference? for (Document document : List<Document> documents) { if (!fileIsPresent(document)) { doSomethingWithThisResult("File is not present"); continue; } if (!isSomethingInTheDocumentPresent(document)) { doSomethingWithThisResult("Something is not in the document"); continue; } doSomethingWithTheSucces(); } Or for (Document document : List<Document> documents) { try { fileIsPresent(document); isSomethingInTheDocumentPresent(document); doSomethingWithTheSucces(); } catch (ProcessingException e) { doSomethingWithTheExceptionalCase(e.getMessage()); } } public boolean fileIsPresent(Document document) throws ProcessingException { ... throw new ProcessingException("File is not present"); } public boolean isSomethingInTheDocumentPresent(Document document) throws ProcessingException { ... throw new ProcessingException("Something is not in the document"); } What is more readable. What is best? Is there even a better approach of doing this (maybe using a design pattern of some sort)? As far as readability goes my preference currently is the Exception variant... What is yours?

    Read the article

  • Check request type in Django

    - by Art
    While it is recommended to use the following construct to check whether request is POST, if request.method == 'POST': pass It is likely that people will find if request.POST: pass to be more elegant and concise. Are there any reasons not to use it, apart from personal preference?

    Read the article

  • What is the advantage of the 'src/main/java'' convention?

    - by Chris
    I've noticed that a lot of projects have the following structure: Project-A bin lib src main java RootLevelPackageClass.java I currently use the following convention (as my projects are 100% java): Project-A bin lib src RootLevelPackageClass.java I'm not currently using Maven but am wondering if this is a Maven convention or not or if there is another reason. Can someone explain why the first version is so popular these days and if I should adopt this new convention or not? Chris

    Read the article

  • PHP Serialize Function - Adding serialized data to mysql and then fetch and display

    - by Abhilash Shukla
    I want to know whether the PHP serialize function is 100% secure, also if we store serialized data into a database and want to do something after fetching it, will it be a nice way. For example:- I have a website with different user privileges, now i want to store the permissions settings for a particular privilege to my database (This data i want to store is to be done through php serialize function), now when a user logs in i want to fetch this data and set the privilege for the customer. Now i am ok to do this thing, what i want to know is, whether it is the best way to do or something more efficient can be done. Also, i was going through php manual and found this code, can anybody explain me a bit what's happening in this code:- [Specially why base64_encode is used?] <?php mySerialize( $obj ) { return base64_encode(gzcompress(serialize($obj))); } myUnserialize( $txt ) { return unserialize(gzuncompress(base64_decode($txt))); } ?> Also if somebody can provide me their own code to show me to do this thing in the most efficient manner. Thanks.

    Read the article

  • How do you assign a variable with the result of a if..else block?

    - by Pierre Olivier Martel
    I had an argument with a colleague about the best way to assign a variable in an if..else block. His orignal code was : @products = if params[:category] Category.find(params[:category]).products else Product.all end I rewrote it this way : if params[:category] @products = Category.find(params[:category]).products else @products = Product.all end This could also be rewritten with a one-liner using a ternery operator (? :) but let's pretend that product assignment was longer than a 100 character and couldn't fit in one line. Which of the two is clearer to you? The first solution takes a little less space but I thought that declaring a variable and assigning it three lines after can be more error prone. I also like to see my if and else aligned, makes it easier for my brain to parse it!

    Read the article

  • what is middleware exactly?

    - by michel
    I hear a lot of people talking last days about middleware, but what is the exact definition of middleware. If I look in information about middleware I found a lot of information and some definitions, but while reading this information and defintions it seems that mostly all 'wares' are in the middle of something. So from my opinion all things are middleware? or do you have an example of a ware that doesn't is middleware?

    Read the article

  • Safest way to change variable names in a project

    - by kamziro
    So I've been working on a relatively large project by myself, and I've come to realise that some of the variable names earlier on were.. less than ideal. But how does one change variable names in a project easily? Is there such a tool that can go through a project directory, parse all the files, and then replace the variable names to the desired one? It has to be smart enough to understand the language I imagine. I was thinking of using regexp (sed/awk on linux?) tools to just replace the variable name, but there were many times where my particular variable is also included as a part of strings. There's also the issue about changing stuff on a c++ namespace, because there is actually two classes in my project that share the same name, but are in different namespaces. I remember visual stuio being able to do this, but what's the safest and most elegant way to do this on linux?

    Read the article

  • What does 'foo' really mean?

    - by Prakash
    I hope this qualifies as a programming question, as in any programming tutorial, you eventually come across 'foo' in the code examples. (yeah, right?) what does 'foo' really mean? If it is meant to mean nothing, when did it begin to be used so? Cheers

    Read the article

  • What should the standard be for ReSTful URLS?

    - by gargantaun
    Since I can't find a chuffing job, I've been reading up on ReST and creating web services. The way I've interpreted it, the future is all about creating a web service for all your data before you build the web app. Which seems like a good idea. However, there seems to be a lot of contradictory thoughts on what the best scheme is for ReSTful URLs. Some people advocate simple pretty urls http://api.myapp.com/resource/1 In addition, some people like to add the API version to the url like so http://api.myapp.com/v1/resource/1 And to make things even more confusing, some people advocate adding the content-type to get requests http://api.myapp.com/v1/resource/1.xml http://api.myapp.com/v1/resource/1.json http://api.myapp.com/v1/resource/1.txt Whereas others think the content-type should be sent in the HTTP header. Soooooooo.... That's a lot of variation, which has left me unsure of what the best URL scheme is. I personally see the merits of the most comprehensive URL that includes a version number, resource locator and content-type, but I'm new to this so I could be wrong. On the other hand, you could argue that you should do "whatever works best for you". But that doesn't really fit with the ReST mentality as far as I can tell since the aim is to have a standard. And since a lot of you people will have more experience than me with ReST, I thought I'd ask for some guidance. So, with all that in mind... What should the standard be for ReSTful URLS?

    Read the article

  • Should I use fork or threads?

    - by shadyabhi
    In my script, I have a function foo which basically uses pynotify to notify user about something repeatedly after a time interval say 15 minutes. def foo: while True: """Does something""" time.sleep(900) My main script has to interact with user & does all other things so I just cant call the foo() function. directly. Whats the better way of doing it and why? Using fork or threads?

    Read the article

  • Consistency vs Design Guidelines

    - by Adrian Faciu
    Lets say that you get involved in the development of a large project that is already in development for a long period ( more than one year ). The projects follows some of the current design guidelines, but also has a few different, that are currently discouraged ( mostly at naming guidelines ). Supposing that you can't/aren't allowed to change the whole project: What should be more important, consistency, follow the existing ones and defy current guidelines or the usage of the guidelines, creating differences between modules of the same project ? Thanks.

    Read the article

  • Vim 80 column layout concerns

    - by cdleary
    I feel like the way I do 80-column indication in Vim is incorrect: set columns=80. At times I also set textwidth but I like to be able to see and anticipate line overflow with the set columns alternative. This has some unfortunate side effects -- I can't set number for fear of splitting between files that have different orders of line numbers; i.e. < 100 line files and = 100 line files will require two different set columns values because of the extra column used for the additional digit display. I also start new (g)Vim sessions instead of splitting windows vertically, which forces me to use the window manager's clipboard -- vsplits force me to do set columns every time I open or close a pane, so starting a new session is less hassle. How do you handle the 80-character indication when you want to set numbers, vertically split, etc.?

    Read the article

  • C#: Get a list of every value for a given key in a set of dictionaries?

    - by Rosarch
    How can I write this code more cleanly/concisely? /// <summary> /// Creates a set of valid URIs. /// </summary> /// <param name="levelVariantURIDicts">A collection of dictionaries of the form: /// dict["filePath"] == theFilePath </param> /// <returns></returns> private ICollection<string> URIsOfDicts(ICollection<IDictionary<string, string>> levelVariantURIDicts) { ICollection<string> result = new HashSet<string>(); foreach (IDictionary<string, string> dict in levelVariantURIDicts) { result.Add(dict["filePath"]); } return result; }

    Read the article

  • How do people handle working with Code Names for their projects?

    - by Mark
    Hi All, Recently we started using some code names for several different types of prototype applications all following a theme. This made things a little more fun and was a great idea. The problem is that Im not too sure how people deal with migrating a codebase from "codename" state into version 1.0 state which may have a proper name... not something that a client really shouldnt see :) We are using Visual Studio at the moment, and I can see that you can change the assembly name, but there are references to the namespaces, etc... that would really be a large change to make. Do people both changing things like namespaces before the v1.0 release?

    Read the article

  • What is the best way to use whitespace while programming?

    - by Emmanuel Smith
    I'm fairly new to programming and from learning I have seen different ways of formatting code, comments, etc; and have been recommended on different techniques. I mostly program in C#, C++, and Java so I want to know what is the the best way to layout code so that if other people where to go through it, they would be impressed by how simple and easy to understand it is. I would like to know the same thing for commenting as well.

    Read the article

  • best practice on precedence of variable declaration and error handling in C

    - by guest
    is there an advantage in one of the following two approaches over the other? here it is first tested, whether fopen succeeds at all and then all the variable declarations take place, to ensure they are not carried out, since they mustn't have had to void func(void) { FILE *fd; if ((fd = fopen("blafoo", "+r")) == NULL ) { fprintf(stderr, "fopen() failed\n"); exit(EXIT_FAILURE); } int a, b, c; float d, e, f; /* variable declarations */ /* remaining code */ } this is just the opposite. all variable declarations take place, even if fopen fails void func(void) { FILE *fd; int a, b, c; float d, e, f; /* variable declarations */ if ((fd = fopen("blafoo", "+r")) == NULL ) { fprintf(stderr, "fopen() failed\n"); exit(EXIT_FAILURE); } /* remaining code */ } does the second approach produce any additional cost, when fopen fails? would love to hear your thoughts!

    Read the article

  • How to properly document programming languages?

    - by roydukkey
    Where can I find information on how to properly document a programming language? What I mean is that there seems to be a standard way to document code. php.net and api.jquery.com seem to document there code the a similar way. For example, the trim() description on php.net. string trim ( string $str [, string $charlist ] ) And likewise on jquery.com .animate( properties, [ duration ], [ easing ], [ callback ] ) Does anyone even know what this syntax is called?

    Read the article

  • Are there any reasons to make all fields and variables final?

    - by Roman
    In my current project I noticed that all class fields and variable inside methods are declared with final modifier whenever it's possible. Just like here: private final XMLStreamWriter _xmlStreamWriter; private final Marshaller _marshaller; private final OutputStream _documentStream; private final OutputStream _stylesStream; private final XMLStreamWriter _stylesStreamWriter; private final StyleMerger _styleMerger; public DocumentWriter(PhysicalPackage physicalPackage) throws IOException { final Package pkg = new Package(physicalPackage); final Part wordDocumentPart = pkg.createPart( "/word/document.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"); // styles.xml final Pair<Part, String> wordStylesPart = wordDocumentPart.createRelatedPart(...); ... } Are there any reasons to do so? p.s. As I know project is not supposed to be multithreaded (at least I've heard nothing about it).

    Read the article

  • Should a connect method return a value?

    - by Matt S
    I was looking at some code I've inherited and I couldn't decided if I like a bit of code. Basically, there is a method that looks like the following: bool Connect(connection parameters){...} It returns true if it connects successfully, false otherwise. I've written code like that in the past, but now, when I see this method I don't like it for a number of reasons. Its easy to write code that just ignores the returned value, or not realize it returns a value. There is no way to return an error message. Checking the return of the method doesn't really look nice: if (!Connect(...)){....} I could rewrite code to throw an exception when it doesn't successfully connect, but I don't consider that an exceptional situation. Instead I'm thinking of refactoring the code as follows: void Connect(Connection Parameters, out bool successful, out string errorMessage){...} I like that other developers have to provide the success and error strings so they know the method has error conditions and I can know return a message Anyone have any thoughts on the matter? Thanks -Matt

    Read the article

  • Is there a way to set the minHeight of the scroll bar thumb in Flex 3

    - by Mad Oxyn
    In my project we needed to make the scollbars look like Windows scrollbars. Therefore I have a thumbIcon on the thumb of a vertical scrollbar, but if I get too many items in the combobox, the scrollbar gets fiddly. This is because the margin between the thumbIcon and the border of the thumbSkin is too small. Is there a way to set the minimum height of the thumbSkin so that I can ensure there is always a margin there and it always looks good, even if there are too many items? Image above, see the thumb? By the thumbIcon I mean the 3 horizontal lines. The top and bottom margin between this icon and the border of the thumb itself is too small. This is the normal scroll bar, the thumbIcon and the borders of the thumb have enough margin, which make the scroll bar look a lot better.

    Read the article

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