Tag Info

New answers tagged

0

I would write a mapper class and manually map the data from one type to the other. Yeah it's boilerplate, but you are fully in control, it's simple and it does the job. I would keep it out of the model assembly as your model objects shouldn't have any knowledge of the WCF returned types. public class FooMapper { public Foo Map(Bar bar) { ...


2

In all cases, I'd prefer #5. In the 1-2-3-4 sample of code, I think that the domain object doesn't have to know DTO objects related to him. Let's say you have public class User { ... some properties ... } public class UserThumbnail { ... some properties ... } A Domain Model object (User) doesn't have to know that a DTO object (UserThumbnail) ...


1

Normally I'd prefer #3 - GetBar is very obvious where its come from and what you're getting, but for this case, mapping classes I would often use the conversion operator. But.. mapping doesn't seem like you're casting, you're really creating something new that is not contained within the object (where I'd use GetBar), just converting it (operator bar). So ...


-2

If working in a compiled language excessive branching can mess with your processor's pipelining so if the 2 logical expressions are simple( e.g. "X<=10 & X >=1") you would be better off not using a short circuiting "and" (&&) or multiple if statements. But some optimizing compilers do this for you.


0

When designing an API for operations which may fail because of foreseeable reasons, but at unforeseeable times, one should generally allow a means by which callers can indicate whether they are expecting to cope with the semi-foreseeable failures. If the only methods which are available return with error codes rather than exceptions, then every call site ...


0

A library which is created for .NET Fw 4.0 (or before, down to 2.0) should be (in most real-world cases) usable from any 4.5 project (the opposite is not true). So as long as there is no compelling reason to upgrade a library to .NET Fw 4.5, I would recommend to stay at 4.0, at least as long as you have at least one project which is 4.5 based which uses that ...


3

The proper answer in 2014 is none of the above. First, that default file save location has no real meaning in life -- I suspect it is just Microsoft following their own rules about where programs should save things by default. As for how to deal with cross-cutting dependency projects, the right answer is to treat them as projects in their own right with ...


2

If newMethod never changes its value after initialization (it could be declared const or readonly, I guess), you should better write a standard private method. Using delegates without a reason can make the code confusing (at least in C#), even for experienced programmers. Comparing private Action<Enum, int, int> newMethod = (configField, fieldA, ...


1

A UUID is a standardised representation of a 128-bit number. As noted by AndyBursh, the representation is 32 hexadecimal digits, split into groups and separated by dashes. Nothing else is a proper UUID, it would just be a string. The point of a UUID is that it's "universally unique". If I just pick a string that I like the look of, then there's no ...


7

No. A UUID has a particular, standardised format. From the wiki article on the subject: In its canonical form, a UUID is represented by 32 lowercase hexadecimal digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and four hyphens).


1

Your UI should tell the database layer what operation to perform. In the UI, you will obviously have two buttons, one which says "Create new Person" and the other saying, "Edit this Person". So you already know what action needs to be performed. When you invoke the UI Dialog, pass in this state (Add or Edit) to the dialog. Then, based on the value of this ...


0

Does over-reliance on tools imply that you are lazy? Generally speaking, 'No'; but there is one big caveat. I started programming in C++ at uni and loved it. In the next term we changed to VB6 and I hated it. I could not tell what was going on, you drag a button to a form and the ide writes the code for you. Yes, indeed. Your experience at ...


1

I think you should make a distinction between comments and documentation. While comments are descriptive, they lack consistancy, they are scattered all over the code. Comments should never compensate for code which is not self-describing enough, instead it should hint other programmers at tricky parts. Whether code should be documented depends on the scale ...


4

How to document code? You already have a hint: look at how Java API is documented. More generally, there is no unique set of rules which apply to every project. When I work on business-critical large-scale projects, the documentation has nothing to do with the one I would write for a small open source library, which, in turn, has nothing to do with the ...


3

tl;dr I suggest static methods, or even instance methods can be alright depending on the objects you're working with and how long lived they are as well as how stateful they are. Do not use properties for this. Properties should be as idempotent as possible (repeated access should return the same result constantly). If A property needs to execute logic to ...


1

In general, it's easier for people to understand the conditional without the negation - it's one less thing to think about when deciphering the meaning of the condition. The performance difference will probably be negligible, and worrying about it is premature optimization. (Besides, if you're working in Python, this kind of micro-optimization is worthless; ...


0

Python optimizer is pretty stupid by design, but this is one case that the optimizer happens to be capable of detecting: >>> def a(): ... if foobar: ... pass ... >>> dis.dis(a) 2 0 LOAD_GLOBAL 0 (foobar) 3 POP_JUMP_IF_FALSE 9 3 6 JUMP_FORWARD 0 (to 9) ...


7

There is 0 difference. However, there are some guidelines about what you put in the if and what - in the else. One is that you should try to put a "positive" result in the if. Many languages have shorter negation than " not " (Java has "!" that shouldn't have whitespace around it), and it's easy to overlook them, especially if you're looking at a verbose ...


10

It is considered to be best practice to arrange the condition such that it is most probable to be entering your if clause. The <50% condition should be your else clause. In this instance, it depends on what you're expecting. If you expect to find the file, then you should use if os.path.isfile(file_name):. This reason stems back to optimization of ...


2

This is the problem closely related to the job scheduling. But there are two issues you have to consider: 1) Your clients are free to choose any job they want. They know when new jobs arrive and can pick any one they want. If you really want to control what they do you should really limit what they can know and reserve for processing. 2) Before really ...


2

If I understand your question correctly, I think the following approach should work: If a client ignores a notification once, because of its load, it ignores all following notifications too (even if the load decreases). From then on, it relies only on querying the database for old requests. Once all old requests are handled, it will start accepting ...


0

The advantage of "compiling as you go along" is you get constant feedback, and won't have a chance to go far wrong before being pushed in the right direction. For a competent programmer like you, that's not a huge consideration, but for many others it is. Put another way, "compiling as you go along" is a way of "minimizing the maximum loss," even though ...


0

Regarding the second interview, a benefit of compiling is that you can observe, within just a few seconds, what the programs does (or doesn't). From there it is easier to read the code and to focus your efforts on the relevant parts. Perhaps this is what the interviewer was expecting. Reading an unknown code base like this from beginning to end can be quite ...


1

I thought a bit longer about this, because I felt that there is something very, very wrong with the interviewer and couldn't exactly point out what it is. Here's the problem: For any code that I have written in the last twenty years, the amount of time needed to turn a workable algorithm into code that compiles has been minimal. Any gain in efficiency in ...


0

In my opinion and in my experience, whether or not a piece of code compiles is essentially random, involving things like whether or not semicolons are missing, and has little to do with the correctness of the underlying program. (To me, focusing on compiling is like running an article through a spell-check without proofreading to check the grammar.) My ...


2

Definitely yes, change variable names when relevant (especially variables whose scope is bigger than what fits in a screen). The name of a variable is an important part of its documentation! Computers (e.g. compilers) don't care about variable names. You could name all your variables like x01, x02 etc..., and the compiler nearly won't notice and the binary ...


4

Code is written to be executed by machine, but to be read by humans. The latter case is more important. By all means keep identifiers in the code as accurately reflecting their purpose as possible. Where I now am, a typical and legit kind of code review complaint is 'please rename this variable / function to be more descriptive'.


0

It is not only unreasonable, it is forbidden by the standard to modify a const variable. [dcl.type.cv]/4 tells (emphasize mine) : Except that any class member declared mutable (7.1.1) can be modified, any attempt to modify a const object during its lifetime (3.8) results in undefined behavior. The idea is still good. Declare a variable extern, and ...


2

For a sufficiently experienced programmer compiling code is never the bottleneck. Once you know a language well enough (i.e. when you no longer have to think about the syntax and instead just code for functionality) you tend not to make simple syntactical errors. Those you do make are usually typos or copy-paste bugs, and they can be cleaned up in short ...


2

Don't use volatile const, it sounds like nonsense! Instead, use a class/struct and initialize all variables in the constructor. You can still use const. Params.h: struct ConfigParams { const int param1; const int param2; // ... // Define a constructor that will load stuff from a configuration file. // Tune this to meet your needs, ...


8

The one important thing about compiling often, missing from other answers as far as I can see is this: if you compile rarely and get a large amount of compiler errors, most of those are meaningless, because they are generated by the first error. It could be because you had wrong type, or typo, or plain syntax error which makes some declaration invalid. You ...


0

In larger projects, with several subroutines, you want to test these parts, before using them in the larger scheme, since it is way easier to debug if you know certain parts already work. In order to test these smaller pieces, you need to compile. It might be that the interviewer confuses this situation with a small program that is not designed in this ...


1

You should read your parameters from a configuration file when the program starts. You can pass the file name on the command line. See this answer for information on using boost::property_tree to read a parameter file.


21

I think there is more than a little professional snobbery here. The implication seems to be "if you've never had the need to compile regularly then you've never worked with anything that complicated - go get some more experience and come back when you've learned to work exactly the way we do." But obviously there is another side to this. Some projects take ...


1

With a good development environment I see little reason to compile unless you're actually planning to test code. The background syntax checking tools catch most everything that the interviewer seems to be talking about, although I will admit there are still a few cases (involving changes that propagate across files) that aren't always fully identified. ...


3

No, it's not unreasonable to hold off compiling until you've done a sufficient amount of code (and a 'sufficient amount' depends on the coder and the code being written). For example, if you're an awesome coder who takes his time to get it right, and you're not writing massive amounts or convoluted code, then compiling regularly is a waste, and probably a ...


11

I actually agree with you that compiler errors should be no big deal for an experienced developer. I don't think the cost of fixing them increases significantly enough over time to worry about. If it were possible to postpone fixing all the compiler errors until just before a push, I would do so, as it would present a much smaller and more consolidated ...


13

I understand the benefits of testing your code as you go along, but why compiling? But how will you test your code as you go along when you don't compile accordingly? The extreme case is test-driven development (TDD). It is obvious that TDD does not work with your strategy, since TDD means extremely short cycles of write-test, compile (should fail), ...


18

There are merits to compiling as you go. But I very much agree that staying on task is an OK coding strategy. The most significant benefit to incremental compiling is the mentality many get in if they wait for the end to compile and test: we're more concerned at the end in getting the code to run than anything else at that point. We say "Oh, just need to ...


91

Compiling is a form of test, especially in languages which make extensive use of types such as Haskell or ML. In other languages it's a syntactic scan that tells you little. Having said that, "compile as you go" seems to me a very situational habit. You could equally well be marked down for being "twitchy" for compiling more frequently than the ...


31

So my question is this: Is there something I missed? Yes: your mind is not a compiler. While a compiler can make n context switches per second, your mind cannot. The number of context switches your mind can make in a day depends on a number of factors like experience/familiarity with code base, how mentally immersed you are in the code, how clean the ...


183

Is there actually a benefit to compiling as you go along? There is. It gives you a shorter feedback loop - which in general, when designing (UI, writing software, visual design etc...) is a good thing. A short feedback loop means you can quickly fix errors early on, before they become more expensive to fix. To borrow your example, say you were coding ...


0

Usually, it helps to look at how others might have done something similar already, and see if that can be used. This is typically how patterns emerge in software (and some are then even formalized as 'design patterns'). I am most familiar with oData, and in ASP.NET, oData supports both client and server side limit. However, it is up to the servers to decide ...


1

I will not call it a "pattern" per se. It's only a convention that has stuck over the years with web developers. There is no benefit from naming a folder something else other than app, and vice versa. I can only think back to Rails when thinking of the start of this convention. I think it was a means to separate the app's source code from the cource code ...


0

Without being puritanical: prefer functional style. Most languages these days (.NET, Ruby, Python, Javascript, etc.) support and promote it (e.g. LINQ, underscorejs). It is exceedingly easy to read. var recentTopCustomers = OrderList .Where(o => o.Date >= DateTime.Now.AddDays(-5)) .Where(o => o.Amount > 1000) .OrderBy(o => ...


0

This is a much more difficult question than it first appears. There was a time when major projects would use only a handful of languages and tools, but no longer. For example, a typical project these days could easily use 10 or more languages, once you include browsers, code, scripting, make, configuration and so on, and there are literally hundreds of ...


2

https://github.com/github/linguist does pretty much exactly what you want: Linguist defines a list of all languages known to GitHub in a yaml file. In order for a file to be highlighted, a language and a lexer must be defined there. Most languages are detected by their file extension. For disambiguating between files with common extensions, we ...


1

Look at the Makefile and find out which compiler is used. If this is gcc, look at its rules for guessing the language. For scripting languages, look at the first line, the one that starts with #!. If it is not present, find in other scripts how the one you are examining is invoqued. Pay attention to how the $PATH variable is set.


0

I play music, and I am pretty sure that typing without errors is not much different than playing a song without making mistakes. Please have a look at that answer to the above question. Basically, it is not only sufficient to practice your typing skills, you should try to practice well. Of course, you rarely practice a single piece of code in order to ...


0

If I may suggest: Get a great keyboard After reading Jeff's Post about mechanical keyboards I decided to buy myself a mechanical keyboard as well. Not only am I firmly convinced that it speeds up typing and has a great ergonomy, it also noticably reduces typing errors I make. Secondary Advice Do you know your keyboard layout? Can you type without ...



Top 50 recent answers are included