问:
Need help eliminating dead code paths and variables from C source code
I have a legacy C code on my hands, and I am given the task to filter dead/unused symbols and paths from it.  Over the time there were many insertions and deletions, causing lots of unused symbols. I have identified many dead variables which were only being written to once or twice, but were never being read from.

Both blackbox/whitebox/regression testing proved that dead code removal did not affected any procedures. (We have a comprehensive test-suite).

But this removal was done only on a small part of code. Now I am looking for some way to automate this work.

We rely on GCC to do the work.

P.S. I'm interested in removing stuff like:

variables which are being read just for the sake of reading from them.

variables which are spread across multiple source files and only being written to.

For example:

```<code>file1.c:
int i;

file2.c:
extern int i;
....
i=x;
</code>```

答:
You should check what clang's scan-build can do for your build. It can sometimes determine if a variable is only written to, but the results is never used (Dead store in scan-build's language).

The problem all these tools have is of course that they cannot determine if a call like

```<code>int status = do_something(input_var);
</code>```

does more than assigns some value to status, e.g. do_something might modify not only input_var, but also global state. So when cleaning out stuff make sure you check stuff that relies on side effects.

scan-build integrates nicely into make-based build process, e.g.

```<code>$ scan-build ./configure
$ scan-build make
</code>```

would run your code through scan-build when using autotools.

You could also try cppcheck, but in my experience it doesn't find more than what scan-build finds (and scan-build can find other issues which cppcheck cannot see).

Body:
You should check what clang's scan-build can do for your build. It can sometimes determine if a variable is only written to, but the results is never used (Dead store in scan-build's language).

The problem all these tools have is of course that they cannot determine if a call like

int status = do_something(input_var);

does more than assigns some value to status, e.g. do_something might modify not only input_var, but also global state. So when cleaning out stuff make sure you check stuff that relies on side effects.

scan-build integrates nicely into make-based build process, e.g.

$ scan-build ./configure
$ scan-build make

would run your code through scan-build when using autotools.

You could also try cppcheck, but in my experience it doesn't find more than what scan-build finds (and scan-build can find other issues which cppcheck cannot see).


问:
How to become a good team player?
I've been programming (obsessively) since I was 12.  I am fairly knowledgeable across the spectrum of languages out there, from assembly, to C++, to Javascript, to Haskell, Lisp, and Qi.  But all of my projects have been by myself.

I got my degree in chemical engineering, not CS or computer engineering, but for the first time this fall I'll be working on a large programming project with other people, and I have no clue how to prepare.  I've been using Windows all of my life, but this project is going to be very unix-y, so I purchased a Mac recently in the hopes of familiarizing myself with the environment.

I was fortunate to participate in a hackathon with some friends this past year -- both CS majors -- and excitingly enough, we won.  But I realized as I worked with them that their workflow was very different from mine.  They used Git for version control.  I had never used it at the time, but I've since learned all that I can about it.  They also used a lot of frameworks and libraries.  I had to learn what Rails was pretty much overnight for the hackathon (on the other hand, they didn't know what lexical scoping or closures were).  All of our code worked well, but they didn't understand mine, and I didn't understand theirs.

I hear references to things that real programmers do on a daily basis -- unit testing, code reviews, but I only have the vaguest sense of what these are.  I normally don't have many bugs in my little projects, so I have never needed a bug tracking system or tests for them.

And the last thing is that it takes me a long time to understand other people's code.  Variable naming conventions (that vary with each new language) are difficult (__mzkwpSomRidicAbbrev), and I find the loose coupling difficult.  That's not to say I don't loosely couple things -- I think I'm quite good at it for my own work, but when I download something like the Linux kernel or the Chromium source code to look at it, I spend hours trying to figure out how all of these oddly named directories and files connect.  It's a programming sin to reinvent the wheel, but I often find it's just quicker to write up the functionality myself than to spend hours dissecting some library.

Obviously, people who do this for a living don't have these problems, and I'll need to get to that point myself.

Question: What are some steps that I can take to begin "integrating" with everyone else?

Thanks!

答:
I'm going to pick out some of your sentences and make a couple of general points:

(on the other hand, they didn't know what lexical scoping or closures were). All of our code worked well, but they didn't understand mine, and I didn't understand theirs.

...

I hear references to things that real programmers do on a daily basis -- unit testing, code reviews, but I only have the vaguest sense of what these are. I normally don't have many bugs in my little projects, so I have never needed a bug tracking system or tests for them.

...

I spend hours trying to figure out how all of these oddly named directories and files connect ... I often find it's just quicker to write up the functionality myself than to spend hours dissecting some library.

I think the biggest single thing that you are going to need to learn is this:

For a given standard of developer ability, a team of n developers does less than n times the work that one of the developers could do alone - but they do still do more than any one person could.

The reason is simple: when working with other people, you must spend some of your time exchanging information with these other people; whereas when working alone, the information exchange all takes place in your head. Which naturally is quicker.

The other important thing is:

Some of your co-workers will be less able than you, certainly in some skills; some will even be less able than you in all skills

With these two ideas in mind, everything I've quoted above makes sense. Lots of people don't 'get' closures.The testing and code reviews are to ensure quality and decrease risk when code is bring produced by a group of people of mixed ability.  The bug tracking is because when you produce sufficiently large systems, bugs are inevitable. And the endless libraries with their conventions are because without conventions there is just too much code to learn or write it afresh every time you need it.

Really, I think the only way to learn how to work in a team is to actually do it; but hopefully the above will help you mentally prepare. Good luck!

ContentLicense: CC BY-SA 3.0

Title: How to become a good team player?


答:
The most efficient way is to become part of a team.

Joining a team might seem difficult, as I understand that you are not part of a team yet, like many students, and many people whose job is to work with no other developers around.

I would recommend you to take part in an open-source project that is very active and favours frequent communication on modern open-to-all channels (issue tracker, mailing list, wiki, etc). Open communication is important because you will probably start by observing how other people interact, so avoid projects that rely on email between core developers, or non-archived IRC.

Prefer a project that seems welcoming, with several quite-frequent contributors, rather than a project with 1 person who does everything. Also, prefer projects where anybody is allowed to touch to everything (rather than each developer having their delimited area), because it is more fun and offers more opportunities for communication.

Shameless plug: you are very welcome here!

Title: How to become a good team player?

Body:
I've been programming (obsessively) since I was 12.  I am fairly knowledgeable across the spectrum of languages out there, from assembly, to C++, to Javascript, to Haskell, Lisp, and Qi.  But all of my projects have been by myself.

I got my degree in chemical engineering, not CS or computer engineering, but for the first time this fall I'll be working on a large programming project with other people, and I have no clue how to prepare.  I've been using Windows all of my life, but this project is going to be very unix-y, so I purchased a Mac recently in the hopes of familiarizing myself with the environment.

I was fortunate to participate in a hackathon with some friends this past year -- both CS majors -- and excitingly enough, we won.  But I realized as I worked with them that their workflow was very different from mine.  They used Git for version control.  I had never used it at the time, but I've since learned all that I can about it.  They also used a lot of frameworks and libraries.  I had to learn what Rails was pretty much overnight for the hackathon (on the other hand, they didn't know what lexical scoping or closures were).  All of our code worked well, but they didn't understand mine, and I didn't understand theirs.

I hear references to things that real programmers do on a daily basis -- unit testing, code reviews, but I only have the vaguest sense of what these are.  I normally don't have many bugs in my little projects, so I have never needed a bug tracking system or tests for them.

And the last thing is that it takes me a long time to understand other people's code.  Variable naming conventions (that vary with each new language) are difficult (__mzkwpSomRidicAbbrev), and I find the loose coupling difficult.  That's not to say I don't loosely couple things -- I think I'm quite good at it for my own work, but when I download something like the Linux kernel or the Chromium source code to look at it, I spend hours trying to figure out how all of these oddly named directories and files connect.  It's a programming sin to reinvent the wheel, but I often find it's just quicker to write up the functionality myself than to spend hours dissecting some library.

Obviously, people who do this for a living don't have these problems, and I'll need to get to that point myself.

Question: What are some steps that I can take to begin "integrating" with everyone else?

Thanks!


问:
Is committing/checking in code everyday a good practice?
I've been reading Martin Fowler's note on Continuous Integration and he lists as a must "Everyone Commits To the Mainline Every Day".

I do not like to commit code unless the section I'm working on is complete and that in practice I commit my code every three days: one day to investigate/reproduce the task and make some preliminary changes, a second day to complete the changes, and a third day to write the tests and clean it up^ for submission. I would not feel comfortable submitting the code sooner.

Now, I pull changes from the repository and integrate them locally usually twice a day, but I do not commit that often unless I can carve out a smaller piece of work.

Question: is committing everyday such a good practice that I should change my workflow to accomodate it, or it is not that advisable?

Edit: I guess I should have clarified that I meant "commit" in the CVS meaning of it (aka "push") since that is likely what Fowler would have meant in 2006 when he wrote this.

^ The order is more arbitrary and depends on the task, my point was to illustrate the time span and activities, not the exact sequence.

答:
If you're meaning "commit" as "merge into mainline", then you definitely should not be doing that everyday on a software project that's being released to the customers. You should be merging changes that are done and tested, so that the mainline is always working and releasable, and not in some broken state with half-finished features.

However, the luxury of working with today's distributed version control is that you can both keep mainline stable, and at the same time do your git/hg/whatever commit every time you feel you want to preserve the state of things. I do this once every few hours and definitely at the end of every day.

With DVCS, you can publish your work, collaborate on it with others in your team, and keep it up to date with changes in the mainline branch. You can do all this without polluting the stability of code your customers and/or other teams depend on.

In times when Subversion was the latest technology and there was no way to fork and merge feature branches without extreme pain, having a mainline where several different features were in simultaneous construction might have been the best approach. But this superiority does not scale beyond 2010.


答:
I won't reiterate what everybody else has already said to the effect of "just do it", but I'll add an additional point I've not seen mentioned: a good manager will really help you integrate in to the team.

While you may have all the right stuff about you for the programming part of the job, you could be missing some of the more inter-personal and software development related stuff. A good manager will guide you in to the teams practices (both in soft skills and hard skills) to help you gel, and will also hopefully tell you if you've done, or do, something that is in opposition to those practices; because you can't fix something you don't know is broken.

Title: How to become a good team player?


问:
Company PC refresh, laptop or desktop?
My company is getting PC refreshes with a choice of to have a desktop or laptop.  Each one seems to have its pros and cons. Would you want the flexibility and freedom of the laptop but take the risk of working extra hours at home? Or a desktop limited to one place, but not having to worry about taking work home and disrupting home time?

I'm not asking what would be better for coding, but more for convenience and productivity.  I currently have a desktop and work about 8 to 9 hours a day, with only coming in on the weekends for when we get behind on major deadlines. I love developing but I also have quite a busy life after work. I feel that having a work laptop will only haze the line of work and home.

答:
A desktop PC with dual monitors is the best work configuration IMHO.

If you need to work from a distance, the possibility of connecting remotely (via a VPN) can be very useful and obviate the need for a laptop.

ContentLicense: CC BY-SA 2.5

Title: Company PC refresh, laptop or desktop?


问:
Default Ant target: help or jar?
What would you choose as the default Ant target?

In the context of a small visual tool with a user interface, open source.

I was thinking about jar because the project's distributable is the jar file.

But someone prefers to have help as the default target, to show the available targets.

Or maybe another target? I doubt anyone would really care, but would be the "least surprise" choice?

答:
This is just personal preference - as any answer to this question is likely to be:

I tend to always have help as the default target. My reasoning is that unless you've looked at the build script or have used it before, you don't know what exactly you're going to get if you just calling the default target.

Even if your projects all use the same set of standard targets, there might be custom properties which will affect what you get out - e.g. build for debug/release, or create a signed/unsigned jar. I tend to have the default help target just display that non-standard info, alongside a couple of example usages.

Title: Default Ant target: help or jar?


问:
When designing a job queue, what should determine the scope of a job?
We've got a job queue system that'll cheerfully process any kind of job given to it. We intend to use it to process jobs that each contain 2 tasks:

Job (Pass information from one server to another)

Fetch task (get the data, slowly)

Send task (send the data, comparatively quickly)

The difficulty we're having is that we don't know whether to break the tasks into separate jobs, or process the job in one go.

Are there any best practices or useful references on this subject? Is there some obvious benefit to a method that we're missing?

So far we can see these benefits for each method:

Split

Job lease length reflects job length: Rather than total of two

Finer granularity on recovery: If we lose outgoing connectivity we can tell them all to retry

The starting state of the second task is saved to job history: Helps with debugging (although similar logging could be added in single task method)

Single

Single job to be scheduled: Less processing overhead

Data not stale on recovery: If the outgoing downtime is quite long, the pending Send jobs could be outdated

答:
First of all: why are these Fetch and Send tasks combined anyway?

If they depend on each other anyhow (use data from the other or have to be processed in a certain order), the "Job" should be atomic, be kept and processed together within the node.

On the other hand, if the "Job" is the representation of a communication unit on the receiver's side (like when nodes collect incoming and outgoing tasks in queues to the other node, and flush them regularly), then it is just a bucket of independent tasks that now happen to contain two items. In this case you should break up the "Job" (and rename to Envelope :-) ), and register the tasks individually in the job queue.

Performance optimization for queue management can wait until real issues. In a parallel queue processing environment, having one core working on a big job while the other cores are on idle is less efficient (and harder to scale up) compared to the relatively small overhead of more queue management.


答:
If I'm not mistaken, Gimpel's PC-Lint/FlexeLint is able to tell you if things are unused. I believe from when last I used it (many moons ago), it will pick out never-used variables, never-used functions, never-used headers, etc, etc.

It also has some kind of system for embedding tags to turn off it's warnings on particular lines of code, should you desire.

Note that when last I used this tool to find unused code paths, it was a multi-pass process - run tool, remove all unused stuff, run tool, find more unused stuff (because I'd just removed functions that were the only users of some other functions), etc, etc.

Kinda pricey, I'm afraid, but pretty good tools, and if you only need one license to get through this problem, rather than one per dev to integrate with your build, then it's not too bad. It looks like the PC licenses are much cheaper, so if only buying one for this job, I'd go for that.

Title: Need help eliminating dead code paths and variables from C source code

Body:
I have a legacy C code on my hands, and I am given the task to filter dead/unused symbols and paths from it.  Over the time there were many insertions and deletions, causing lots of unused symbols. I have identified many dead variables which were only being written to once or twice, but were never being read from.

Both blackbox/whitebox/regression testing proved that dead code removal did not affected any procedures. (We have a comprehensive test-suite).

But this removal was done only on a small part of code. Now I am looking for some way to automate this work.

We rely on GCC to do the work.

P.S. I'm interested in removing stuff like:

variables which are being read just for the sake of reading from them.

variables which are spread across multiple source files and only being written to.

For example:

```<code>file1.c:
int i;

file2.c:
extern int i;
....
i=x;
</code>```


问:
What tools do you use to manage requests from users?
I'm drowning in user emails and I'd like to implement a better way to manage all these requests I get and put them in a queue where those people on a team, as well as users, have access to them and can make common notes. I'm thinking about some sort of task management tool that would allow multiple tasks to be created under a project where emails, comments, ideas, etc. could be dropped/entered and easily accessible.

I need something that all parties can be involved in - users, managers, team leaders, developers. I'm looking for a tool that can allow:

Users to just drag/drop an email to submit a request for maintenance or enhancement.

Developers to just see their queue and the weighted priority of each task/project.

A team of developers to see what everyone is working on in real-time.

Management to keep a a log of time spent on each task.

I I am starting to look in more of a Agile/Scrum direction for solving this problem. I found list of scrum agile sofware project management open source tools. Since I am limited on time, has anyone used these? Which one should I test to see if it will meet my needs? TeamPulse is a good direction, but think it is a little too bloated. I need something simple for all parties.

答:
JIRA

$10 bucks for a standard license for 10 users (with proceeds going to charity).   Worth every penny -- I use it to track features, bugs, releases, etc -- for multiple projects.  It's extremely easy to use and setup.  And Atlassian has a lot of other tools that integrate well with it (and the standard license for those are just as cheap!) -- GreenHopper, Bamboo, etc.

Based on your criteria:

I think I am starting to look in more of a Agile/Scrum direction for solving this problem.

See GreenHopper integration

Users to just drag/drop an email to submit a request for maintenance or enhancement.

Creating Issues from Emails

Developers to just see their queue and the weighted priority of each task/project.

A team of developers to see what everyone is working on in real-time.

See above.

Management to keep a a log of time spent on each task.

Logging work on an issue


问:
I've inherited 200K lines of spaghetti code -- what now?
I hope this isn't too general of a question; I could really use some seasoned advice.

I am newly employed as the sole "SW Engineer" in a fairly small shop of scientists who have spent the last 10-20 years cobbling together a vast code base. (It was written in a virtually obsolete language: G2 -- think Pascal with graphics). The program itself is a physical model of a complex chemical processing plant; the team that wrote it have incredibly deep domain knowledge but little or no formal training in programming fundamentals. They've recently learned some hard lessons about the consequences of non-existant configuration management. Their maintenance efforts are also greatly hampered by the vast accumulation of undocumented "sludge" in the code itself. I will spare you the "politics" of the situation (there's always politics!), but suffice to say, there is not a consensus of opinion about what is needed for the path ahead.

They have asked me to begin presenting to the team some of the principles of modern software development. They want me to introduce some of the industry-standard practices and strategies regarding coding conventions, lifecycle management, high-level design patterns, and source control. Frankly, it's a fairly daunting task and I'm not sure where to begin.

Initially, I'm inclined to tutor them in some of the central concepts of The Pragmatic Programmer, or Fowler's Refactoring ("Code Smells", etc). I also hope to introduce a number of Agile methodologies. But ultimately, to be effective, I think I'm going to need to hone in on 5-7 core fundamentals; in other words, what are the most important principles or practices that they can realistically start implementing that will give them the most "bang for the buck".

So that's my question: What would you include in your list of the most effective strategies to help straighten out the spaghetti (and prevent it in the future)?

答:
Questions like these are the whole reason the Software Carpentry project exists.

For the last 14 years, we've been teaching scientists and engineers basic software development skills: version control, testing, how to modularize code, and so on. All our materials are freely available under a Creative Commons license, and we run a couple of dozen free two-day workshops every year to help people get started.

Based on that, I think the best starting point is probably Robert Glass's excellent (short) book Facts and Fallacies of Software Engineering: its evidence-based approach is a good way to convince scientists that what we're telling them about good programming practices is more than just opinion.

As for specific practices, the two that people are most willing to adopt are version control and unit testing; once those are in place, they can tackle the kind of systematic refactoring that Michael Feathers describes in Working Effectively With Legacy Code.

I no longer recommend The Pragmatic Programmer (lots of exhortation, hard for novices to put into practice), and I think McConnell's Code Complete is too much to start with (though it's a great thing to give them six months or a year in, once they've mastered the basics).

I would also highly recommend Paul Dubois' excellent paper "Maintaining Correctness in Scientific Programs" (Computing in Science & Engineering, May-June 2005), which describes a "defense in depth" approach that combines a dozen different practices in a logical, coherent way.


问:
Best practices for web page styling with CSS?
I have a website to design. I have information on how the page should look and interact. The problem is I'm not good in front-end design, and have put many many hours to get the hang of the stuff. Currently I use the CSS from sample sites in github to style my site, which seems to be an un-ethical way.

Question:  how do you style webpages?

Are there some really good tools?

I would be deeply appreciated if a detailed answer will be provided or link to wiki will work as well.

答:
Most web developers will use a combination of some editor (whether that be a tool like Dreamweaver or something as simple as notepad) and a web browser. They go through a process of building up the markup and style rules piece by piece, refreshing the browser at each stage to see if it looks and behaves how they're intending. Outside of an editor and a browser, there aren't really any special tools required for frontend web development, however there are tools like Firebug which are extremely helpful.

It sounds like you need to properly learn CSS, so you can write it yourself. There are loads of good places to learn and reference on the internet, but my personal favourite is http://www.w3schools.com/css/.


答:
Most true web developers will be writing their own CSS and HTML from scratch. Tools can be useful in testing or tuning CSS rules, but anything that claims to do it for you is more trouble than it's worth.

Learning to properly use HTML and CSS is something that takes time, just like learning any other technology. There's no shortcut; practice will get you there.

With that said, some WYSIWYG editors, like Dreamweaver, have support for editing CSS rules which provides autocomplete. I found this very useful when I was first starting off (hit ctrl + space to see a list of all possible CSS rules).

Title: Best practices for web page styling with CSS?

Body:
I have a website to design. I have information on how the page should look and interact. The problem is I'm not good in front-end design, and have put many many hours to get the hang of the stuff. Currently I use the CSS from sample sites in github to style my site, which seems to be an un-ethical way.

Question:  how do you style webpages?

Are there some really good tools?

I would be deeply appreciated if a detailed answer will be provided or link to wiki will work as well.


答:
In Team Foundation Server you can 'Shelve' which is not the same as a check in, but just makes a backup of your code so that if your machine dies you have not lost the changes.

I have also seen software houses that have a 'developer line' and a 'mainline'. Devs are free to check in to the developer line whenever they deem fit and only the team leader has access to the mainline so they are responsible for copying code from dev to main when it is production ready.

Title: Is committing/checking in code everyday a good practice?

Body:
I've been reading Martin Fowler's note on Continuous Integration and he lists as a must "Everyone Commits To the Mainline Every Day".

I do not like to commit code unless the section I'm working on is complete and that in practice I commit my code every three days: one day to investigate/reproduce the task and make some preliminary changes, a second day to complete the changes, and a third day to write the tests and clean it up^ for submission. I would not feel comfortable submitting the code sooner.

Now, I pull changes from the repository and integrate them locally usually twice a day, but I do not commit that often unless I can carve out a smaller piece of work.

Question: is committing everyday such a good practice that I should change my workflow to accomodate it, or it is not that advisable?

Edit: I guess I should have clarified that I meant "commit" in the CVS meaning of it (aka "push") since that is likely what Fowler would have meant in 2006 when he wrote this.

^ The order is more arbitrary and depends on the task, my point was to illustrate the time span and activities, not the exact sequence.


答:
There are several different approaches, each with its up- and downsides, and most of them are tied to a particular workflow.

In large teams, where the work is divided into 'graphics design', 'interaction design', 'slicing', 'front-end scripting', and 'back-end coding', each job performed by a different person, the CSS part is the job of the person who does the slicing, and because that person controls both the HTML and the CSS, they can do it pretty much as they like. Often, they use tools like Dreamweaver; this allows for WYSIWYG editing, but the resulting HTML/CSS is often kind of messy and hard to maintain - which is OK if the process demands setting the design in stone before writing any code: once handed to the coders, the design isn't going to change, so there is little point in spending extra effort on maintainability.

Often, however, teams are smaller, and the site needs to be more dynamic and more maintainable. In such a situation, it is important to write scalable and adaptable CSS. What I found works reasonably well is this:

Start with a few 'reset' rules. You can use a pre-written general-purpose reset stylesheet (google for them, there are a bunch of good ones available on the net), or you can write some simple rules yourself. Some people don't believe in reset stylesheets; it's a matter of taste and philosophy really, so you may want to just overrule the default appearance of those elements that you don't like.

Keep your HTML semantic, that is, write it so that it reflects the structure of your document, not the appearance. Load the HTML without any stylesheet at all. It doesn't have to look as intended yet, but it should present itself in a logical structure.

Create the general style by writing rules matching on element names (div, dd, input, a, ...) and, where needed, pseudo-elements / pseudo-classes (a:hover, a:visited, ...), and attribute selectors (you need those to distinguish between different types of inputs, e.g. input[type=text]). Try them out on a generic piece of HTML, e.g. the output of http://loripsum.net/. This is going to be your default appearance; most of your site should look good with these rules alone.

Now you have some site elements left that don't look as you want them yet. For those, add class names that describe, semantically, what the element is (or one aspect of what it is). Examples are things like <input type="submit" class="default-button"/>,
, etc. Don't use class names to describe presentational properties (,
): those tend to diverge from the actual rules over time, and then you end up with class float-right being floated to the left or some such nonsense. Style those elements based on their class names. For example, if your default button should be larger, you'd use .default-button { font-size: larger; } (or a percentage if you like those better).

Avoid inline styles at all costs.

Develop on a sane browser (firefox, or anything webkit-based); once you have it all working, test it on at least Firefox, Webkit, and Opera. It's probably going to break on IE; use conditional comments to include extra stylesheets for various IE versions you have to support, adding whatever hacks you need to make it work.

As far as tools go; you don't really need more than a text editor and a browser to test in. Firebug or an equivalent document inspector plugin is a great help (Google Chrome / Chromium has a similar tool built into it), especially since it allows you to modify styles inside the browser - they won't persist, but you can quickly try out things to see what works.

On the server side, there are a few technologies that allow you to take shortcuts - basically, they take a stylesheet written in a superset of CSS, adding things like variables, nested rules, etc., and transform it into regular CSS before sending it to the browser. The cassius and lucius template languages (for Haskell) are nice examples, but solutions exist for many programming languages.

Body:
There are several different approaches, each with its up- and downsides, and most of them are tied to a particular workflow.

In large teams, where the work is divided into 'graphics design', 'interaction design', 'slicing', 'front-end scripting', and 'back-end coding', each job performed by a different person, the CSS part is the job of the person who does the slicing, and because that person controls both the HTML and the CSS, they can do it pretty much as they like. Often, they use tools like Dreamweaver; this allows for WYSIWYG editing, but the resulting HTML/CSS is often kind of messy and hard to maintain - which is OK if the process demands setting the design in stone before writing any code: once handed to the coders, the design isn't going to change, so there is little point in spending extra effort on maintainability.

Often, however, teams are smaller, and the site needs to be more dynamic and more maintainable. In such a situation, it is important to write scalable and adaptable CSS. What I found works reasonably well is this:

Start with a few 'reset' rules. You can use a pre-written general-purpose reset stylesheet (google for them, there are a bunch of good ones available on the net), or you can write some simple rules yourself. Some people don't believe in reset stylesheets; it's a matter of taste and philosophy really, so you may want to just overrule the default appearance of those elements that you don't like.

Keep your HTML semantic, that is, write it so that it reflects the structure of your document, not the appearance. Load the HTML without any stylesheet at all. It doesn't have to look as intended yet, but it should present itself in a logical structure.

Create the general style by writing rules matching on element names (div, dd, input, a, ...) and, where needed, pseudo-elements / pseudo-classes (a:hover, a:visited, ...), and attribute selectors (you need those to distinguish between different types of inputs, e.g. input[type=text]). Try them out on a generic piece of HTML, e.g. the output of http://loripsum.net/. This is going to be your default appearance; most of your site should look good with these rules alone.

Now you have some site elements left that don't look as you want them yet. For those, add class names that describe, semantically, what the element is (or one aspect of what it is). Examples are things like <input type="submit" class="default-button"/>, <div class="validation-errors">, etc. Don't use class names to describe presentational properties (<span class="red large">, <div class="float-right">): those tend to diverge from the actual rules over time, and then you end up with class float-right being floated to the left or some such nonsense. Style those elements based on their class names. For example, if your default button should be larger, you'd use .default-button { font-size: larger; } (or a percentage if you like those better).

Avoid inline styles at all costs.

Develop on a sane browser (firefox, or anything webkit-based); once you have it all working, test it on at least Firefox, Webkit, and Opera. It's probably going to break on IE; use conditional comments to include extra stylesheets for various IE versions you have to support, adding whatever hacks you need to make it work.

As far as tools go; you don't really need more than a text editor and a browser to test in. Firebug or an equivalent document inspector plugin is a great help (Google Chrome / Chromium has a similar tool built into it), especially since it allows you to modify styles inside the browser - they won't persist, but you can quickly try out things to see what works.

On the server side, there are a few technologies that allow you to take shortcuts - basically, they take a stylesheet written in a superset of CSS, adding things like variables, nested rules, etc., and transform it into regular CSS before sending it to the browser. The cassius and lucius template languages (for Haskell) are nice examples, but solutions exist for many programming languages.


问:
Programming knowledge vs. programming logic
Is there any difference between the two topics? I have seen companies asking for Good Programming knowledge some Good Programming logic.

I have seen this in Job profiles for a developer – for e.g. "good Programming logic", "strong Programming knowledge".

I believe that Programming knowledge is related to knowledge about the language in consideration and Programming logic is problem solving logic using programming (in general).

Please correct me if I am wrong. Also what is more important?

Edit: Do selection of components for application, designing interfaces validating user inputs fall under programming knowledge or Programming logic?

Does programming logic simply imply problem solving, or is there anything else which it should comprise of?

答:
Programming Knowledge is knowing the use of hammer n Chisel

Programming Logic is crafting the Chair out of Wooden Log .. !! (using Hammer n Chisel)


答:
It is really an ART to write your own CSS and it may take a lot of time to master. However, there are some quick shortcuts. Basically, re-using existing templates and modifying them slightly can produce results in less time.
There are some Free tools to work with CSS - 50 Extremely Useful And Powerful CSS Tools.

Thus, starting from a template is the easiest and fastest way for web-developer. There are some good FREE template sites that are very handy. In addition, there a decent css styles for few bucks. Here is a list of template sites i prefer to visit when good css styling is required.

free css templates

style shout

35 Excellent Websites for Downloading Free CSS Template

100 Free High-Quality XHTML/CSS Templates

Free 365 CSS Templates

Here are some good places to learn CSS. I took them from the W3Tools link in my comment:

Google: HTML, CSS, and Javascript from the Ground Up

SitePoint

MDN (Mozilla's Developer Network)


问:
Programming SOLID Principles
Over time I could understand two parts of SOLID – the “S” and “O”.

“O” – I learned Open Closed Principle with the help of Inheritance and Strategy Pattern.

“S” – I learned Single Responsibility principle while learning ORM (the persistence logic is taken away from domain objects).

In a similar way, what are the best regions/tasks to learn other parts of SOLID (the “L”, “I” and “D”)?

References

msdn - Dangers of Violating SOLID Principles in C#

channel9 - Applying S.O.L.I.D. Principles in .NET/C#

OOPS Principles (SOLID Principles)

答:
I was in your shoes couple months ago till I found a very helpful article.

Each principle is nicely explained with real-world situations that each software developer may face in their projects. I am cutting short here and pointing to the reference - S.O.L.I.D. Software Development, One Step at a Time.

As pointed in comments, there is another very good pdf reading - Pablo's SOLID Software
Development.

In addition, there are some good books that describe SOLID principles in more details - Good Book on SOLID Software Development.

Edit and comments of a short summary for each principle:

“S” – Single Responsibility Principle is driven by the needs of the business to allow change. “A single reason to change” helps you understand which logically separate concepts should be grouped together by considering the business concept and context, instead of the technical concept alone.
In another words, i learned that each class should have a single responsibility.
The responsibility is to just accomplish the assigned task

“O” – I learned Open Closed Principle and started to "prefer composition over inheritance" and as such, preferring classes that have no virtual methods and are possibly sealed, but depend on abstractions for their extension.

“L” – I learned Liskov Substitution Principle with help of Repository pattern for  managing data access.

“I” – I learned about Interface Segregation Principle by learning that clients shouldn't be forced to implement interfaces they don't use (like in Membership Provider in ASP.NET 2.0). So interface should not have “a lot of responsibilities”

“D” – I learned about Dependency Inversion Principle and started to code that is easy to change. Easier to change means a lower total cost of ownership and higher maintainability.

As a useful resource from CodePlex was mentioned in comments, reference is included to SOLID by example

ContentLicense: CC BY-SA 4.0

Title: Programming SOLID Principles


问:
Representing business rules with exceptions
I know it is expensive but (IMO) I believe it is a very good practice. I'm talking about rules like say, you can't save an Invoice if you are not a sales person... so in that case throwing an exception saying 'your are not authorized' or such...

Another approach it would be having objects with a status or something like that

Is there any other approach? how do you feel about it?

答:
That depends entirely on what's being done.

First, what is the actual behavior you want?  If somebody is entering their own information, then a rejection and a dialog box saying, essentially, "You can't do that" is probably correct.  If this is a data entry person, working from a pile of forms, a dialog box is probably also good, and the data entry person can put the invalid forms in a special pile.  If you're doing batch processing, you don't want to bring things to a halt, but flag it and move to the next.

Once you have the behavior, you need to decide how you're going to implement it.  Having a business rules checker that throws an exception is probably a good idea.  Returning an return code and having it passed along is something else that can go wrong, and you certainly don't want the erroneous entries getting further.

Don't worry about performance expense.  In the case of an individual entering data, it's trivial compared to the other times involved.  Typically, the human will take the most time in that system.  In the case of a batch job, if exceptions are a performance problem, you're entering far too many bad records, and in reality handling and re-entering all of those is going to be more of a problem than the exceptions.


问:
Why do we need to put N before strings in Microsoft SQL Server?
I'm learning T-SQL. From the examples I've seen, to insert text in a varchar() cell, I can write just the string to insert, but for nvarchar() cells, every example prefix the strings with the letter N.

I tried the following query on a table which has nvarchar() rows, and it works fine, so the prefix N is not required:

```<code>insert into [TableName] values ('Hello', 'World')
</code>```

Why the strings are prefixed with N in every example I've seen?

What are the pros or cons of using this prefix?

答: NVarchar is used for Unicode. If your database is not storing multilingual data you can keep using Varchar. As an example: N'abc' simply converts your string to unicode.


答: (I)nterface Segregation and (D)ependency Inversion can be learned via unit testing and mocking. If classes create their own dependencies, you can't create good unit tests. If they depend on a too-broad interface (or no interface at all), it isn't very obvious what needs to be mocked to make your unit tests.</p>

Title: Programming SOLID Principles

Body:
Over time I could understand two parts of SOLID – the “S” and “O”.

“O” – I learned Open Closed Principle with the help of Inheritance and Strategy Pattern.

“S” – I learned Single Responsibility principle while learning ORM (the persistence logic is taken away from domain objects).

In a similar way, what are the best regions/tasks to learn other parts of SOLID (the “L”, “I” and “D”)?

References

msdn - Dangers of Violating SOLID Principles in C#

channel9 - Applying S.O.L.I.D. Principles in .NET/C#

OOPS Principles (SOLID Principles)


问:
Why is it better for a programmer to design the algorithm before starting to write the code?
Does an appropriate algorithm really help improve the quality and ultimately the efficiency of a program?

Can we still produce a good quality program without the algorithm?

Is an appropriate algorithm a MUST in modern programming?

答:
It is not better. It is better not to "design" anything. That is for people who do not write programs. You know, the people with real experience of the problem at hand. If you're a mathematician, engineer or a logistician, fine, you need to work on the process elsewhere. But that is not 'programming'.

Put some kind of test and benchmark in place first.

Then write something, anything. Do refactor-rewrite -loop until you run out of time or can no longer improve.

While many seem to think one can do things with a computer without actually doing anything on a computer, I think this is one of the most common myths out there. Architecture astronautisms.

Also, you can not optimize your algo before it is written.

IOW, "stay close to the metal".

OwnerDisplayName: Jervis


答:
By default SQL server uses the Windows-1252 character codes for varchar.  It contains most of characters for latin-based languages (English, German, French, etc.)  But it does not contain characters for non-latin based languages (Polish, Russian, etc.).  As stated by @Pieter B, nvarchar is used to get around that issue because it is for Unicode which contains those missing characters.  This comes at a cost, it takes twice as much space to store nvarchar than varchar.  </p>

<p>Putting N in front of your string ensures the characters are converted to Unicode before being placed into a nvarchar column.  Most of the time you will be okay leaving the N off, but I wouldn't recommend it.  It is a lot better to be safe than sorry.  </p>

Title: Why do we need to put N before strings in Microsoft SQL Server?

Body:
I'm learning T-SQL. From the examples I've seen, to insert text in a varchar() cell, I can write just the string to insert, but for nvarchar() cells, every example prefix the strings with the letter N.

I tried the following query on a table which has nvarchar() rows, and it works fine, so the prefix N is not required:

```<code>insert into [TableName] values ('Hello', 'World')
</code>```

Why the strings are prefixed with N in every example I've seen?

What are the pros or cons of using this prefix?

Body:
By default SQL server uses the Windows-1252 character codes for varchar.  It contains most of characters for latin-based languages (English, German, French, etc.)  But it does not contain characters for non-latin based languages (Polish, Russian, etc.).  As stated by @Pieter B, nvarchar is used to get around that issue because it is for Unicode which contains those missing characters.  This comes at a cost, it takes twice as much space to store nvarchar than varchar.

Putting N in front of your string ensures the characters are converted to Unicode before being placed into a nvarchar column.  Most of the time you will be okay leaving the N off, but I wouldn't recommend it.  It is a lot better to be safe than sorry.


问:
How to fetch commit messages from bitbucket for project manager to see
Is it possible to fetch commit messages from bitbucket via json or something so that a project manager can see what the changes are without having to look at the code. If it's possible can you give me some ideas on how to do it.</p>

答:
As already mentioned by Yannis in his comment, you can use the Bitbucket API.

The documentation for changesets says that you can use the following URI to get a list of all changesets for a repository:

https://api.bitbucket.org/1.0/repositories/USERNAME/REPOSITORY/changesets

For example, https://api.bitbucket.org/1.0/repositories/jespern/django-piston/changesets

(this is the example link from the documentation)

This does return JSON, but I doubt that this is really comfortable to read for a (non-technical?) manager.

--> I guess I'd rather give him the link to the list of commits in Bitbucket's GUI.

IMO it's much easier to read and he doesn't need to look at the code either.


问:
What's your favourite quote about programming?
What's your favourite quote about programming?

One quote per answer, and please check for duplicates before posting!

答:
If you fail to plan, you plan to fail

-My c# Teacher (not sure where he heard it from!)

LastEditorDisplayName: Roger Pate


问:
Sharing ideas without risk of leaking
As freelancers, we meet somewhere and chat about a new idea for a project, brainstorm etc. Up to this point, we have taken notes of the ideas, but we would like to be able to share more efficiently the ideas with each other. However, I fear that if I use some online product (such as Google Docs) these ideas could be seen by people outside the team (employees of the company of the online product, other users...). I am not sure if I am being a little Paranoid parrot...

One solution that we have considered is to install a Subversion with just one ideas.txt. But that would require a server in one of our houses, which is a little unconfortable.

So how do you share your ideas for a new project with your team without risking the ideas to be stolen?

答:
You offer two basic choices:

1.  Store ideas on a server you control.

2.  Store ideas on a server you do not control (e.g., Google's)

I say that none of these matter.  Do either 1 or 2, but encrypt the ideas document and send the key to the relevant freelancers via Sneakernet.

Title: Sharing ideas without risk of leaking


答:
You are at a greater risk of the leak coming from a member of the group than you are through someone hacking, or snooping your document.

Ask yourself how much that document is worth with out the context of the group brainstorm?  I know most of my working documents would not be worth the effort to figure out rather than just solve the problem myself.  But with the context they are invaluable.  So assuming your document was open to the world, unless you have the context it is likely worthless.  If you put the document somewhere that keeps it away from all but determined eyes your risk is about as low as you can get it.

Title: Sharing ideas without risk of leaking

Body:
As freelancers, we meet somewhere and chat about a new idea for a project, brainstorm etc. Up to this point, we have taken notes of the ideas, but we would like to be able to share more efficiently the ideas with each other. However, I fear that if I use some online product (such as Google Docs) these ideas could be seen by people outside the team (employees of the company of the online product, other users...). I am not sure if I am being a little Paranoid parrot...

One solution that we have considered is to install a Subversion with just one ideas.txt. But that would require a server in one of our houses, which is a little unconfortable.

So how do you share your ideas for a new project with your team without risking the ideas to be stolen?


问:
When to start writing Exception Handling, Logging
When do you start writing your Exception Handling Code? When do you start writing Logging Statements.

For the purpose of elaborating this question, let us assume that we are on .NET platform with log4net logging but feel free to answer in a generic way.

Solution: A Windows Forms Project.
Projects: UI, BusinessRules, DataHandlers

So, do you go about writing your DataHandlers which does your Data Manipulations such as Create, Read, Update, Delete first.

Then follow it up with your Business Rules

And then your UI or any other permutation of the above.

Test your Application for Functionality.

And then start writing your Exception Handling Code and finally your Logging code?

When is a right time to start writing your Exception Handling code?

PS: In the book Clean Code, they say Write your try-catch-finally block first. That, prompted me to ask this question.

答:
Depends on what you are doing

for exceptions:

If you are writing something that is likely to have errors or something where there are good top level points to let exceptions bubble up to write them as you go.

If you are writing something that needs performance and has a low possibility of errors an lacks a meaningful place to put error handlers write the error handlers where testing proves you need them.

In either case, if you don't have anything useful to do with the error consider letting it bubble up (no handler)

for logging:

If you need an audit trail you should write the logging first.  If you are letting errors bubble all the way to the top you need to provide some logging there as well so the log can be captured.

Aside from those cases I generally only add logging in the places where testing/use proves it is necessary and I usually make an option to configure it off once I am done with it.


问:
Unit testing multiple conditions in an IF statement
I have a chunk of code that looks something like this:

```<code>function bool PassesBusinessRules()
{
    bool meetsBusinessRules = false;

    if (PassesBusinessRule1
         && PassesBusinessRule2
         && PassesBusinessRule3)
    {
         meetsBusinessRules= true;
    }

    return meetsBusinessRules;
}
</code>```

I believe there should be four unit tests for this particular function.  Three to test each of the conditions in the if statement and ensure it returns false.  And another test that makes sure the function returns true.

Question: Should there actually be ten unit tests instead?  Nine that checks each of the possible failure paths.  IE:

False False False

False False True

False True False

And so on for each possible combination.

I think that is overkill, but some of the other members on my team do not.  The way I look at it is if BusinessRule1 fails then it should always return false, it doesn't matter if it was checked first or last.

答:
Formally, those types of coverage have names.

First, there's predicate coverage: you want to have a test case that makes the if statement true, and one that makes it false. Having this coverage met is probably a basic requirement for a good test suite.

Then there Condition Coverage: Here you want to test that each sub-condition in the if has the value true and false. This obviously creates more tests, but it usually catches more bugs, so it's often a good idea to include in your test suite if you have time.

The most advanced coverage criteria is usually called Combinatorial Condition Coverage: Here the goal is to have a test case that goes through all possible combinations of boolean values in your test.

Is this better than simple predicate or condition coverage? In terms of coverage, of course. But it's not free. It comes at a a very high cost in test maintenance. For this reason, most people don't bother with full combinatorial coverage. Usually testing all branches (or all conditions), will be good enough for catching bugs. Adding the extra tests for combinatorial testing won't usually catch more bugs, but requires a lot of effort to create and maintain. The extra effort usually makes this not worth the very very small payoff, so I wouldn't recommend this.

Part of this decision should be based on how risky you think that code will be. If it has a lot of room to fail, it's worth testing. If it's somewhat stable, and won't change much, you should consider focusing your testing efforts elsewhere.


答:
Yes, there should be the full combination in an ideal world.

When doing the unit test, you really should try to ignore how the method does its work. Simply provide the 3 inputs and verify that the output is correct.

Title: Unit testing multiple conditions in an IF statement

Body:
I have a chunk of code that looks something like this:

```<code>function bool PassesBusinessRules()
{
    bool meetsBusinessRules = false;

    if (PassesBusinessRule1
         && PassesBusinessRule2
         && PassesBusinessRule3)
    {
         meetsBusinessRules= true;
    }

    return meetsBusinessRules;
}
</code>```

I believe there should be four unit tests for this particular function.  Three to test each of the conditions in the if statement and ensure it returns false.  And another test that makes sure the function returns true.

Question: Should there actually be ten unit tests instead?  Nine that checks each of the possible failure paths.  IE:

False False False

False False True

False True False

And so on for each possible combination.

I think that is overkill, but some of the other members on my team do not.  The way I look at it is if BusinessRule1 fails then it should always return false, it doesn't matter if it was checked first or last.


答:
If you want to be safe, you would need eight unit tests using the conditions represented by a three variable truth table (http://teach.valdosta.edu/plmoch/MATH4161/Spring%202004/and_or_if_files/image006.gif).

You can never be sure that the business logic will always stipulate that the checks are performed in that order and you want the test to know as little about the actual implementation as possible.


答:
Ultimately, it depends on you(r team), the code and the specific project environment. There is no universal rule. You(r team) should write as many tests as you need to feel comfortable that the code is indeed correct. So if your teammates aren't convinced by 4 tests, maybe you need more.

OTOH time to write unit tests is usually a scarce resource. So strive to find the best way to spend the limited time you have. E.g. if you have another important method with 0% coverage, it may be better to write a couple of unit tests to cover that one, rather than to add extra tests for this method. Of course, it also depends on how fragile the implementation of each is. Planning a lot of changes to this particular method in the foreseeable future may justify extra unit test coverage. So may being on a critical path inside the program. These are all factors which only you(r team) can assess.

I personally would usually be happy with the 4 tests you outline, that is:

true false false

false true false

false false true

true true true

plus maybe one:

true true false

to ensure that the only way to get a return value of true is to satisfy all 3 business rules. But in the end, if your teammates insist on having combinatorial paths covered, it may be cheaper to add those extra tests than to continue the argument a lot longer :-)


问:
What OO Design to use ( is there a Design Pattern )?
I have two objects that represent a 'Bar/Club' ( a place where you drink/socialise).

In one scenario I need the bar name, address, distance, slogon

In another scenario I need the bar name, address, website url, logo

So I've got two objects representing the same thing but with different fields.

I like to use immutable objects, so all the fields are set from the constructor.

One option is to have two constructors and null the other fields i.e:

```<code>class Bar {
     private final String name;
     private final Distance distance;
     private final Url url;

     public Bar(String name, Distance distance){
          this.name = name;
          this.distance = distance;
          this.url = null;
     }

     public Bar(String name, Url url){
          this.name = name;
          this.distance = null;
          this.url = url;
     }

     // getters
}
</code>```

I don't like this as you would have to null check when you use the getters

In my real example the first scenario has 3 fields and the second scenario has about 10, so it would be a real pain having two constructors, the amount of fields I would have to declare null and then when the object are in use you wouldn't know which Bar you where using and so what fields would be null and what wouldn't.

What other options do I have?

Two classes called BarPreview and Bar?

Some type of inheritance / interface?

Something else that is awesome?

答:
The key point here is the difference between what a "Bar" is and how you use it in one or another context.

The Bar is a single entity in the real world (or an artificial world, like a game), and only ONE object instance should represent it. Anytime later, when you don't create that instance from a code segment, but load it from a config file or a database, this will be more evident.

(To be even more esoteric: each Bar instance has a different lifecycle than the object that represents it when your program runs. Even if you have a source code that creates that instance, it means that the Bar entity as it is described, "exists" in a dormant state in your source code, and "awaken" when that code actually creates it in the memory...)

Sorry for the long start, but I hope this makes my point clear. You have ONE Bar class having all the attributes that you would ever need, and one Bar instance representing each Bar entity. This is correct in your code, and independent from how you want to see the same instance in different contexts.

The latter can be represented by two different interfaces, that contain the required access methods (getName(), getURL(), getDistance()), and the Bar class should implement both. (And perhaps the "distance" will change to "location", and the getDistance() becomes a calculation from another location :-) )

But the creation is for the Bar entity and not for the way you want to use that entity: one constructor, all fields.

EDITED: I can write code! :-)

```<code>public interface Place {
  String getName();
  Address getAddress();
}

public interface WebPlace extends Place {
   URL getUrl();
   Image getLogo();
}

public interface PhysicalPlace extends Place {
  Double getDistance();
  Slogon getSlogon();
}

public class Bar implements WebPlace, PhysicalPlace {
  private final String name;
  private final Address address;
  private final URL url;
  private final Image logo;
  private final Double distance;
  private final Slogon slogon;

  public Bar(String name, Address address, URL url, Image logo, Double distance, Slogon slogon) {
    this.name = name;
    this.address = address;
    this.url = url;
    this.logo = logo;
    this.distance = distance;
    this.slogon = slogon;
  }

  public String getName() { return name; }
  public Address getAddress() { return address; }
  public Double getDistance() { return distance; }
  public Slogon getSlogon() { return slogon; }
  public URL getUrl() { return url; }
  public Image getLogo() { return logo; }
}
</code>```

Body:
The key point here is the difference between what a "Bar" is and how you use it in one or another context.

The Bar is a single entity in the real world (or an artificial world, like a game), and only ONE object instance should represent it. Anytime later, when you don't create that instance from a code segment, but load it from a config file or a database, this will be more evident.

(To be even more esoteric: each Bar instance has a different lifecycle than the object that represents it when your program runs. Even if you have a source code that creates that instance, it means that the Bar entity as it is described, "exists" in a dormant state in your source code, and "awaken" when that code actually creates it in the memory...)

Sorry for the long start, but I hope this makes my point clear. You have ONE Bar class having all the attributes that you would ever need, and one Bar instance representing each Bar entity. This is correct in your code, and independent from how you want to see the same instance in different contexts.

The latter can be represented by two different interfaces, that contain the required access methods (getName(), getURL(), getDistance()), and the Bar class should implement both. (And perhaps the "distance" will change to "location", and the getDistance() becomes a calculation from another location :-) )

But the creation is for the Bar entity and not for the way you want to use that entity: one constructor, all fields.

EDITED: I can write code! :-)

public interface Place {
  String getName();
  Address getAddress();
}

public interface WebPlace extends Place {
   URL getUrl();
   Image getLogo();
}

public interface PhysicalPlace extends Place {
  Double getDistance();
  Slogon getSlogon();
}

public class Bar implements WebPlace, PhysicalPlace {
  private final String name;
  private final Address address;
  private final URL url;
  private final Image logo;
  private final Double distance;
  private final Slogon slogon;

  public Bar(String name, Address address, URL url, Image logo, Double distance, Slogon slogon) {
    this.name = name;
    this.address = address;
    this.url = url;
    this.logo = logo;
    this.distance = distance;
    this.slogon = slogon;
  }

  public String getName() { return name; }
  public Address getAddress() { return address; }
  public Double getDistance() { return distance; }
  public Slogon getSlogon() { return slogon; }
  public URL getUrl() { return url; }
  public Image getLogo() { return logo; }
}


问:
Is an app that does nothing but link to a web site functional enough to meet Apple's iOS guidelines?
I don't hang out on Programmers enough to know whether this question is "ok", so my apologies if not. I tried to make the title obvious so at least it can be closed quickly :-)

The question is simple. My employer wants "home screen presence" (or at least the possibility thereof) on iOS devices (also Android but I'm mostly interested in Apple at the moment). Our actual application will be a pure web-delivered mobile-friendly application, so what we want on the homescreen is basically something that just acts as a link to bring up Safari (or Chrome now I guess; not important). I'm presuming that that's more-or-less possible; if not then that would be interesting too.

I know that the Apple guidelines are such that low-functionality apps are generally rejected out of hand. There are a lot of existing apps that seem (to me) less functional than a link to something useful, but I'm not Apple of course.  Because this seems like a not-too-weird situation, I'm hoping that somebody knows it's either definitely OK (maybe because there are many such apps) or definitely not OK.

Note that I know about things like PhoneGap  and I don't want that, at least not at the moment.

答:
Probably not. See the iOS App Store Review Guidelines:

2.12 Apps that are not very useful, are simply web sites bundled as apps,  or do not provide any lasting entertainment value may be
  rejected

One might guess that if your app is just a pointer to a web site, not even the web site bundled into an app, then it's even less useful than the sort of thing contemplated in section 2.12.


答:
Profanity is the one language all
  programmers know best.

-- Anonymous

Body:
What's your favourite quote about programming?

One quote per answer, and please check for duplicates before posting!


问:
Facebook Payments & Credits vs. Real-World & Charities
I am having a difficult time understanding Facebook's internal "e-commerce microcosm" and what it allows Facebook App developers to do (and what it restricts them from doing).

Two use cases:

I'm an e-com retailer selling clothes and coffee mugs (real-world goods) on my website; I want to write a Facebook App that allows Facebook users to buy my real-world goods from inside of Facebook using real money ($ USD)

I'm highschool student trying to raise money for my senior class trip and want to build a Facebook App that allows Facebook users to donate to our class using real money ($ USD)

Are these two scenarios possible? If not, why (what Facebook policies prohibit me from doing so)? If so, what APIs do I use: Payments or Credits? And how (specifically) would it work? Do Facebook Users have to first buy "credits" (which are mapped to $ USD values under the hood) and pay/donate with credits, or can they whip out their credit card and pay/donate right through my Facebook App?

I think that last question really summarizes my confusion: can Facebook users enter their credit card info directly into Facebook Apps, or do you have to go through Payments/Credits APIs as a "middleman"?

答:
You can't use real money on facebook, you can only deal with the "Facebook Credits", the only way to exchange values on Facebook for now.

https://developers.facebook.com/docs/credits/

This is the situation about the public part of Facebook.

In the late years Facebook is allowing some e-commerce to use their login-system to basically keep the user connected to both Facebook and the e-commerce that is requiring this functionality, this mechanism is not yet available for everyone and requires you to ask Facebook in private terms to allow your site to use this solution.

Among the few sites that offers this kind of option, there is a special reseller ( I only know this one ) http://www.beetailer.com/ which re-sell special solution to keep your shop connected to Facebook.

There is also a third solution but in this case everything is very undefined, i just provide this link to you but i do not really know what the rules are in this case, they announces this feature but i don't know how to use it and what this feature allow you to do http://blog.facebook.com/blog.php?post=2383962130


问:
Practical size limits of a DataTable in c#
I have to query a large data-set (~500 MB) using a sqlDataReader but I have to save the data in three different formats. Instead of querying the database 3 times I'm thinking about saving the data to an in-memory table and then save the data from there.

Is there a practical limit to a table size in memory? Any ideas for a better approach?

答:
I am not aware of any memory size limits to data tables - you might hit the process size ceiling if you are running as a 32bit process however (the 3GB of addressable memory).

The approach (caching the data into an in memory structure like a DataTable) is valid and makes sense.


答: As for the approach - how about building each of your three outputs while looping over the data reader a single time?</p>

Title: Practical size limits of a DataTable in c#

Body:
I have to query a large data-set (~500 MB) using a sqlDataReader but I have to save the data in three different formats. Instead of querying the database 3 times I'm thinking about saving the data to an in-memory table and then save the data from there.

Is there a practical limit to a table size in memory? Any ideas for a better approach?


答:
Some guidelines in addition to all the other advices:

Use a reset stylesheet to achieve the same basic look and feel across all browsers, e.g. HTML5 Reset.

Give elements "ugly" color backgrounds, when you start working with box sizes / margins / paddings to see the workings of the box model. It helps, especially when you are starting with CSS.

Use some generic values for your CSS and tweak those values using Firebug or something else.

Try to keep your CSS modular instead of getting into "specificity wars" (hmm, why is my style li.special-class not applied? Ah, there is #my-wrapper li somewhere else). You could apply SMACSS methodology or object oriented C4S.

Do not overestimate the necessity of the same look across all browsers. Serve rounded corners that understand them, but do not use graphics to serve those to IE6. Websites are not like magazines, but more like TV channels.


问:
When do you use a struct instead of a class?
What are your rules of thumb for when to use structs vs. classes?  I'm thinking of the C# definition of those terms but if your language has similar concepts I'd like to hear your opinion as well.

I tend to use classes for almost everything, and use structs only when something is very simplistic and should be a value type, such as a PhoneNumber or something like that.  But this seems like a relatively minor use and I hope there are more interesting use cases.

答:
The most important difference between a class and a struct is what happens in the following situation:

```
  Thing thing1 = new Thing();
  thing1.somePropertyOrField = 5;
  Thing thing2 = thing1;
  thing2.somePropertyOrField = 9;
```

What should be the effect of the last statement on thing1.somePropertyOrField?  If Thing a struct, and somePropertyOrField is an exposed public field, the objects thing1 and thing2 will be "detached" from each other, so the latter statement will not affect thing1.  If Thing is a class, then thing1 and thing2 will be attached to each other, and so the latter statement will write thing1.somePropertyOrField.  One should use a struct in cases where the former semantics would make more sense, and should use a class in cases where the latter semantics would make more sense.

Note that while some people advise that a desire to make something mutable is an argument in favor of it being the class, I would suggest the reverse is true: if something which exists for the purpose of holding some data is going to be mutable, and if it will not be obvious whether instances are attached to anything, the thing should be a struct (likely with exposed fields) so as to make clear that instances are not attached to anything else.

For example, consider the statements:

```
  Person somePerson = myPeople.GetPerson("123-45-6789");
  somePerson.Name = "Mary Johnson"; // Had been "Mary Smith"
```

Will the second statement alter the information stored in myPeople?  If Person is an exposed-field struct, it won't, and the fact that it won't will be an obvious consequence of its being an exposed-field struct; if Person is a struct and one wishes to update myPeople, one would clearly have to do something like myPeople.UpdatePerson("123-45-6789", somePerson).  If Person is a class, however, it may be much harder to determine whether the above code would never update the contents of MyPeople, always update it, or sometimes update it.

With regard to the notion that structs should be "immutable", I disagree in general.  There are valid usage cases for "immutable" structs (where invariants are enforced in a constructor) but requiring that an entire struct must be rewritten any time any part of it changes is awkward, wasteful, and more apt to cause bugs than would simply exposing fields directly.  For example, consider a PhoneNumber struct whose fields, include among others, AreaCode and Exchange, and suppose one has a List<PhoneNumber>.  The effect of the following should be pretty clear:

```
  for (int i=0; i < myList.Count; i++)
  {
    PhoneNumber theNumber = myList[i];
    if (theNumber.AreaCode == "312")
    {
      string newExchange = "";
      if (new312to708Exchanges.TryGetValue(theNumber.Exchange), out newExchange)
      {
        theNumber.AreaCode = "708";
        theNumber.Exchange = newExchange;
        myList[i] = theNumber;
      }
    }
  }
```

Note that nothing in the above code knows or cares about any fields in PhoneNumber other than AreaCode and Exchange.  If PhoneNumber were a so-called "immutable" struct, it would be necessary either that it provide a withXX method for each field, which would return a new struct instance which held the passed-in value in the indicated field, or else it would be necessary for code like the above to know about every field in the struct.  Not exactly appealing.

BTW, there are at least two cases where structs may reasonably hold references to mutable types.

The semantics of the struct indicate that it's storing the identity of the object in question, rather than as a shortcut for holding the object's properties.  For example, a `KeyValuePair` would hold the identities of certain buttons, but would not be expected to hold a persistent information about those button's positions, highlight states, etc.

The struct knows that it holds the only reference to that object, nobody else will get a reference, and any mutations which will ever be performed to that object will have been done before a reference to it gets stored anywhere.

In the former scenario, the object's IDENTITY will be immutable; in the second, the class of the nested object may not enforce immutability, but the struct holding the reference will.

Body:
The most important difference between a class and a struct is what happens in the following situation:

  Thing thing1 = new Thing();
  thing1.somePropertyOrField = 5;
  Thing thing2 = thing1;
  thing2.somePropertyOrField = 9;

What should be the effect of the last statement on thing1.somePropertyOrField?  If Thing a struct, and somePropertyOrField is an exposed public field, the objects thing1 and thing2 will be "detached" from each other, so the latter statement will not affect thing1.  If Thing is a class, then thing1 and thing2 will be attached to each other, and so the latter statement will write thing1.somePropertyOrField.  One should use a struct in cases where the former semantics would make more sense, and should use a class in cases where the latter semantics would make more sense.

Note that while some people advise that a desire to make something mutable is an argument in favor of it being the class, I would suggest the reverse is true: if something which exists for the purpose of holding some data is going to be mutable, and if it will not be obvious whether instances are attached to anything, the thing should be a struct (likely with exposed fields) so as to make clear that instances are not attached to anything else.

For example, consider the statements:

  Person somePerson = myPeople.GetPerson("123-45-6789");
  somePerson.Name = "Mary Johnson"; // Had been "Mary Smith"

Will the second statement alter the information stored in myPeople?  If Person is an exposed-field struct, it won't, and the fact that it won't will be an obvious consequence of its being an exposed-field struct; if Person is a struct and one wishes to update myPeople, one would clearly have to do something like myPeople.UpdatePerson("123-45-6789", somePerson).  If Person is a class, however, it may be much harder to determine whether the above code would never update the contents of MyPeople, always update it, or sometimes update it.

With regard to the notion that structs should be "immutable", I disagree in general.  There are valid usage cases for "immutable" structs (where invariants are enforced in a constructor) but requiring that an entire struct must be rewritten any time any part of it changes is awkward, wasteful, and more apt to cause bugs than would simply exposing fields directly.  For example, consider a PhoneNumber struct whose fields, include among others, AreaCode and Exchange, and suppose one has a List<PhoneNumber>.  The effect of the following should be pretty clear:

  for (int i=0; i < myList.Count; i++)
  {
    PhoneNumber theNumber = myList[i];
    if (theNumber.AreaCode == "312")
    {
      string newExchange = "";
      if (new312to708Exchanges.TryGetValue(theNumber.Exchange), out newExchange)
      {
        theNumber.AreaCode = "708";
        theNumber.Exchange = newExchange;
        myList[i] = theNumber;
      }
    }
  }

Note that nothing in the above code knows or cares about any fields in PhoneNumber other than AreaCode and Exchange.  If PhoneNumber were a so-called "immutable" struct, it would be necessary either that it provide a withXX method for each field, which would return a new struct instance which held the passed-in value in the indicated field, or else it would be necessary for code like the above to know about every field in the struct.  Not exactly appealing.

BTW, there are at least two cases where structs may reasonably hold references to mutable types.

The semantics of the struct indicate that it's storing the identity of the object in question, rather than as a shortcut for holding the object's properties.  For example, a `KeyValuePair` would hold the identities of certain buttons, but would not be expected to hold a persistent information about those button's positions, highlight states, etc.

The struct knows that it holds the only reference to that object, nobody else will get a reference, and any mutations which will ever be performed to that object will have been done before a reference to it gets stored anywhere.

In the former scenario, the object's IDENTITY will be immutable; in the second, the class of the nested object may not enforce immutability, but the struct holding the reference will.


答:
According to MSDN DataTable Class
"The maximum number of rows that a DataTable can store is 16,777,216", surprisingly, the page is not showing limitations in terms of MBs. There are issues addressed in MSDN Out of Memory Exception.

If you are running under Windows, its quick and safe to serialize the data to a file of any kind you choose and then use the generated file as input for each of your 3 formats. Writing to a file is much more safer and can allow you to restart the application in case it fails during one of the generations. It would also allow you to run the generation of your 3 formats in parallel, hence making the application much faster and more reliably.

The save-to-file approach is reliable and is used in Data Mart projects all over the planet.


问:
Do people in non-English-speaking countries code in English?
I've heard it said (by coworkers) that everyone "codes in English" regardless of where they're from. I find that difficult to believe, however I wouldn't be surprised if, for most programming languages, the supported character set is relatively narrow.

Have you ever worked in a country where English is not the primary language?

If so, what did their code look like?

答: I'm from Taiwan. We code in English and follow the naming convention of specific languages.</p>


问:
Developing an Interface to a Dynamic System
I work for a small company and have been designing a GUI to interface our embedded system.  The problem with this embedded system is that it is not a finished product (may never be) and is constantly under development and being tweaked and updated for different customers and applications in small volumes.

So to deal with this I made a program that can export all the data from a spreadsheet where most of the embedded system variables are sourced from and throw them into a small database for the GUI application to use.  This database program I made also spits out a cross reference file for the embedded system which allows the GUI to look up all the variables.

This system works pretty well so far, and is even integrated with version control among the GUI, database, and embedded system.  The big problem is that there is constant development on several projects that use this system and it gets terribly tedious to keep the system up to date and bring in new changes.  This has gotten to the point to where I have had to code the GUI to dynamically (generically) generate all interfaces since I am never guaranteed to find the same data the same way.  I have not been able to come up with a good way to uniquely identify the data I import from excel since all fields are able to be changed (due to engineering stubbornness, code re-factoring and/or excel issues) and I cannot assign a fixed reference within the sheet itself.

So, are there any good methods or ideas on how to handle the chaos?

答:
So, what I understand is that you parse an Excel spreadsheet that is changed constantly by your colleagues. Here are some ideas on how to remedy that situation:

Teach the other programmers to be careful with their changes. As soon as an API (in this case, the spreadsheet format) is public, it must stay that way or be deprecated in a controlled, system-wide way. It's uncomfortable, but necessary.

Very effective together with the above would be automated testing. You said that everything is in version control. Set up a system that runs automated tests each time someone commits a change. If the tests fail, the commit should be rejected, if your VCS allows this. The goal is to always have a working, reliable state checked in.

If the spreadsheet really needs to be changed all the time with no regard to compatibility, try and come up with a system so that the burden of adapting your interface is on the guy who changes the spreadsheet. Maybe some domain specific language, another GUI or some kind of annotations in the spreadsheet itself. Use the automated testing from above to verify consistency so your users are forced to keep the interface up-to-date.


答:
You need to stop looking at software construction as something fundamentally from the construction of anything else of value. It is not. So, like anything else, a well-thought plan or design, however succint, is always needed.

Does an appropriate algorithm really help improve the quality and
  ultimately the efficiency of a program?

Does an appropriate building plan/schematics help build a quality house efficiently?

Can we still produce a good quality program without the algorithm?

Can you build a good quality house efficiently without an appropriate building plan? As per the Infinite Monkey Theorem, probabilistically, yeah (just as a million monkeys typing at random for eternity will eventually type the complete works of Shakespeare.

Is an appropriate algorithm a MUST in modern programming?

If you don't want to be a code monkey and you want to ensure you don't deliver software that looks and works like shit, yes, it is a must. Every project that I've had to salvage (because the code looked like umaintainable shit) has invariable started with a negative answer to that question.

In fact, modern programming has been the move away from cowboy programming software engineer where planning of some sort if a must.

Even when you have a library of algorithms and data structures at your disposal (.ie. Boost in C++ or the Java collections library), you have to know how that stuff works to use it appropriately, and to compose it into reasonable, higher-level algorithms.

Title: Why is it better for a programmer to design the algorithm before starting to write the code?

Body:
Does an appropriate algorithm really help improve the quality and ultimately the efficiency of a program?

Can we still produce a good quality program without the algorithm?

Is an appropriate algorithm a MUST in modern programming?


答:
I don't see what value throwing an Exception has in creating good business logic. There are dozens of approaches to handling business logic that do not involve using a system that is meant for addressing unexpected conditions in the operation of a system.

It is expected that in business logic, conditions will not be met; that's the reason for having it in the first place, and you don't want to piggyback on the same mechanism that handles unexpected I/O failures, out of memory errors and null references. Those are failures of the system, but detecting unmet business conditions is the successful operation of the system.

Additionally, it is a system that is ripe for unintended consequences. Because an exception has to be caught at some point, you run the risk of having a new business rule exception ened up being caught somewhere that it's not intended or you chance having the code that looks for business rules catching exceptions that aren't actually meant for it. Yes, these conditions can be accounted for with good coding practices, but in any non-trivial system on which more than one developer is working, mistakes will happen, and you just have to hope that they won't be costly mistakes.

Title: Representing business rules with exceptions

Body:
I know it is expensive but (IMO) I believe it is a very good practice. I'm talking about rules like say, you can't save an Invoice if you are not a sales person... so in that case throwing an exception saying 'your are not authorized' or such...

Another approach it would be having objects with a status or something like that

Is there any other approach? how do you feel about it?


问:
Self-Executing Anonymous Function vs Prototype
In Javascript there are a few clearly prominent techniques for create and manage classes/namespaces in javascript.

I am curious what situations warrant using one technique vs. the other. I want to pick one and stick with it moving forward.

I write enterprise code that is maintained and shared across multiple teams, and I want to know what is the best practice when writing maintainable javascript ?

I tend to prefer Self-Executing Anonymous Functions however I am curious what the community vote is on these techniques.

Prototype :

```<code>function obj()
{
}

obj.prototype.test = function() { alert('Hello?'); };
var obj2 = new obj();
obj2.test();
</code>```

Self-Closing Anonymous Function :

```<code>//Self-Executing Anonymous Function
(function( skillet, $, undefined ) {
    //Private Property
    var isHot = true;

    //Public Property
    skillet.ingredient = "Bacon Strips";

    //Public Method
    skillet.fry = function() {
        var oliveOil;

        addItem( "\t\n Butter \n\t" );
        addItem( oliveOil );
        console.log( "Frying " + skillet.ingredient );
    };

    //Private Method
    function addItem( item ) {
        if ( item !== undefined ) {
            console.log( "Adding " + $.trim(item) );
        }
    }
}( window.skillet = window.skillet || {}, jQuery ));
//Public Properties
console.log( skillet.ingredient ); //Bacon Strips

//Public Methods
skillet.fry(); //Adding Butter & Fraying Bacon Strips

//Adding a Public Property
skillet.quantity = "12"; console.log( skillet.quantity ); //12

//Adding New Functionality to the Skillet
(function( skillet, $, undefined ) {
    //Private Property
    var amountOfGrease = "1 Cup";

    //Public Method
    skillet.toString = function() {
        console.log( skillet.quantity + " " +
                     skillet.ingredient + " & " +
                     amountOfGrease + " of Grease" );
        console.log( isHot ? "Hot" : "Cold" );
     };

}( window.skillet = window.skillet || {}, jQuery ));
//end of skillet definition

try {
    //12 Bacon Strips & 1 Cup of Grease
    skillet.toString(); //Throws Exception
} catch( e ) {
    console.log( e.message ); //isHot is not defined
}
</code>```

I feel that I should mention that the Self-Executing Anonymous Function is the pattern used by the jQuery team.

Update
When I asked this question I didn't truly see the importance of what I was trying to understand. The real issue at hand is whether or not to use new to create instances of your objects or to use patterns which do not require constructors/use of the new keyword.

I added my own answer, because in my opinion we should make use of patterns which don't use the new keyword.

For more information please see my answer.

答:
Update
I now have a much better understanding of javascript and feel I can properly address the question. I think it was a poorly worded, but very important javascript topic to address.

The Self Executing Anonymous Function pattern is not one which requires use of the new keyword if you avoid the use of this outside of functions. I agree with the idea that using new is an old technique and we should instead strive to use patterns that avoid the use of new.

The Self Executing Anonymous Function meets this criteria.

The answer to this question is subjective, because there are so many coding styles in javascript. However based on my research and experience I would recommend choosing to use the Self Executing Anonymous Function to define your API's and avoid the use of new whenever possible.


问:
How do I reuse a state machine in a slightly different way?

Problem

I have a big state machine. The design requirements of the project have changed such that I need to re-use this state machine in another place. All the states remain the same in this new place, but a few states run slightly different stuff. What design pattern allows me to reuse this state machine?

Motivation

I am building a video player. It is modeled by a state machine with these states: stopped, loading, playing, paused, crashed, and some more... This video player needs to be used on two web pages. When the player crashes on the first page, it should show an error message below. If the player crashes on the second page, the error message should appear in the center of the video and pulsate a few times.

答:
The basic concept is to abstract out what varies.  So, if you have a state that does FOO one way in place A, and FOO differently in place B, abstract out FOO into several strategies:

FooAStrategy does what place A needs.  It is invoked by calling doFoo, or execute, or some such thing.
FooBStrategy does what place B needs.  It is invoked by calling doFoo, or execute, or some such thing.

The FooState in place A would have a FooAStrategy.
The FooState in place B would have a FooBStrategy.

Each would invoke its strategy as needed.

In case you hadn't guessed, this is the Strategy pattern.


问:
How to Mentor a Junior Developer
This title is a little broad but I may need to give a little background before I can ask my question properly.

I know that similar questions have been asked here already. But in my case I'm not asking if I should be mentoring someone or if the person is a good fit for being a software developer. That is not my place to judge. I have not been asked outright, but it is apparent that myself and other fellow senior developers are to mentor the new developers that start here. I have no problem with this whatsoever and, in many cases, it lends me a fresh perspective on things and I end up learning in the process. Also, I remember how beneficial it was in the beginning of my career when someone would take some time to teach me something.

When I say "new developer" they could be anywhere from fresh out of college to having a year or two of experience.

Recently we've had people start here who seem to have an attitude toward development/programming which is different from my own and hard for me to reconcile; they extract just enough information to get the task done but not really learn from it. I find myself going over and over the same issues with them. I understand that part of this could be a personality thing, but I feel it's my job to do my best and push them out of the nest while they're under my wing, so to speak.

How can I impart just enough information so that they will learn but not give so much as to solve the problem for them?

Or perhaps:

What's the proper response to questions that are designed to take the path of least resistance and, in essence, force them to learn instead of take the easy way out?

These questions are probably more general teaching questions and don't have that much to do specifically with software development.

Note: I do not get a say in what tasks they are working on. Management doles the task out and it could be anything from a very simple bug fix to starting an entire application by themselves. While this is not ideal by any means and obviously presents its own gauntlet of challenges, I feel it's a topic best left for another question. So the best I can do is help them with the problem at hand and try to help them break it down into simpler problems and also check their commit logs and point out mistakes that they made.

My main objectives are to:

Help them out and give them the tools they need to start becoming more self-reliant.

Steer them in the right direction and break bad development habits early on.

Lessen the amount of time I spend with them (the personality type described above tends to need much more one-on-one time and does not do well over IM or email. While that's generally fine, I can't always stop what I'm working on, break my stride, and help them debug an error on a moments notice; I have my own projects that need to get done).

答:
I have not seen anyone here mentioning my personal hero, Randy Pausch.

I think it can be beneficial for anyone actually doing, teaching or mentoring programming (or even for anyone who want to live a meaningful life). You and/or your colleagues might find watching these lectures worth the time as I have, on

achieving your dreams (he WAS a professor and this is heavily related to motivating others), and

time management.

Title: How to Mentor a Junior Developer


答:
State is evil. The following function does not need a unit test because it has no side effects and it is well understood what it does and what it does not do. Why test it? Do you not trust your own brain??? Static functions are great!</p>

```<code>static function bool Foo(bool a, bool b, bool c)
{
    return a && b && c;
}
</code>```

Body:
State is evil. The following function does not need a unit test because it has no side effects and it is well understood what it does and what it does not do. Why test it? Do you not trust your own brain??? Static functions are great!

static function bool Foo(bool a, bool b, bool c)
{
    return a && b && c;
}