Search Results

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

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

  • Is it wrong to use a boolean parameter to determine behavior?

    - by Ray
    I have seen a practice from time to time that "feels" wrong, but I can't quite articulate what is wrong about it. Or maybe it's just my prejudice. Here goes: A developer defines a method with a boolean as one of its parameters, and that method calls another, and so on, and eventually that boolean is used, solely to determine whether or not to take a certain action. This might be used, for example, to allow the action only if the user has certain rights, or perhaps if we are (or aren't) in test mode or batch mode or live mode, or perhaps only when the system is in a certain state. Well there is always another way to do it, whether by querying when it is time to take the action (rather than passing the parameter), or by having multiple versions of the method, or multiple implementations of the class, etc. My question isn't so much how to improve this, but rather whether or not it really is wrong (as I suspect), and if it is, what is wrong about it.

    Read the article

  • css - use universal '*' selector vs. html or body selector?

    - by Michael Durrant
    Applying styles to the body tag will be applied to the whole page, so body { font-family: Verdana } will be applied to the whole page. This could also be done with * {font-family: Verdana} which would apply to all elements and so would seem to have the same effect. I understand the principle that in the first instance the style is being applied to one tag, body for the whole page whereas in the second example the font is being applied against each individual html elements. What I am asking is what is the practical difference in doing that, what are the implications and what is a reason, situation or best practice that leads to using one over another. One side-effect is certainly speed (+1 Rob). I am most interested in the actual reason to choose one over the other in terms of functionality.

    Read the article

  • "static" as a semantic clue about statelessness?

    - by leoger
    this might be a little philosophical but I hope someone can help me find a good way to think about this. I've recently undertaken a refactoring of a medium sized project in Java to go back and add unit tests. When I realized what a pain it was to mock singletons and statics, I finally "got" what I've been reading about them all this time. (I'm one of those people that needs to learn from experience. Oh well.) So, now that I'm using Spring to create the objects and wire them around, I'm getting rid of static keywords left and right. (If I could potentially want to mock it, it's not really static in the same sense that Math.abs() is, right?) The thing is, I had gotten into the habit of using static to denote that a method didn't rely on any object state. For example: //Before import com.thirdparty.ThirdPartyLibrary.Thingy; public class ThirdPartyLibraryWrapper { public static Thingy newThingy(InputType input) { new Thingy.Builder().withInput(input).alwaysFrobnicate().build(); } } //called as... ThirdPartyLibraryWrapper.newThingy(input); //After public class ThirdPartyFactory { public Thingy newThingy(InputType input) { new Thingy.Builder().withInput(input).alwaysFrobnicate().build(); } } //called as... thirdPartyFactoryInstance.newThingy(input); So, here's where it gets touchy-feely. I liked the old way because the capital letter told me that, just like Math.sin(x), ThirdPartyLibraryWrapper.newThingy(x) did the same thing the same way every time. There's no object state to change how the object does what I'm asking it to do. Here are some possible answers I'm considering. Nobody else feels this way so there's something wrong with me. Maybe I just haven't really internalized the OO way of doing things! Maybe I'm writing in Java but thinking in FORTRAN or somesuch. (Which would be impressive since I've never written FORTRAN.) Maybe I'm using staticness as a sort of proxy for immutability for the purposes of reasoning about code. That being said, what clues should I have in my code for someone coming along to maintain it to know what's stateful and what's not? Perhaps this should just come for free if I choose good object metaphors? e.g. thingyWrapper doesn't sound like it has state indepdent of the wrapped Thingy which may itself be mutable. Similarly, a thingyFactory sounds like it should be immutable but could have different strategies that are chosen among at creation. I hope I've been clear and thanks in advance for your advice!

    Read the article

  • How can you learn to code faster? [closed]

    - by SDGator
    Possible Duplicate: How to Code Faster (Without Sacrificing Quality) I think I code pretty well. I'd say I'm in the top 20% of the folks doing what I do (ASIC verification using System Verilog). But, out of the folks that I admire and aspire to be like, the difference isn't so much quality of code, but the fact that they can pump out reams of good quality code very quickly. Of course, they've been at it far longer than I have. Is it possible to learn to code faster without compromising quality? Or is that something that only comes with time and experience?

    Read the article

  • How should I group these variables?

    - by stariz77
    I have a shape that will be defined by: char s_type; char color; double height; double width; These variables are scanned in from a request string sent to my server and passed into my printing function, which then prints out the shape. Currently they are just local variables sitting in my main(); however, I was wondering if there would be any advantage in creating a struct containing these variables, and then passing the struct to my printing function? or how else might I improve my program's structure/style, would passing a struct by reference have any kind of performance benefit if there were many requests and therefore many printing function calls? printer(char st, char cr, double ht, double wd); int main() { // Other main functionality. char s_type; char color; double height; double width; sscanf (serv_req, "GET /%c/%c/%lf/%lf", &s_type, &color, &height, &width); printer(s_type, color, height, width); // Other main functionality. return 0; } It seemed "neater" if I had a struct or something that didn't leave me with declarations in the middle of everything else going on in main. I'm interested in structure/style as well as performance. EDIT: didn't mean to put printer declaration inside main.

    Read the article

  • Vocabulary: Should I call this apply or map?

    - by Carlos Vergara
    So, I'm tasked with organizing the code and building a library with all the common code among our products. One thing that seems to happen all the time and I wanted to abstract is posted below in pseudocode, and I don't know how to call it (different products have different domain specific implementations and names for it) list function idk_what_to_name_it ( list list_of_callbacks, value common_parameter ): list list_of_results = new list for_each(callback in list_of_callbacks) list_of_results.push(callback(common_parameter)) end for_each return list_of_results end function Would you call this specific construct a list ListOfCallbacks.Map( value value_to_map) method or would it better be value Value.apply(list list_of_callbacks) I'm really curious about this kind of thing. Is there a standard guide for this stuff?

    Read the article

  • How will I know when my company is ready to receive an investment? [migrated]

    - by gunshor
    How will I know when my company is ready to receive an investment? I am starting a company and have bootstrapped it so far. I have produced four versions of the demo. The first fully-working version is underway. Getting this to a beta phase product will require capital, which requires an investment, which requires an investor, which requires I stop working on the product and go out and talk to people about it. The last time I raised money from investors, it took a while but I was successful. I don't want it to take a while. I want it to be brain dead simple for an investor to understand the value so that I can optimize the time I spend with the product. Is my logic flawed? What is the best way to approach raising money, while limiting both my time and risk? Thanks.

    Read the article

  • What's Your Method of not forgetting the end brackets, parentheses

    - by JMC Creative
    disclaimer: for simplicity sake, brackets will refer to brackets, braces, quotes, and parentheses in the couse of this question. Carry on. When writing code, I usually type the beginning and end element first, and then go back and type the inner stuff. This gets to be a lot of backspacing, especially when doing something with many nested elements like: jQuery(function($){$('#element[input="file"]').hover(function(){$(this).fadeOut();})); Is there a more efficient way of remembering how many brackets you've got open ? Or a second example with quotes: <?php echo '<input value="'.$_POST['name'].'" />"; ?>

    Read the article

  • Where to find common database abbreviations in Spanish

    - by jmh_gr
    I'm doing a little pro bono work for an organization in Central America. I'm ok at Spanish and my contacts are perfectly fluent but are not techincal people. Even if they don't care what I call some fields in a database I still want to make as clean a schema as possible, and I'd like to know what some typical abbreviations are for field / variable names in Spanish. I understand abbreviations and naming conventions are entirely personal. I'm not asking for the "correct" or "best" way to abbreviate database object names. I'm just looking for references to lists of typical abbreviations that would be easily recognizable to a techincally competent native Spanish speaker. I believe I am a decent googler but I've had no luck on this one. For example, in my company (where English is the primary language) 'Date' is always shortened to 'DT', 'Code' to 'CD', 'Item' to 'IT', etc. It's easy for the crowds of IT temp workers who revolve through on various projects to figure out that 'DT' stands for 'Date', 'YR' for 'Year', or 'TN' for 'Transaction' without even having to consult the official abbreviations list.

    Read the article

  • What is the possible disadvantage of putting declarations in inner blocks, instead of at beginning of function?

    - by shan23
    At the place where I work, there are explicit guidelines for placement of declarations of variables. According to that, it is required to put them at the global level and / or at the beginning of functions, and not in inner blocks (such as a for loop). Since they've been specified by persons more experienced than I am, I'm sure that there must be a good reason for it, but I cannot figure out what that might be. It would be nice to know if there are any compile time / run time advantages at having them declared at a bigger scope.

    Read the article

  • In C and C++, what methods can prevent accidental use of the assignment(=) where equivalence(==) is needed?

    - by DeveloperDon
    In C and C++, it is very easy to write the following code with a serious error. char responseChar = getchar(); int confirmExit = 'y' == tolower(responseChar); if (confirmExit = 1) { exit(0); } The error is that the if statement should have been: if (confirmExit == 1) As coded, it will exit every time, because the assignment of the confirmExit variable occurs, then confirmExit is used as the result of the expression. Are there good ways to prevent this kind of error?

    Read the article

  • Is the use of explicit ' == true' comparison always bad? [closed]

    - by Slomojo
    Possible Duplicate: Make a big deal out of == true? I've been looking at a lot of code samples recently, and I keep noticing the use of... if( expression == true ) // do something... and... x = ( expression == true ) ? x : y; I've tended to always use... x = ( expression ) ? x : y; and... if( expression ) // do something... Where == true is implicit (and obvious?) Is this just a habit of mine, and I'm being picky about the explicit use of == true, or is it simply bad practice?

    Read the article

  • When is it appropriate to use colour in a command-line application?

    - by marcoms
    Currently I have a command-line application in C called btcwatch. It has a -C option that it can receive as an argument that compares the current price of Bitcoin with a price that was stored beforehand with -S. Example output with this option is: $ btcwatch -vC # -v = verbose buy: UP $ 32.000000 USD (100.000000 -> 132.000000) sell: UP $ 16.000000 USD (100.000000 -> 116.000000) The dilemma is whether to use colour for the UP or DOWN string (green and red, respectively). Most command-line applications I know of (apart from git) stay away from colour in their output. In my desire for btcwatch to look and be quite "standard" (use of getopt, Makefiles, etc), I'm not sure if colour would look out of place in this situation.

    Read the article

  • SSD harddisks & programming

    - by Carra
    SSD harddisks have been on the rise lately. And I've been wondering if it's worth buying one as a programmer. Being able to save five minutes when starting my PC is fun but won't convince my boss. How does it impact a typical visual studio project containing hundreds of files? Compile times, accessing files, waiting for visual studio to do its thing... Are there any benchmarks that checked this? And ideally, how much time would one win each week by upgrading?

    Read the article

  • Is sending data to a server via a script tag an outdated paradigm?

    - by KingOfHypocrites
    I inherited some old javascript code for a website tracker that submits data to the server using a script url: var src = "http://domain.zzz/log/method?value1=x&value2=x" var e = document.createElement('script'); e.src = src; I guess the idea was that cross domain requests didn't haven't to be enabled perhaps. Also it was written back in 2005. I'm not sure how well XmlHttpRequests were supported at the time. Anyone could stick this on their website and send data to our server for logging and it ideally would work in most any browser with javascript. The main limitation is all the server can do is send back javascript code and each request has to wait for a response from the server (in the form of a generic acknowledgement javascript method call) to know it was received, then it sends the next. I can't find anyone doing this online or any metrics as to whether this faster or more secure than XmlHttpRequests. I don't know if this is just an old way of doing things or it's still the best way to send data to the server when you are mostly trying to send data one way and you need the best performance possible. So in summary is sending data via a script tag an outdated paradigm? Should I abandon in favor of using XmlHttpRequsts?

    Read the article

  • How to choose between Tell don't Ask and Command Query Separation?

    - by Dakotah North
    The principle Tell Don't Ask says: you should endeavor to tell objects what you want them to do; do not ask them questions about their state, make a decision, and then tell them what to do. The problem is that, as the caller, you should not be making decisions based on the state of the called object that result in you then changing the state of the object. The logic you are implementing is probably the called object’s responsibility, not yours. For you to make decisions outside the object violates its encapsulation. A simple example of "Tell, don't Ask" is Widget w = ...; if (w.getParent() != null) { Panel parent = w.getParent(); parent.remove(w); } and the tell version is ... Widget w = ...; w.removeFromParent(); But what if I need to know the result from the removeFromParent method? My first reaction was just to change the removeFromParent to return a boolean denoting if the parent was removed or not. But then I came across Command Query Separation Pattern which says NOT to do this. It states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, asking a question should not change the answer. More formally, methods should return a value only if they are referentially transparent and hence possess no side effects. Are these two really at odds with each other and how do I choose between the two? Do I go with the Pragmatic Programmer or Bertrand Meyer on this?

    Read the article

  • When creating a library for a simple program, what must I do to protect others from its lack of thread safety?

    - by DeveloperDon
    When creating a library for a simple program, is it more cost effective to make it thread safe or is there a way to detect the program's use in a multithreaded program and ASSERT() or otherwise determine (preferably at compile or link time) that it may create problems. Related help for this question would be automated tool support for finding potential problems with thread safety, programming language features that enforce it,

    Read the article

  • Bikeshedding: Placeholders in strings

    - by dotancohen
    I find that I sometimes use placeholders in strings, like this: $ cat example-apache <VirtualHost *:80> ServerName ##DOMAIN_NAME## ServerAlias www.##DOMAIN_NAME## DocumentRoot /var/www/##DOMAIN_NAME##/public_html </VirtualHost> Now I am sure that it is a minor issue if the placeholder is ##DOMAIN_NAME##, !!DOMAIN_NAME!!, {{DOMAIN_NAME}}, or some other variant. However, I now need to standardize with other developers on a project, and we all have a vested interest in having our own placeholder format made standard in the organization. Are there any good reasons for choosing any of these, or others? I am trying to quantify these considerations: Aesthetics and usability. For example, __dict__ may be hard to read as we don't know how many underscores are in there. Compatibility. Will some language try to do something funny with {} syntax in a string (such as PHP does with "Welcome to {$siteName} today!")? Actually, I know that PHP and Python won't, but others? Will a C++ preprocessor choke on ## format? If I need to store the value in some SQL engine, will it not consider something a comment? Any other pitfalls to be wary of? Maintainability. Will the new guy mistake ##SOME_PLACEHOLDER## as a language construct? The unknown. Surely the wise folk here will think of other aspects of this decision that I have not thought of. I might be bikeshedding this, but if there are real issues that might be lurking then I would certainly like to know about them before mandating that our developers adhere to a potentially-problematic convention.

    Read the article

  • Checking negative of a condition

    - by oym
    What is the (slightly pejorative) term for checking the negative of a condition (rather than the positive which is often more readable): e.g. if(!someVar) { return null; } else { return doSomethingInteresting(); } instead of doing this (which is arguably more readable) if(someVar) { return doSomethingInteresting(); } else { return null; } I vaguely remember there being a term for this; something in the same spirit as the term Yoda conditions.

    Read the article

  • Placeholders in strings

    - by dotancohen
    I find that I sometimes use placeholders in strings, like this: $ cat example-apache <VirtualHost *:80> ServerName ##DOMAIN_NAME## ServerAlias www.##DOMAIN_NAME## DocumentRoot /var/www/##DOMAIN_NAME##/public_html </VirtualHost> Now I am sure that it is a minor issue if the placeholder is ##DOMAIN_NAME##, !!DOMAIN_NAME!!, {{DOMAIN_NAME}}, or some other variant. However, I now need to standardize with other developers on a project, and we all have a vested interest in having our own placeholder format made standard in the organization. Are there any good reasons for choosing any of these, or others? I am trying to quantify these considerations: Aesthetics and usability. For example, __dict__ may be hard to read as we don't know how many underscores are in there. Compatibility. Will some language try to do something funny with {} syntax in a string (such as PHP does with "Welcome to {$siteName} today!")? Actually, I know that PHP and Python won't, but others? Will a C++ preprocessor choke on ## format? If I need to store the value in some SQL engine, will it not consider something a comment? Any other pitfalls to be wary of? Maintainability. Will the new guy mistake ##SOME_PLACEHOLDER## as a language construct? The unknown. Surely the wise folk here will think of other aspects of this decision that I have not thought of. I might be bikeshedding this, but if there are real issues that might be lurking then I would certainly like to know about them before mandating that our developers adhere to a potentially-problematic convention.

    Read the article

  • Estimates, constraint and design [closed]

    - by user65964
    For your next two software projects (assuming that you're getting programming assignments, otherwise consider the program to find the min and max of a set of rational numbers) estimate how much effort they would take before doing them, then keep track of the actual time spent. How accurate were your estimates? State the requirements, constraint, design, estimate (your original estimate and the actual time it took), implementation (conventions used, implement/test path followed.

    Read the article

  • Accepting a numerical range in a function call

    - by dekpos
    I have encountered two ways of doing it: void foo(int from, int to); /* 'from' inclusive, 'to' exclusive */ void foo(int startIndex, int rangelength); Has one style historically been preferred over the other? If so, was it just a matter of convention or was it due to some deeper underlying reason? I'm currently programming in Java and noticed that the Arrays class uses the former style. The exclusivity of the to argument felt somewhat unintuitive to me, which led me to ask this question.

    Read the article

  • Should Equality be commutative within a Class Hierachy?

    - by vossad01
    It is easy to define the Equals operation in ways that are not commutative. When providing equality against other types, there are obviously situations (in most languages) were equality not being commutative is unavoidable. However, within one's own inheritance hierarchy where the root base class defines an equality member, a programmer has more control. Thus you can create situations where (A = B) ? (B = A), where A and B both derive from base class T Substituting the = with the appropriate variation for a given language. (.Equals(_), ==, etc.) That seems wrong to me, however, I recognize I may be biased by background in Mathematics. I have not been in programming long enough to know what is standard/accepted/preferred practice when programming. Do most programmers just accept .Equals(_)may not be commutative and code defensibly. Do they expect commutativity and get annoyed if it is not. In short, when working in a class hierarchy, should effort me made to ensure Equality is commutative?

    Read the article

  • Naming the implementation version of an interface function

    - by bolov
    When I need to write an implementation version of an interface function, I put the implementation function within a impl namespace, but with the same name as the interface function. Is this a bad practice? (the same name part, the namespace part I am confident it’s more than OK). For me, who I write the code, there is no confusion between the two, but I want to make sure this isn’t confusing for someone else. One other option would be to append impl suffix to the function name, but since it is already in a separate namespace named impl it seems redundant. Is there an idiomatic way to do this? E.g.: namespace n { namespace impl { // implementation function (hidden from users) // same name, is it ok? void foo() { // ... //sometimes it needs to call recursively or to call overloads of the interface version: foo(); // calls the implementation version. Is this confusing? n::foo(); // calls the interface version. Is this confusing? // ... } // namespace impl // interface function (exposed to users) void foo() { impl::foo(); } } // namespace n

    Read the article

  • Array sum of difference of first smallest k elment

    - by prateeak ojha
    Hi i come across this challenge on an online programing challange the task is so simple for ex WE have to variable N and K where N is where N is lenght of array and we have to find sum of duiffrence of K smallest element of array as Sample Input 10 4 1 2 3 4 10 20 30 40 100 200 Sample Output 10 Explanation #0 We have 10 as N size of array and K is 4 here the next N values are array's elments in order to find sum of diffrences we will takek smallest values from array which are 1,2,3,4 then will perform operation(sum of difference) as |1-2| + |1-3| + |1-4| + |2-3| + |2-4| + |3-4| = 10 I tried solving the problem and found a way through which i can solve the problem wit N^3 complexity but my solution is rejected i need a approach to solve the problem with n complexity i still can't figure out a way .. looked at some solution but coud'nt find the exact way to approach. if anybody have a better idea and would like to share it would be appreciable thanks in advance

    Read the article

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