问:
Are testers considered low profile?
I happened to know some system admin and according to him, testing guys are not given preferences in an organization in comparison to developers. No doubt software releases are not possible without testers but I've never laid my hands on testing so not much aware of it. No offense intended. </p>

答:
I've worked as a functional tester for a year on a fairly large project. Each team of about 10 members had 2-3 were testers. I must say that we were treated as equally important to the project as the developers.

Finding bugs is not easy. First, the testers have to understand what the code is suppose to do. That means reading and understanding the requirements. Key here is understanding the requirements - if the testers can't understand the requirements well enough to know how to to write positive test cases, you should be worried. This means that the developers have written some code that does what they've assumed it to do. Is this assumption the right one? You don't know until you've sorted out the requirements, and you can thank your testers for finding that flaw.

Second, the testers have to write false test cases, which ensures that the code does not what it's not supposed to do. A reasonable rule of thumb is that you write 5-10 false test cases for every positive test case. This means understanding the requirements even further, and often this information is, or was at least in our project, confusing and ambiguous. (And it wasn't because of low effort on gathering requirements - we had something like 13,000 in our team alone.) Again, the developers will have written their code using their assumptions, or even worse, not even considered this at all. So what does the code do under these conditions which are not normal? You don't know until you've tested it. Maybe the program doesn't respond; maybe it just crashes; maybe it destroys data; maybe it allows the user to run commands as root user. Whatever it does, you want to know. Otherwise you may find yourself reading the following headline in the newspaper one day - BUG IN [YOUR COMPANY NAME]'S FLAGSHIP PROGRAM LEAKS CLIENTS' CREDIT CARD NUMBERS. You can thank your testers if this doesn't happen.

So treat your testers good. Treat them well. After all, they are the ones who root out the bugs in your software and make your, and our, life easier.

Title: Are testers considered low profile?


问:
How can a developer evaluate the effectiveness of his workflow?
This question has been on my mind for probably 10 years. Ever since I've started programming for a living. And I've seen multiple discussions about good fit, distractions, being in the zone, etc. But I haven't seen links to some information/research that could give an objective self evaluation measure/tool to understand how you're really doing.

What constantly bugs me, is that I think I'm not spending enough time on coding, and the effective work hours are not 8 out of 8, but less, with some days being even super ineffective, exactly like in this article.

There are some metrics expressed as lines of code per day, with some sources quoting 1.5 being good and some sources indicating 500 per day being normal, but this again, is completely invalid metric as far as I can see.

So at the end of the day, you have an assignment, you do it, but part of the time evaporates in sort of like "wth I was doing" kind of way. Emails, just staring at the code, thinking, painting a mental picture of the code in your head, floating somewhere, rethinking how things could have done more effectively, etc.

And because of that, I'm never sure if I need to do something ASAP, to keep the raises coming, or am I paranoid, or is it just normal.

The only half-good measure I've found so far, is seeing the amount of code other developers produce-vs-code I produce. And that usually floats around same number. But when I look at my code, or others code I still always get a feeling it could be done 10x faster.

Then again, code crunching doesn't seem to work, or does seem to cause a burnout if not handled properly.

So do you know of a good self evaluation approach to see if you're ineffective/effective? How do you weight the work you've done?

答:
I don't know if there's a "documented best way", but I would suggest that you should try personal A/B testing. Pick your favorite metric - lines coded, progress towards goals made, features implemented, etc - and then switch things around on a bi-weekly schedule. Start using the Pomodoro technique. Try using multiple monitors. Try blocking internet access to time-wasting. Try exercising in the middle of the day. Try any of the bazillion or so fads that promote themselves as increasing productivity, and see which ones work for you.

It will take a long time, sure, but it's all during your regular work anyway, and worst case scenario you've just tried a bunch of different things and now you know that you're just as (un)productive no matter which ones you use.

ContentLicense: CC BY-SA 3.0


问:
Does the LGPL allow me to do this?
I am planning to develop a commercial software using a LGPL software.

In the LGPL software that I am using some functions in a class are not fully implemented. I want to modify the LGPL code so that the class and not-implemented functions are made visible outside the dll by adding dllexport infront of class and by adding virtual keyword infront of function.

Then I plan to implement those functions in my proprietary software. I am ready to distribute the modified LGPL code but not proprietary software that implements functions in the way I want.

Does that violate LGPL terms and conditions?

答:
Standard I am not a lawyer disclaimer.

LGPL requires modifications to the library source code to be distributed to anybody that used your code. It does not require that your code, which uses the library, be open-sourced and released under the same license.

Wikipedia for a more detailed, but non-lawyer description of LGPL, including a section on class inheritance.

Title: Does the LGPL allow me to do this?


答: Counting the lines of code is one of the most useless metrics I can think of.  Sounds like there's more of a prioritizing issue at play than effectiveness.</p>

Title: How can a developer evaluate the effectiveness of his workflow?

Body:
This question has been on my mind for probably 10 years. Ever since I've started programming for a living. And I've seen multiple discussions about good fit, distractions, being in the zone, etc. But I haven't seen links to some information/research that could give an objective self evaluation measure/tool to understand how you're really doing.

What constantly bugs me, is that I think I'm not spending enough time on coding, and the effective work hours are not 8 out of 8, but less, with some days being even super ineffective, exactly like in this article.

There are some metrics expressed as lines of code per day, with some sources quoting 1.5 being good and some sources indicating 500 per day being normal, but this again, is completely invalid metric as far as I can see.

So at the end of the day, you have an assignment, you do it, but part of the time evaporates in sort of like "wth I was doing" kind of way. Emails, just staring at the code, thinking, painting a mental picture of the code in your head, floating somewhere, rethinking how things could have done more effectively, etc.

And because of that, I'm never sure if I need to do something ASAP, to keep the raises coming, or am I paranoid, or is it just normal.

The only half-good measure I've found so far, is seeing the amount of code other developers produce-vs-code I produce. And that usually floats around same number. But when I look at my code, or others code I still always get a feeling it could be done 10x faster.

Then again, code crunching doesn't seem to work, or does seem to cause a burnout if not handled properly.

So do you know of a good self evaluation approach to see if you're ineffective/effective? How do you weight the work you've done?


问:
What web frameworks are capable of loading other web apps at runtime?
I am not sure how to phrase this, but in asp.net there is the notion of a "web application" that is fundamentally just a DLL that the web server loads.  It has the ability to dynamically discover and load user controls at runtime (e.g. a customized button), using something called MEF (which can discover dlls and load them).  What I have not been able to find anything about is if it asp.net is capable of loading other asp.net web applications.  E.g. web application A, looks for any dlls in a folder and dynamically loads them one by one (and maybe loads their index.html pages in a iframe).

Can this be done in asp.net or other web frameworks?

答:
Sounds like a bit of background research is in your future... Yes, asp.net 4.0 does have MEF, which allows you to, in theory, build web applications that can technically have extended functionality by a third party through interfaces and a few decorators.  It's slightly hairy though, because of the ascx and asps pages... If you choose to go through using asp.net MVC, it may be slightly easier.  As you do your research, you'll find that there are two main paths people take.. Asp.net MVC, and web forms (some just list it as asp.net,)

If you go mvc, you'll want to look at portable areas to create the functionality you're talking about.


答: Sounds like you're looking for a widget framework. You could achieve this with something like wookie. Also, look into IWC (Inter-widget Communication).</p>

Title: What web frameworks are capable of loading other web apps at runtime?

Body:
I am not sure how to phrase this, but in asp.net there is the notion of a "web application" that is fundamentally just a DLL that the web server loads.  It has the ability to dynamically discover and load user controls at runtime (e.g. a customized button), using something called MEF (which can discover dlls and load them).  What I have not been able to find anything about is if it asp.net is capable of loading other asp.net web applications.  E.g. web application A, looks for any dlls in a folder and dynamically loads them one by one (and maybe loads their index.html pages in a iframe).

Can this be done in asp.net or other web frameworks?


问:
Releasing patches and updates to web service users
I have written one web services using Java. Its already live (up and running).

During development I have SVN (repository) + Jira for task maintenance + Maven for building the web services. Now I have some small update for my web services and I have created that task in Jira and committed the files in svn with respect to Jira-Id after all testing, etc.

Say my web services is used by 10 clients, we did not give our source code to them.

Is there any steps/procedure available to release patch/updates?

Is there any way to render/create the change log at the build time (maven)?

How do I manage the change log for all version or Patch updates during build time?   (Automatically)

答:
Ideally you should try to distribute binaries in the form of package - such .deb or .rpm.  This is not limited to distributing the packages for desktops alone, the packages can contain configuration files, module binaries and documentation.

Also, packages provide great way to apply dependency checks.

Once, you distribute elements as packages - there are mechanisms to declare patched versions (or incremental versions).Refer to this for more information. http://www.debian.org/doc/manuals/maint-guide/build.en.html

Now, as far as - making release patches are concerned, ideally you should have every check-in with messages. Using SVN, you can use svn log to view all this. You can use this between specific versions as well. Based on this,you should create release-notes for every patch you produce and tag it.

The point is using svn log (if your logs are good) can be an automated mechanism to produced change-logs automatically.


问:
Should developers enter bugs into the bug tracking system?
While developing (either features or bug fixes) I sometimes happen to discover bugs that are not directly related to what I'm working on.  What should I do in that situation.  Just fix it?  Try to remember to fix it later?  Write it down somewhere?  Or enter it into the bug tracking system?

I generally enter it into the bug tracking system and let the process play itself out (i.e. triaging, assigning, etc.).  However I have hardly ever seen another developer enter a bug.  (Why is that?)

答:
Indeed you should be recording them in the system, and in case it's not practiced then it's good to start off.

In my past I was part of a product team, and we were on the beta release of a new product and at times we occasionally found bugs which at that point we used to note down and mail to the respective persons handling the modules (we had a bug tracking system, but we didn't think of pushing them there). Later on when days went by the items in the mail started to get ignored because of other priorities and that eventually lead to some sleepless nights.

Then, bang one day, Nirvana! Why are we not using the bug tracker, even if you found something which seems like a bug and could be possible that it isn't one (your thought about the process is wrong/flawed). It at least makes up on the list which could then be tested and most important of all a feedback as to why it's critical or on the flip side it is perfect and that's how it should work because of reasons 1... 2....

Now you have the list and also for those who have misunderstood some parts of the application they have the feedback based on which they can clarify their thoughts. A win-win situation.


问:
How to deal with variables when extracting methods in to smaller methods?
This is an abstract question to clarify a refactoring concept in the ruby language.  Assume in the real world that there would be many more variables and method in the Furniture Class and Refinish method.

I have a Class called Furniture.

It has a method called 'refurnish(VarnishToUse, TimeToTake)'.
This method has

```<code>varnish_cost = Varnish(VarnishToUse).price * TimeToTake
</code>```

I want to extract out the cost calculation into

```<code>def VarnishCost
  price * TimeToTake
end
</code>```

then the Furniture class can just have:

```<code>def Refurnish(VarnishToUse)
  varnish_cost = VarnishCost(VarnishToUse)
end
</code>```

How do I pass in the VarnishToUse into VarnishCost?  Should the method be

```<code>def VarnishCost(Varnish)
...
end
</code>```

or should I be setting an instance variable @varnish = VarnishToUse in the Refinish class and then just expect that instance variable to be available in the VarnishCost method as I showed above?  Does it make a difference if the other method is private? protected?

I am looking to minimize the use of variables and multiple responsibilities for a class (SRP).

答:
should I be setting an instance variable @varnish = VarnishToUse in the Refinish class

You should do this when there are some other functions in your Refinish class which can use varnish, too, and when having a somewhat "global" (in the context of your class) variable in your code does not give you a higher risk of malfunction (for example, when varnish does not change any more after first initialization). Especially the second condition should be fulfilled, otherwise pass VarnishToUse as a parameter.


问:
How to connect iPad app to an app I have running in Windows
I recently picked up a macbook and want to start doing some apps for my ipad. I have a chat client written in c# that interfaces a game I play. What I would like to do is write an app for the ipad that would communicate somehow with my c# app.

What would be the best approach to this? I have never used JSON but is this where I should be looking?

I don't want to spend a ton of time looking in the wrong place, hoping someone here could point me in the right direction.

答: there are already proven standards that exists to solve this problem such as web-services, soap, and JSON. I would recommend you to use a web-service.</p>


问:
Prepare source code handover plan
Our company is about to acquire a source code of a huge product.

What are thing to take into consideration when the handover starts, to make sure we have everything and be capable to maintain that product in the future?

答:
What are thing to take into consideration when the handover starts, to make sure we have everything and be capable to maintain that product in the future?

The things you should make sure are :

you see them build the code successfully

you see them build unit tests and make all pass

you see them execute other tests successfully, and all pass (acceptance, integration, etc)

you get the database of open issues (easy to get if they use bugzilla, or similar)

the product runs (installation instructions).

Everything else is up to the current maintainer to hand over.

Title: Prepare source code handover plan


答:
Firstly good luck.

Here are some of the things which you probably should ask for / be provided with.

List of known defects.

List of incident and problem records.

Details on the last two releases like; how long did they take to implement, was there a period of increased incidents following the release, etc.

Who are the key subject matter experts.

What are the hours of operation and primary support.

How long has the product been in existence and how stable is the code base.

What is the product roadmap.

What is the technology stack.

What are the integration points, and who supports the integrated systems.

Is there any DR components

Who is responsible for invoking DR

What are the application SLAs or service targets.

What is the expected growth of the file system / database / message queues.

When are system backups performed, who is responsible and what is the restoration strategy.

Who is responsible for managing the product backlog.

What vendor SLA and contact details are in place.

Are there any batch schedules or long running processes.

Is the system completely transactional and how is concurrency managed.

What is the major incident management process for the application.

What, when, who and how are the stakeholders notified of changes and outages.

What are the agreed outage periods / times.

Where is the source code kept.

How is the source code backed up, restored and change log managed.

Where, what and who owns the solution architecture.

What is the deployment target (DEV, ST, UAT, Pre PROD, PROD, DR).

When are the 3rd party licenses renewed.

Is there a RACI chart

How many users are there and where are they located.

What are the common troubleshooting problems or complaints.

Who is responsible for granting system access.

When are pent tests / security audits undertaken.

Where is the CI and automated build process.

Who is responsible for administering the source control and build server.

Where are the installation guides.

Is there documentation for the target infrastructure and network.

What are the types of severity and impact from recent incidents.

Are there developer workstation setup instructions.

What development aides and frameworks are used and are they licensed for your team.

That's about all I can think of at the moment.

Title: Prepare source code handover plan

Body:
Our company is about to acquire a source code of a huge product.

What are thing to take into consideration when the handover starts, to make sure we have everything and be capable to maintain that product in the future?


问:
Creating Compelling Desktop Application in .NET
I'm about to create an open source desktop application.  I'm primarily a .NET developer , with experience in ASP.NET and SharePoint.  I've created basic Windows Forms applications before, but I have never developed using WPF or Silverlight before.  I want a compelling, highly interactive UI for my desktop application.  What are my technology choices for doing this, using .NET?  In particular, is HTML5 something I should be considering?</p>

答:
I always give this advice to any developer that wants to build something on his own: focus on building the product, don't spend a large amount of time on thinking what technology to choose. There is no 100% right answer for your question because you didn't specified what the application will do, what kind of problem will solve.

My personal point of view: HTML 5 is not yet suitable for desktop applications. Just go with WPF, build an awesome desktop product, please some users, find some people to work with. Later you can consider building a HTML5 version of your application.
Good luck!


答:
You don't appear to refer to the objective of the code you are writing at all. I'm of the opinion that if you want to evaluate how effective you are in writing code, you need to evaluate it in terms of how well it matches the requirements fed to you. I don't see this as an evaluation of workflow - an evaluation of your workflow should cover a) does it leave you constantly stressed, b) does it enable you to write effective code that fulfills your requirements c) do you spend a lot of time firefighting/bug fixing d) do you design effectively up front e) do you split your time for design/code/testing effectively such that you get a balance that doesn't cause you to spend a lot of time bug fixing, firefighting and stressing. f) do you have the right tools to do help you do your job effective and if you don't can you recognise what's missing

In short, you need to differentiate between evaluating your workflow (process) and your output. They are two different things although it is likely that an effective workflow will improve your ability to generate output.

Counting lines of code is a very bad way of measuring output or workflow. It's an accounting idea that sees code as widgets. Code isn't a widget however, it's a way of doing things and sometimes something important can be done in 2 lines of code more effectively than in 1000 lines of code. A LOC metric fails in this respect and it's not uncommon

I work on a system where brevity and speed are vital. But because of business requirements, it's not always wise to use least LOC as a metric either. What matters is effectivity versus business requirement and most people have trouble measuring that.


答:
You can only evaluate a productivity enhancing technique if, during your experimentation everything else remains constant. This is obviously impossible if you have a varied workload.

My advice would be to find a number of problems of equal difficulty, (for example, by looking at problems from project Euler) and then trying different techniques on different problems, measuring your completion time.

It's important that the technique that you use is the only variable changing, so try to eliminate every other variation. Perhaps you could eliminate alertness from the equation by only doing one or two problems a day before anything else.

Repeat until your results are conclusive.


问:
Re-inventing system design for Scala
Many, many, moons ago, I did my masters in Object Orientated Software Engineering. I covered everything: project initiation, requirements, analysis, design, architecture, development, etc, etc. My favourite IT book of all time was Developing Object Oriented Software, an Experience Based Approach (IBM-1996). A book created by a group of true experts of their time. It describes a work product centric approach to object oriented analysis, design and development methods.

I designed and developed and was happy and at the top of my game, but I started to feel a little dated: Agile movements became fashion of the day and re-branded some well known iterative and incremental approaches with new hip words. Suddenly inexperienced developers started frowning when I said "requirements" or "architecture" as if these things were superseded by magic.

Design and development lost it's fun and I was about to leave the whole IT industry behind me.

Then I discovered Scala. Oh, like soft rain on a dusty road. Everything just became clear, the air became sweet again and the little light of my hard-drive would flicker deep into the night, merrily keeping me company in my world of discovery.

I like system design. I'm an architect at heart, more than a programmer. I love analyzing, designing, thinking, arguing, improving - I just love simple, clean and crisp designs.

How do we design pure Scala solutions?

Surely conventional sequence diagrams, interaction diagrams, object diagrams, etc, could all be replaced or improved for the goodness of blending imperative and functional object orientated systems. Surely there is an opening for something totally different!

I'm not looking for bloated complexity - I'm looking for flexible simplicity. Much like Scala is actually simple and easy (albeit different), but can be extended to fit your requirement like a pair of Yoga pants. There must be a design system for this lovely language that will start simple, and can be extended to fit your requirements and your domain. Surely UML can not be it!

So how do we design pure Scala systems? Imagine for a moment, you have the luxury to design a complete system from scratch, and know that you will only be using Scala - How will your models look? What types of diagrams would you have to describe structure and behaviour? How would you model Options, matches, mixins, singleton Objects, etc. without being drawn into the complexity of extending existing modeling techniques rather than a fresh, light-weight, innovative tool-set.

Does such a design/process/solution exist, or is it time to invent one?

答:
The question was: How do we design pure Scala solutions?

Answers like,

We use XYZ because ....

We use ABC but like so ....

We started using XYZ, but then found ABC to be better because ...

would have indicated some maturity, or generally accepted existence, of such a tool-set or solution.

Comments relating to whether it's appropriate to consider a Scala specific design tool-set is a different matter. My opinion on this is that Scala is revolutionary in the way it combines imperative and functional programming. Scala captures an amazing breath of development practices, concepts and principles, and so, in finding a solution that is the perfect fit for Scala, we will probably discover a solution for which a subset will serve many other languages very well also.

Is it safe to say then, that we know the answer to the fallback question:

"... is it time to invent one?"

Could it be yes? (Where 'yes' does not prescribe the means to the solution. It could be achieved either by extending an existing solution, or creating one from the ground up. It does admit though that there are significant shortcomings in existing design options)

You are welcome to vote my answer down if you disagree. I'll take it like a man.

OwnerDisplayName: JacobusR

Title: Re-inventing system design for Scala


问:
When should you call yourself a senior developer?

Possible Duplicate:

  Whats the difference between Entry Level/Jr/Sr developers?

I'm curious what senior developer means because apparently the definition doesn't mean what I thought it would. I keep seeing these teens at 22-23 years old who call themselves senior X developer or senior Y developer. To me, a senior must have 10 years or so experience in programming to call himself 'senior'. I've seen a lot of these teens here (hence the question). Am I wrong? Why?

答: I find this "Junior/Senior Developer" title wrong and misleading because there's no real measurement unit for this. We're all Software Developers with less or more hands-on experience. Don't try to create a hierarchy for Software Developers, there's no point and it can harm the main focus point: a great-software development team.</p>


答:
You are right about lines-of-code is a completely meaningless figure. As one of the original bearded UNIX hackers put it: "Today was a very productive day. I deleted 1000 lines of code."

You are also right about crunch mode being mostly counter-productive. It is possible to force yourself to type faster, but this inevitably comes at the cost of thinking your code through. You'll build up technical debt, and you'll have to pay for it one way or the other. Permanent crunch mode is a perfect recipe for unmaintainable code.

Your problems doesn't seem to be one of productivity, but rather one of management. It looks like you are being managed badly, or not at all. You need a list of tasks with priorities and time estimates. The time estimates have to be yours (you are the best qualified person to estimate how long it takes you to do something), the prioritizing has to be done by the person responsible for managing the project. With these two in place, it is both clear what your next task is, and when you'll get around to task X. Be sure to include all the overhead (thinking, staring, research, communication) in your estimate. Also, measure how long it actually took you to complete the task, and use this information to adjust future estimates - your estimates are going to be more reliable over time if you do this.

About the "actual coding vs. overhead" issue; don't expect to be actively coding 8 hours a day, it's simply not realistic. Spending 1/3 or more of a project's budget on design is not unusual, and it's not a bad thing either - design changes are generally cheaper than code changes. Add to that self-management overhead, mental blocks (we all have those), interruptions, communication overhead, paperwork, keeping your development environment up-to-date, and all those other pesky little annoyances, and you'll quickly drop below 50% of your working day spent on programming. Of those 50%, you probably spend half or more thinking, reading code, researching, etc., so spending three hours or less per working day on actual programming isn't unusual at all. Programming is a mind game, it's not like assembly line work.

So, how do you assess your productivity? Programmer performance isn't generally quantifyable, so you'll have to go with subjective figures:

Customer satisfaction

Employer satisfaction

Reliability of the software you write

Correctness (does your software meet the specs? does it consistently produce the right results?)

Robustness (does your code handle errors gracefully? does it contain a low number of critical bugs?)

Code maintainability (is it easy and safe to change your code?)

Usability (do users find your application easy to use?)

Personal growth (does the subjective quality of your work increase over time?)

...


答:
If these are all methods in the Furniture class, you don't need to "pass" anything, just access the methods:

```<code>class Furniture
  attr_accessor :time_to_take
  attr_accessor :varnish_to_use

  def varnish_cost
    varnish_to_use.price * time_to_take
  end

  def refurnish
    # varnish_cost * markup_percent + premium # if you want to affect the price more...
    varnish_cost
  end
end

class Varnish
  def self.price
    # default price
    10
  end
end

class BasicVarnish < Varnish
  def self.price
    5
  end
end

class PremiumVarnish < Varnish
  def self.price
    20
  end
end

so now:
f1 = Furniture.new(:time_to_take => 2, :varnish_to_use => BasicVarnish)
f1.refurnish => 10

f2 = Furniture.new(:time_to_take => 2, :varnish_to_use => PremiumVarnish)
f1.refurnish => 40
</code>```

(PS I changed the names of the methods as it's a bit confusing having them as Constants)

Title: How to deal with variables when extracting methods in to smaller methods?

Body:
This is an abstract question to clarify a refactoring concept in the ruby language.  Assume in the real world that there would be many more variables and method in the Furniture Class and Refinish method.

I have a Class called Furniture.

It has a method called 'refurnish(VarnishToUse, TimeToTake)'.
This method has

```<code>varnish_cost = Varnish(VarnishToUse).price * TimeToTake
</code>```

I want to extract out the cost calculation into

```<code>def VarnishCost
  price * TimeToTake
end
</code>```

then the Furniture class can just have:

```<code>def Refurnish(VarnishToUse)
  varnish_cost = VarnishCost(VarnishToUse)
end
</code>```

How do I pass in the VarnishToUse into VarnishCost?  Should the method be

```<code>def VarnishCost(Varnish)
...
end
</code>```

or should I be setting an instance variable @varnish = VarnishToUse in the Refinish class and then just expect that instance variable to be available in the VarnishCost method as I showed above?  Does it make a difference if the other method is private? protected?

I am looking to minimize the use of variables and multiple responsibilities for a class (SRP).

Body:
If these are all methods in the Furniture class, you don't need to "pass" anything, just access the methods:

class Furniture
  attr_accessor :time_to_take
  attr_accessor :varnish_to_use

  def varnish_cost
    varnish_to_use.price * time_to_take
  end

  def refurnish
    # varnish_cost * markup_percent + premium # if you want to affect the price more...
    varnish_cost
  end
end

class Varnish
  def self.price
    # default price
    10
  end
end

class BasicVarnish < Varnish
  def self.price
    5
  end
end

class PremiumVarnish < Varnish
  def self.price
    20
  end
end

so now:
f1 = Furniture.new(:time_to_take => 2, :varnish_to_use => BasicVarnish)
f1.refurnish => 10

f2 = Furniture.new(:time_to_take => 2, :varnish_to_use => PremiumVarnish)
f1.refurnish => 40

(PS I changed the names of the methods as it's a bit confusing having them as Constants)


问:
Suitable vocabulary when helping novice programmers
I find myself aiding novice programmers relatively often; explaining why their code won't work when they ask, suggesting solutions and the like. The people I'm helping do have a formal education in programming from a first-year degree-level module, in Java, but I feel like I can't communicate with them very well.

For example: one might write a function but not understand why it isn't executed, not realising they forgot to call it. If I use phrases like "(make a) call (to) the function/it" and "pass it the.." I get blank looks.

My normal process then would be to find some place in their code where they call a function from the language, and tell them they can call their own functions in the same way as they called this other function. Sometimes even that gets blank looks.

Are there other pieces of vocabulary that are more suited to (better for?) helping novice programmers? Or is this not an issue of communication?

答:
They'll have to learn the proper terms eventually, the sooner the better.

Use them correctly, and explain them whenever you get a blank stare. Just try to send the right signals, that it's OK to ask about anything they don't understand - the only stupid questions are those you don't ask.


问:
Is it a problem to have different styles of HTML coding within team?
I with 2 other friends are new to web development. We are learning HTML, CSS, Javascript and are creating simple websites to get a feel of different things. And as HTML is only a markup and not a programming language we have very different styles evolving. I mean whenever we look at each other's code, we tend to put a good amount of time in understanding why the other one does that.

Now we want to build a larger website together and my question is- Is that a problem having very different styles in a team for web development(specifically)?

答:
You still need to maintain HTML/CSS. As you say:

we tend to put a good amount of time in understanding why the other one does that

Just because it is markup does not mean that you should ignore good practices of working in a team.

If you standardize on how to do things, such maintenance burden will be significantly lowered.


答:
It is part of an HTML author’s competence to be able to read HTML markup written in different styles (e.g., nesting, uppercase ~ lowercase, quotes around attribute values).

In a large project it may well be useful to decide on such matters. More importantly, decisions are needed on higher-level issues such as the use of tags, naming of id and class attributes, the use of external stylesheets and scripts vs. embedded styles and scripts, and conformance to HTML specs (HTML 4.01 ~ XHTML 1.0 ~ HTML5 ~ something else).

Title: Is it a problem to have different styles of HTML coding within team?

Body:
I with 2 other friends are new to web development. We are learning HTML, CSS, Javascript and are creating simple websites to get a feel of different things. And as HTML is only a markup and not a programming language we have very different styles evolving. I mean whenever we look at each other's code, we tend to put a good amount of time in understanding why the other one does that.

Now we want to build a larger website together and my question is- Is that a problem having very different styles in a team for web development(specifically)?


答:
In general

When a person doesn't understand you, you have two alternatives:

Adapt the vocabulary according to what the person knows or not,

Explain to the person the terms she doesn't understand.

The first case works well when the person knows already the technical vocabulary quite well, but not enough, or not in your domain.

For example, you may use the term method in C# or Java, and the person who mostly works with some other language would not understand this term. You will then explain that in C# or Java, method is referring to what we usually call function (for example in C), and that there is no such a thing as function in C# or Java. In PHP, for example, both methods and functions exist, and have a different meaning. If the difference is too painful for the person, you will talk about functions for the sake of simplicity.

In your precise case, you can hardly choose the first one: "make a call to the function" cannot be reformulated in any simpler way. A call is a call. You can't simplify this more.

This means that you have to choose the second way: explain to the person each technical term.

Either point the person to a dictionary or Wikipedia, which works very well for basic concepts and terminology.

I would choose this for commonly used terms. For example, I would rather invite the person to read Wikipedia to understand what is polymorphism, or what are covariance and contravariance. Those terms are already explained very well, so don't need to reinvent the wheel here.

Or explain in your own words.

I would choose this for terms which are specific to the context and/or accepting wide range of definitions. For example, Wikipedia is not very helpful to understand the Microsoft's vision of cloud computing, and I would rather explain myself what is cloud to somebody who will be working on a Windows Azure application.

In your particular case

The people you are talking to are lacking the most basic concepts and terms used in programming. They can't continue without learning this core vocabulary, because they are unable to communicate at all: they can't read books about programming or blogs, they can't listen to their colleagues, and they even can't really ask questions on Stack Exchange websites, since nobody will understand what they are asking.

In your case, rather than searching for suitable vocabulary, I would spend a few days or weeks teaching them some core programming concepts and the commonly used terms. After a few days, you will be able to talk to them without  being required to constantly "draw them pictures and use metaphors involving cats and dogs".

Title: Suitable vocabulary when helping novice programmers

Body:
I find myself aiding novice programmers relatively often; explaining why their code won't work when they ask, suggesting solutions and the like. The people I'm helping do have a formal education in programming from a first-year degree-level module, in Java, but I feel like I can't communicate with them very well.

For example: one might write a function but not understand why it isn't executed, not realising they forgot to call it. If I use phrases like "(make a) call (to) the function/it" and "pass it the.." I get blank looks.

My normal process then would be to find some place in their code where they call a function from the language, and tell them they can call their own functions in the same way as they called this other function. Sometimes even that gets blank looks.

Are there other pieces of vocabulary that are more suited to (better for?) helping novice programmers? Or is this not an issue of communication?


答:
this is an issue within our team, where there are two different html developers who have different coding styles, but we do not force on them anything specific, so that they can work efficiently and happily. And we have never experienced a problem where the two are completely unable to understand each other's html.

The same is true for any style of programming.

Basically you just need to have special considerations on "documenting the code". And everything will be good to go.


问:
Does giving a developer a slower development machine result in faster/more efficient code?
Suppose I give my developers a screaming fast machine.  WPF-based VS2010 loads very quickly.  The developer then creates a WPF or WPF/e application that runs fine on his box, but much slower in the real world.

This question has two parts...

1) If I give a developer a slower machine, does that mean that the resulting code may be faster or more efficient?

2) What can I do to give my developers a fast IDE experience, while giving 'typical' runtime experiences?

Update:

For the record, I'm preparing my even-handed response to management. This isn't my idea, and you folks are helping me correct the misguided requests of my client.  Thanks for giving me more ammunition, and references to where and when to approach this.  I've +1'ed valid use cases such as:

- specific server side programming optimizations

- test labs

- the possibly buying a better server instead of top of the line graphics cards

答:
I think this is an interesting question, and I wouldn't go for a "no" that quickly. My opinion is: it depends on what kind of developing team we are talking about. Example: if you are leading a group that's running for the annual ICFP programming contest, maybe having good results after a small amount of developing time on a HPC cluster wouldn't necessarily mean that the solution you found is good. The same can be said if you are writing some scientific or numerical algorithm: on your old AMD Duron 600 MHz with 64 MB of memory you're forced to be careful about the way you are getting things done, and this may affect even some design choices.

On the other hand, a smart programmer/scientist/whatever is supposed to be careful anyways. But I found myself writing down some of my best codes when I had NO computer AT ALL and had to take notes on paper. This may not apply for big projects involving huge frameworks, when an IDE is strictly necessary.

One thing is sure: fast machines and good immediate results make (bad) programmers spoiled and may be one of the reasons for some of the crap we find on computers.

ContentLicense: CC BY-SA 2.5


问:
Online Code Editor
The major online IDEs are hosted on the service provider's server. Examples are Kodingen, Cloud9, ShiftEdit. Hence they would be unavailable if the external server was down for some reason, and I prefer to do my computing on my own computer anyway.

Does anyone know of an online IDE or editor (preferably just an editor - a simple implementation of the Ace or CodeMirror JS editors) which can be downloaded and run on localhost (on a local LAMP server)? I've found two so far - Eclipse Orion and Wiode, but I don't like either of them very much, and I'm looking for alternatives.

Also suitable are browser extensions which run natively on the browser (offline) without going to some external site. An example would be SourceKit for Chrom(e/ium).

答:
First, you can take a look to this article:

Wikipedia ― Comparison of JavaScript-based source code editors.

For more, here is some tools that seem to fit with your request:

All of these software are downloadable, and usable on a local server.

EditArea ― Download ― Demo as FileEditor who is a Yii Extension ― (Apache Software License, BSD, LGPL)

Here is EditArea, a free javascript editor for source code. It allow to write well formated source code with line numerotation, tab support, search & replace (with regexp) and live syntax highlighting (customizable).

CodePress ― Download ― Demo of Joomla! CodePress Plugin ― (LGPL) ― It doesn't work in Chrome and it looks like development has ceased.

CodePress is web-based source code editor with syntax highlighting written in JavaScript that colors text in real time while it's being typed in the browser.

CodeMirror ― Download ― One of the many demo ― (MIT-style license + optional commercial support)

CodeMirror is a JavaScript library that can be used to create a relatively pleasant editor interface for code-like content ― computer programs, HTML markup, and similar. If a mode has been written for the language you are editing, the code will be coloured, and the editor will optionally help you with indentation

Ace Ajax.org Cloud9 Editor ― Demo ― (Mozilla tri-license (MPL/GPL/LGPL))

Ace is a standalone code editor written in JavaScript. Our goal is to create a web based code editor that matches and extends the features, usability and performance of existing native editors such as TextMate, Vim or Eclipse. It can be easily embedded in any web page and JavaScript application. Ace is developed as the primary editor for Cloud9 IDE and the successor of the Mozilla Skywriter (Bespin) Project.

  Getting the code

  Ace is a community project. We actively encourage and support contributions. The Ace source code is hosted on GitHub. It is released under the Mozilla tri-license (MPL/GPL/LGPL). This is the same license used by Firefox. This license is friendly to all kinds of projects, whether open source or not. Take charge of your editor and add your favorite language highlighting and keybindings!

  git clone git://github.com/ajaxorg/ace.git

Moreover, it seems that this question have been asked twice on stackoverflow, so you can probably gather more information here:

Textarea that can do syntax highlighting on the fly?

textarea with syntax / code highlighting dead link, question removed (q/1505761)

AjaXplorer implements CodeMirror's advanced editor. This provides you with file management and syntax highlighted code editing in a single, multi-user application.

Title: Online Code Editor


问:
Which statically typed languages support intersection types for function return values?

Initial note:

This question got closed after several edits because I lacked the proper terminology to state accurately what I was looking for. Sam Tobin-Hochstadt then posted a comment which made me recognise exactly what that was: programming languages that support intersection types for function return values.

Now that the question has been re-opened, I've decided to improve it by rewriting it in a (hopefully) more precise manner. Therefore, some answers and comments below might no longer make sense because they refer to previous edits. (Please see the question's edit history in such cases.)

Are there any popular statically & strongly typed programming languages (such as Haskell, generic Java, C#, F#, etc.) that support intersection types for function return values? If so, which, and how?

(If I'm honest, I would really love to see someone demonstrate a way how to express intersection types in a mainstream language such as C# or Java.)

I'll give a quick example of what intersection types might look like, using some pseudocode similar to C#:

```<code>interface IX { … }
interface IY { … }
interface IB { … }

class A : IX, IY { … }
class B : IX, IY, IB { … }

T fn()  where T : IX, IY
{
    return … ? new A()
             : new B();
}
</code>```

That is, the function fn returns an instance of some type T, of which the caller knows only that it implements interfaces IX and IY. (That is, unlike with generics, the caller doesn't get to choose the concrete type of T — the function does. From this I would suppose that T is in fact not a universal type, but an existential type.)

P.S.: I'm aware that one could simply define a interface IXY : IX, IY and change the return type of fn to IXY. However, that is not really the same thing, because often you cannot bolt on an additional interface IXY to a previously defined type A which only implements IX and IY separately.

Footnote: Some resources about intersection types:

Wikipedia article for "Type system" has a subsection about intersection types.

Report by Benjamin C. Pierce (1991), "Programming With Intersection Types, Union Types, and Polymorphism"

David P. Cunningham (2005), "Intersection types in practice", which contains a case study about the Forsythe language, which is mentioned in the Wikipedia article.

A Stack Overflow question, "Union types and intersection types" which got several good answers, among them this one which gives a pseudocode example of intersection types similar to mine above.

答:
Original question asked for "ambiguous type". For that the answer was:

Ambiguous type, obviously none. The caller needs to know what they'll get, so it's isn't possible. All any language can return is either base type, interface (possibly auto-generated as in intersection type) or dynamic type (and dynamic type is basically just type with by-name call, get and set methods).

Inferred interface:

So basically you want it to return an interface IXY that derives IX and IY though that interface was not declared in either A or B, possibly because wasn't declared when those types were defined. In that case:

Any that is dynamically typed, obviously.

I don't remember any statically typed mainstream language would be able to generate the interface (it is the union type of A and B or intersection type of IX and IY) itself.

GO, because it's classes implement interface if they have the correct methods, without ever declaring them. So you just declare an interface that derives the two there and return it.

Obviously any other language where type can be defined to implement interface outside of definition of that type, but I don't think I remember any other than GO.

It's not possible in any type where implementing an interface has to be defined in the type definition itself. You can however work around in most of them by defining wrapper that implements the two interfaces and delegates all methods to a wrapped object.

P.S. A strongly typed language is one in which an object of given type can't be treated as object of another type, while weakly typed language is one that has a reinterpret cast. Thus all dynamically typed languages are strongly typed, while weakly typed languages are assembly, C and C++, all three being typed statically.


答:
Frameworks that have a good architectural premise for building large applications provide a notion of an application, a full-blown container that provides it's own MVC triads, URL mappings, tests, static resources, translations and what have you. While most Web framework provide you with some kind of an ability to plug in 3rd party solutions, unless there's support for a concept of an application, your results may vary.

You may look into Django and Flask, as they have first-class support for applications.

Django specifies applications as simple Python packages that follow a few conventions and Flask provides an application object that describes a WSGI application. Both concepts of applications allow you to develop applications that are self-contained and that can be distributed independently of any project.


问:
Programming "everything" using HTML5?
HTML 5 applications in the browser really seem to be taking off. I've been using src:kit within Google Chrome for a few weeks and love it. I'm an ASP.Net (C#/MVC 3) developer by trade, and in the past did several pieces of WebForms programming.

With Windows 8 app development moving into the trade of local HTML5 apps, and the major smartphone browsers supporting HTML5 installation, as well as many platforms supporting it (PhoneGap and Titanium, for example), are we already/will we soon be at the point that I could create an app that would be fully "installable" to run as a standalone on every platform?

I do realise that a database (or instert-your-data-store-here) would also be necessary, so adding another language in there for middleware would be necessary. C# on Mac/Linux with Mono is possible, but Mono generally only creates a GTK+ Application, so I would likely need to create another wrapper to house the application... I think.

Any suggestions of a better language to use as middleware? I.e. for ease of transportation - I've got far more experience with C# than anything else so would like something from that family if I'll need to do something different.

Basically, how far away are we from this? What still needs to change? Most importantly, if it is possible (which I believe, theoretically it is), what is the big jump between where we are now and when we will be there?

This will eventually turn into a program, so it is a completely practical problem that I'm working my way through (I'll start development after Christmas).

EDIT: To clarify, by 'every' platform, I include at least the following: Windows XP+/Mac OS X/Linux: any distro pretty much in the last 2 years/iOS/Android/Blackberry 5+/Windows Phone 7+

答:
With HTML 5 you can create web application front ends that run on the latest generation browsers in desktops, laptops, tablets and mobiles. If you want to support native to hardware operations, basically for tablets and mobiles, you should probably create a native application or a hybrid application (one with HTML code plus native web extensions like Windows 8 -WinRT).

Stick with the HTML approach on the front end and always use a service layer approach to minimize dependencies on the server side. If you have to create a native application you will only create the native front end, and not the service.

Title: Programming "everything" using HTML5?


答:
You need to make sure that the team hands over the code will provide support for a period of time. Make it a signed contract!

You will have questions later on that you didn't know you had to ask upfront, so they need to "stick around" to explain stuff to you not just give the code, docs and whatever they have on the project.

When you have a project handover you loose one important thing: the original team experience.

You sometimes also get something you didn't expect: their hostility.

Is the company doing the handover getting a good deal with the handover? If they loose business because they turn the project to you, the (proud) developers that created the code might resent the fact that their "baby" is given away. You might get responses like: "It's in the docs you got" ... even if it isn't.

Technical aspects are good to cover, but also take into consideration the human side of it.

YMMV!

Title: Prepare source code handover plan


问:
Why don't schools teach about bad code?
I realized there could be a lot of bad code in a system while writing Java.

I wonder why schools don't teach what programming practices are bad. For example, in Java, using a big try/catch block that catches Exception is bad, but no one told me. And we see the typical "String + String" concatenation appear in every corner of a program.

Isn't it the job of schools, assuming most programmers are taught at a school and not self-taught, to warn students away from the pitfalls in a programming?

答:
Two fundamental reasons:

Projects you develop at school are not to be maintained in the future, you just get a grade and move on to another course. Therefore, even if you actually attempt to "enforce" some rules, most students will not realize the true importance of it. When I was at university, some teachers actually did the effort and gave some extra points for "clean code", but it was only when I started working and reading many peoples code that I actually realized it. It comes with experience.

Some of the teachers never left the academia world and never had the responsibility to actually maintaining a project for a big team. Therefore, your code could be beautifully designed or a mess, and you would get the same grade as long as the output was correct and the algorithm efficient.

Title: Why don't schools teach about bad code?


答:
Python

It's very, very strongly typed.

But the type is not declared when a function is created, so the returned objects are "ambiguous".

In your specific question, a better term might be "Polymorphic".  That's the common use case in Python is to return variant types which implement a common interface.

```<code>def some_function( selector, *args, **kw ):
    if selector == 'this':
        return This( *args, **kw )
    else:
        return That( *args, **kw )
</code>```

Since Python is strongly typed, the resulting object will be an instance of This or That and cannot (easily) be coerced or cast to another type of object.

Title: Which statically typed languages support intersection types for function return values?

Body:
Initial note:

This question got closed after several edits because I lacked the proper terminology to state accurately what I was looking for. Sam Tobin-Hochstadt then posted a comment which made me recognise exactly what that was: programming languages that support intersection types for function return values.

Now that the question has been re-opened, I've decided to improve it by rewriting it in a (hopefully) more precise manner. Therefore, some answers and comments below might no longer make sense because they refer to previous edits. (Please see the question's edit history in such cases.)

Are there any popular statically & strongly typed programming languages (such as Haskell, generic Java, C#, F#, etc.) that support intersection types for function return values? If so, which, and how?

(If I'm honest, I would really love to see someone demonstrate a way how to express intersection types in a mainstream language such as C# or Java.)

I'll give a quick example of what intersection types might look like, using some pseudocode similar to C#:

```<code>interface IX { … }
interface IY { … }
interface IB { … }

class A : IX, IY { … }
class B : IX, IY, IB { … }

T fn()  where T : IX, IY
{
    return … ? new A()
             : new B();
}
</code>```

That is, the function fn returns an instance of some type T, of which the caller knows only that it implements interfaces IX and IY. (That is, unlike with generics, the caller doesn't get to choose the concrete type of T — the function does. From this I would suppose that T is in fact not a universal type, but an existential type.)

P.S.: I'm aware that one could simply define a interface IXY : IX, IY and change the return type of fn to IXY. However, that is not really the same thing, because often you cannot bolt on an additional interface IXY to a previously defined type A which only implements IX and IY separately.

Footnote: Some resources about intersection types:

Wikipedia article for "Type system" has a subsection about intersection types.

Report by Benjamin C. Pierce (1991), "Programming With Intersection Types, Union Types, and Polymorphism"

David P. Cunningham (2005), "Intersection types in practice", which contains a case study about the Forsythe language, which is mentioned in the Wikipedia article.

A Stack Overflow question, "Union types and intersection types" which got several good answers, among them this one which gives a pseudocode example of intersection types similar to mine above.

Body:
Python

It's very, very strongly typed.

But the type is not declared when a function is created, so the returned objects are "ambiguous".

In your specific question, a better term might be "Polymorphic".  That's the common use case in Python is to return variant types which implement a common interface.

def some_function( selector, *args, **kw ):
    if selector == 'this':
        return This( *args, **kw )
    else:
        return That( *args, **kw )

Since Python is strongly typed, the resulting object will be an instance of This or That and cannot (easily) be coerced or cast to another type of object.


答:
First, I think it is a mistake to assume that there aren't a lot of self-taught programmers.

Second, there is a lot of room for debate about what is good code and what isn't.  Some people are focused on readability, some on maintainability, some on efficiency, some on testability - and so forth.

Third, there is a big problem with how programming is taught - in the secondary and post secondary schools I've attended, at least.  There isn't a good, cohesive, multi-year curriculum that can build year over year.  Just about every course has to assume that there may be novices and veterans in the same class, so the course content ends up dumbed down so as not to leave too many people behind.

I'm sure that there are many university CS programmes that do have cohesive mulit-year curriculums, but there are many, many professional programmers with science, math, business and even arts degrees, not CS degrees.

Title: Why don't schools teach about bad code?

Body:
I realized there could be a lot of bad code in a system while writing Java.

I wonder why schools don't teach what programming practices are bad. For example, in Java, using a big try/catch block that catches Exception is bad, but no one told me. And we see the typical "String + String" concatenation appear in every corner of a program.

Isn't it the job of schools, assuming most programmers are taught at a school and not self-taught, to warn students away from the pitfalls in a programming?


答:
I would add that even if the bug has already been fixed (which shouldn't have happened before recording it in an issue tracker) it is a good idea to track it.

This way, if the issue should arise again in the future (regressions happen!) it is relatively easy to recognize the issue as "already dealt with" and read how it was fixed the first time.

Title: Should developers enter bugs into the bug tracking system?

Body:
While developing (either features or bug fixes) I sometimes happen to discover bugs that are not directly related to what I'm working on.  What should I do in that situation.  Just fix it?  Try to remember to fix it later?  Write it down somewhere?  Or enter it into the bug tracking system?

I generally enter it into the bug tracking system and let the process play itself out (i.e. triaging, assigning, etc.).  However I have hardly ever seen another developer enter a bug.  (Why is that?)


答:
There is a massive general perception that school knowledge (specifically about programming) is useless or weak. This is actually not true.

In fact, ask an average fresher from school to write about code -she/he will right a bad code. But it will at least compile and run. Ask an average fresh electronics engineer (i was one of them!) to build an FM radio - he won't even be halfway through the job.

The problem is the classic difference between - knowing and realizing. Usually, there is enough of theory of you know from the college but you don't quite develop a judgment of where and how to use that knowledge.

For example Schools do teach you that violating encapsulation is bad. But many people don't quite realize that their code had done it - till long things become a problem.

The reason why development of judgment doesn't come by the time you leave school because you have only spent few months on real problems to solve. When you spent another 10 years in industry you repeat the same thing you learn't in your first year.

Title: Why don't schools teach about bad code?


问:
What would you say to a bunch of software engineering students on their first day at college?
Next Friday I'm giving a short (30 min.) talk to a bunch of software engineering students who will be attending the same university I did.

Some context:

The place is Montevideo, Uruguay

The university is Universidad de la República (public, free university)

The Software Engineering programme takes 5 years (if you're very good and don't start working early). Around 800 new students per year, around 80 graduates per year. Conditions are harsh, particularly the first two years.

Most of them probably have no idea what software engineering or programming is.

My goal would be to somehow give them an idea of the field and hopefully motivate them to endure the hardships ahead to eventually become successful developers.

So the question is: what would you tell these people?

答:
I remember what was told to me on my first day as an engineering student. It really struck my mind, and I think it's a deep truth, so you may find it useful as well.

I was told that the main duty of an engineer is to reason about money. You don't have to design beautiful architectures for their own sakes, or implement a new system, or anything else, without keeping in mind the economical side.

What is the most effective way to solve my problem? How much does it cost to do it? Am I really willing to pay for the solution to the problem, or would I prefer keeping the problem and the money? Am I better solving the problem on my own, or paying someone else to deal with it? (Not only offshoring, but also buying a module or a commercial product is the same).

In the end, as engineers, we have to keep an eye on the practicability and economical feasibility of what we design. That's what sets us aside from pure scientists.


问:
Extensibility data model pattern
I was wondering how you'd be able to map the following criterias to common design patterns. I use PHP 5.3 and MySQL 5.5 and have my own mvc framework for my company but some parts could be better and here are the requirements:

(Take the concept of a catalog since it's the first app that would be affected in our application pool)

The controllers (products, clients and basket) all manage different information namely their own set of models. For example, the basket will create basket objects in memory, assign products to it, quantities, etc. Then it will save the basket to database and try the payment logic and save the payment associated to the basket.

My issue is that most of the time, our clients want to customize the different objects such as the client (add more coordinate fields or descriptive fields) or the product (add custom properties to the product). If my controller always refers to the class product but i want to extend it to create:

```<code>MyCompany_Models_Product
MyClient_Models_Product extends MyCompany_Models_Product
</code>```

How will i setup my system to support extension of classes and change the classes used by my different modules, controllers, views and other models. If i hardcode MyCompany_Models_Product as the class name in the controller and all other object, how would i go at creating an overridable system.

Is there any pattern i can go for that will leverage this problem?

答:
I thought about it last night before going to sleep and i'd like your input on this solution:

I'd use some kind of factory pattern which i don't know the name of. By default this factory could be called:

```<code>MyCompany_Factories_Products
</code>```

And you could call:

```<code>MyCompany_Factories_Products::setProductModel('MyClient_Models_Product');
MyCompany_Factories_Products::setProductFactory('MyClient_Models_Products');
</code>```

And by default it would call:

```<code>MyCompany_Factories_Products::setProductModel('MyCompany_Models_Product');
MyCompany_Factories_Products::setProductFactory('MyCompany_Models_Products');
</code>```

when i register the module into the system.

Then, calling the getProductModel or getProductFactory, i could extend my whole logic. Obviously i can't extend the controllers or i'd face problems relative to instanciation but all in all, i think thats a good pattern...

Need to know if there is a pattern name for that...

Title: Extensibility data model pattern

Body:
I thought about it last night before going to sleep and i'd like your input on this solution:

I'd use some kind of factory pattern which i don't know the name of. By default this factory could be called:

MyCompany_Factories_Products

And you could call:

MyCompany_Factories_Products::setProductModel('MyClient_Models_Product');
MyCompany_Factories_Products::setProductFactory('MyClient_Models_Products');

And by default it would call:

MyCompany_Factories_Products::setProductModel('MyCompany_Models_Product');
MyCompany_Factories_Products::setProductFactory('MyCompany_Models_Products');

when i register the module into the system.

Then, calling the getProductModel or getProductFactory, i could extend my whole logic. Obviously i can't extend the controllers or i'd face problems relative to instanciation but all in all, i think thats a good pattern...

Need to know if there is a pattern name for that...


问:
What is the architectural pattern: data pollers collect push normalized data to a central server for monitoring
I am trying to find a name for this architectural pattern that I have seen in many places before:

Poller - (There are a number of these)

These are either plugins or services acting on there own

communicate with equipment of various sorts collecting data and pushing that data to a central service in a normalized form.

each poller knows how to communicate with a particular device,

collects the devices status but does not act on it, just passes it on.

Central Server

Receives normalized data, files it in key / value store.

Periodically (or by some trigger) evaluates conditions that refer to the data.
The conditions cause some action to occur (like an event to be logged, or message to be sent to an operator)

答:
Isn't this an example of a producer/consumer architecture, where the poller produce data and the central server consumes it?

(Although I should point out that if I were to read 'producer/consumer' I would focus my attention on the synchronization issues, which may or may not be the concept you're trying to convey)


答:
If a school puts too much emphasis on avoiding bad code they could be guilty of "premature optimization". For many projects in school only a portion of the code is used to demonstrate the understanding of the new material. Because there is a need to cover a lot of material in a semester, asking the students to go back and improve the code to save a few seconds of run time, will mean that less material can be covered.

At work you can say take a couple of hours to find the parts of the code that are a bottleneck and fix them. In school asking them to do that extends the due date for the project by a few days or a week.

There is no need to focus on what is strictly bad style, because every company does it differently.

I agree with the comment about the mixture of students in a class, especially in high school. Some members of the class have never seen an If statement, others are on their third language.

Title: Why don't schools teach about bad code?


答:
If you are talking about CS degree at a university the answer is simple: programming is just a means to an end. The degree is more about the science of computing and not programming. Now, it may be a valid question for a community college/technical college program whose sole purpose is to create programmers.

To build on what S.Lott said in the comments, that there are an infinite amount of bad things but only a small amount of good, so why focus on the infinite bad. That is just for one language. So the university would spend all this time teaching the students how not to do something (and if they had time they may teach them how to do it right) for language X. So lets say that is 2 classes (the intro and then the "how to do it right class"). That is a full year of studies learning that one language, language X. The next year you want to take an embedded systems class which uses Y. So now you have to burn another year block of classes to learn Y and learn it properly. It just isn't realistic nor is it desirable because often what is good or bad can change. It is just something that can easily be learned once in the real world.

Title: Why don't schools teach about bad code?


问:
Examples of operator overloading, which make sense
While I learning C#, I found that, the C# supports operator overloading. I have problem with good example which:

Make sense (ex. adding class named sheep and cow)

Is not an example of concatenation of two strings

Examples from Base Class Library are welcome.

答:
I'm glad I saw this because I've been fooling around with Irony and it has a GREAT use of operator overloading. Here is a sample of what it can do.

So Irony is a ".NET Language Implementation Kit" and is a parser generator (generating an LALR parser). Instead of having to learn a new syntax/language like parser generators such as yacc/lex you write the grammar in C# with the operator overload. Here is a simple BNF grammar

```<code>// BNF
Expr := Term | BinExpr
Term := number | ParExpr
ParExpr := "(" + Expr + ")"
BinExpr := number + BinOp + number
BinOp := "+" | "-" | "*" | "/"
number := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
</code>```

So it is a simple little grammar (please excuse it if there are inconsistencies as I'm just learning BNF and constructing grammars). Now lets look at the C#:

```<code>  var Expr = new NonTerminal("Expr");
  var Term = new NonTerminal("Term");
  var BinExpr = new NonTerminal("BinExpr");
  var ParExpr = new NonTerminal("ParExpr");
  var BinOp = new NonTerminal("BinOp");
  var Statement = new NonTerminal("Statement");
  var ProgramLine = new NonTerminal("ProgramLine");
  var Program = new NonTerminal("Program", typeof(StatementListNode));
  // BNF Rules - Overloading
  Expr.Rule = Term | BinExpr;
  Term.Rule = number | ParExpr;
  ParExpr.Rule = "(" + Expr + ")";
  BinExpr.Rule = Expr + BinOp + Expr;
  BinOp.Rule = ToTerm("+") | "-" | "*" | "/" | "**";
</code>```

As you can see, with the operator overloading, writing the grammar in C# is almost exactly writing the grammar in BNF. To me, that not only makes sense but is a great use of operator overloading.

Body:
I'm glad I saw this because I've been fooling around with Irony and it has a GREAT use of operator overloading. Here is a sample of what it can do.

So Irony is a ".NET Language Implementation Kit" and is a parser generator (generating an LALR parser). Instead of having to learn a new syntax/language like parser generators such as yacc/lex you write the grammar in C# with the operator overload. Here is a simple BNF grammar

// BNF
Expr := Term | BinExpr
Term := number | ParExpr
ParExpr := "(" + Expr + ")"
BinExpr := number + BinOp + number
BinOp := "+" | "-" | "*" | "/"
number := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

So it is a simple little grammar (please excuse it if there are inconsistencies as I'm just learning BNF and constructing grammars). Now lets look at the C#:

  var Expr = new NonTerminal("Expr");
  var Term = new NonTerminal("Term");
  var BinExpr = new NonTerminal("BinExpr");
  var ParExpr = new NonTerminal("ParExpr");
  var BinOp = new NonTerminal("BinOp");
  var Statement = new NonTerminal("Statement");
  var ProgramLine = new NonTerminal("ProgramLine");
  var Program = new NonTerminal("Program", typeof(StatementListNode));
  // BNF Rules - Overloading
  Expr.Rule = Term | BinExpr;
  Term.Rule = number | ParExpr;
  ParExpr.Rule = "(" + Expr + ")";
  BinExpr.Rule = Expr + BinOp + Expr;
  BinOp.Rule = ToTerm("+") | "-" | "*" | "/" | "**";

As you can see, with the operator overloading, writing the grammar in C# is almost exactly writing the grammar in BNF. To me, that not only makes sense but is a great use of operator overloading.


答: One solution could be Microsoft Azure. You could run a Push Notification Service to enable the communication between your app on windows and your app on your iPad. Services like a RESTful or SOAP service could fit your problem as well, but I don't know your exact problem ;-)</p>

Title: How to connect iPad app to an app I have running in Windows

Body:
I recently picked up a macbook and want to start doing some apps for my ipad. I have a chat client written in c# that interfaces a game I play. What I would like to do is write an app for the ipad that would communicate somehow with my c# app.

What would be the best approach to this? I have never used JSON but is this where I should be looking?

I don't want to spend a ton of time looking in the wrong place, hoping someone here could point me in the right direction.


答:
The very well known Publish Subscribe pattern exactly covers this.

Just a small introduction to Publish Subcribe and putting terminology consistent we can say the following:

This diagram and more good details are available from Open Pattern Repository

According to this, the Producer elements are the ones which are polling the sensors internally - once they have information they push it to the Subscription manager (a.k.a central system).  Of course, there is one more thing listed here is that of final Consumer. While you have not mentioned, but any form of mechanism to retrieve this information (be it a brower or any app) is end consumer.

One of the most common usage of this pattern is System Monitoring tools
Any thing from Nagios, OpenNMS, CollectD to advanced OSS used in telecom or ISP netowrk essentially use this pattern.

While this pattern is widely understood and very simple there are many facets to it - essentially the mechanics of different parts of the communication can vary widely while the core pattern still holds. Here is a great ACM paper that can give deep study of the same.

The Many Faces of Publish/Subscribe by PATRICK TH. EUGSTER, PASCAL A. FELBER, RACHID GUERRAOUI, ANNE-MARIE KERMARREC ACM Computing Surveys, Vol. 35, No. 2, June 2003, pp. 114–131.

Title: What is the architectural pattern: data pollers collect push normalized data to a central server for monitoring

Body:
I am trying to find a name for this architectural pattern that I have seen in many places before:

Poller - (There are a number of these)

These are either plugins or services acting on there own

communicate with equipment of various sorts collecting data and pushing that data to a central service in a normalized form.

each poller knows how to communicate with a particular device,

collects the devices status but does not act on it, just passes it on.

Central Server

Receives normalized data, files it in key / value store.

Periodically (or by some trigger) evaluates conditions that refer to the data.
The conditions cause some action to occur (like an event to be logged, or message to be sent to an operator)


问:
How does bit flipping / complementing work?
I am currently learning about bitwise operation, so bear with me. I understand AND, OR, and shifting. What I don't understand is bit flipping.

So, 5 is 0101. When someone says to me "flip those", it would result in 1010 which is 10. So why does ~5result in -6?

I think I got this very wrong. Can someone enlight me?

(I am putting this here because I think it is a general programming question and not a specific one, which would belong to stack overflow).

Edit 1 Thanks to mcfinnigan's comment I learned that there is a "most significant bit" that defines if a number is positive or negative (correct me if I'm wrong). This would explain why positive results are ending up negative and vice versa. However, IMO the example above would result in -10 then.

Edit 2 Thanks to Don 01001100 and S.Lott, I finally got it.

答:
You're not quite right.  I'll use 32-bit 2's complement values, since they're pretty common.

It's not 00000000 00000000 00000000 00001010

(Which is not 9, BTW, check your math more carefully.)

It's 11111111 11111111 11111111 11111010

Which is -6


问:
Would you allow your programmers to use Messenger and social networks like Facebook?
I had many bosses, each one had a different approach about allowing or not use of Windows Live Messenger, Facebook, and many other Internet sites.

Of course Internet is really needed to research about the best way to solve a specific task. Sometimes you could have a friend online, also a programmer, who knows better about something.

For some managers, internet access would slow down project progress, and on the other hand, allow people to interact and find out brand new solutions.

What would you do?

答:
I wouldn't make it an issue unless it became a problem. I prefer to treat my employees as adults and assume they will act professionally unless there is evidence to the contrary. For example, if someone is continually missing deadlines without a good reason I might check in on them once in a while and if they are wasting time online, THEN I would deal with that individual as needed.

Also, since none of my employees are paid hourly, I don't see the sense in policing every minute they spend at the office as long as they are getting their work done.

The exception might be if they were doing something online that is otherwise problematic (porn, leaking company secrets, badmouthing the company publicly, etc.) For those things we would have specific policies against it and deal with infractions also on an individual basis.


答:
If you're using a two's complement signed integer, then the first bit indicates the sign, and the remaining bits count down from -1, with -1 represented as all "1" bits, so, counting down, you have:</p>

``` 7: 0111
 6: 0110
 5: 0101
 4: 0100
 3: 0011
 2: 0010
 1: 0001
 0: 0000
-1: 1111
-2: 1110
-3: 1101
-4: 1100
-5: 1011
-6: 1010
-7: 1001
-8: 1000```

Title: How does bit flipping / complementing work?

Body:
I am currently learning about bitwise operation, so bear with me. I understand AND, OR, and shifting. What I don't understand is bit flipping.

So, 5 is 0101. When someone says to me "flip those", it would result in 1010 which is 10. So why does ~5result in -6?

I think I got this very wrong. Can someone enlight me?

(I am putting this here because I think it is a general programming question and not a specific one, which would belong to stack overflow).

Edit 1 Thanks to mcfinnigan's comment I learned that there is a "most significant bit" that defines if a number is positive or negative (correct me if I'm wrong). This would explain why positive results are ending up negative and vice versa. However, IMO the example above would result in -10 then.

Edit 2 Thanks to Don 01001100 and S.Lott, I finally got it.

Body:
If you're using a two's complement signed integer, then the first bit indicates the sign, and the remaining bits count down from -1, with -1 represented as all "1" bits, so, counting down, you have:

 7: 0111
 6: 0110
 5: 0101
 4: 0100
 3: 0011
 2: 0010
 1: 0001
 0: 0000
-1: 1111
-2: 1110
-3: 1101
-4: 1100
-5: 1011
-6: 1010
-7: 1001
-8: 1000


问:
Does the LGPL allow me to do this?
I am planning to develop a commercial software using a LGPL software.

In the LGPL software that I am using some functions in a class are not fully implemented. I want to modify the LGPL code so that the class and not-implemented functions are made visible outside the dll by adding dllexport infront of class and by adding virtual keyword infront of function.

Then I plan to implement those functions in my proprietary software. I am ready to distribute the modified LGPL code but not proprietary software that implements functions in the way I want.

Does that violate LGPL terms and conditions?

答:
This is a complex question, but I believe that what you propose is not allowed.

You are suggesting adding hooks into the library to make it easier for you to sub-class the library and thus, at the very least. to bypass the spirit of the LGPL.

The problem is, if you sub-class a class which is subject to the LGPL license in your own code, then your work becomes a work based on the library, rather than a work which uses the library which means that your code is a derivative work that is covered under section 2 (LGPL v2.1) rather than one covered under section 6 (LGPL v2.1). I.e. it becomes subject to the LGPL!

I think that Stephen Colebourne provides a good summary over on javalobby.

I'm not a big fan of knee-jerk talk to your lawyer suggestions, but in this case I think it would be well worth doing so if you plan to proceed with this, otherwise you might be getting a nasty letter from the Free Software Foundation legal team.

Alternatively, you could ask the FSF directly. From their contact page:

For questions about free software licensing and copyright

Please check our licensing FAQ, the license list, general copyleft information, and related pages. If questions remains, email <licensing@gnu.org>.

Incidentally, in the related question Reflection and the LGPL, gbjbaanb answers with the LGPL 3.0 perspective.

Title: Does the LGPL allow me to do this?


答:
As explained in the Wikipedia article on one's complement, there are at least three different systems for representing signed binary numbers:

sign magnitude: This is the system where you the most significant bit represents the sign, and the rest of the word represents the magnitude of the number. In this system, an 8-bit representation of -5 would be 10000101. This is simple conceptually, but it has some problems. For example, for 8-bit numbers, 00000000 - 00000001 = 11111111, which is to say that  0 - 1 = -127. To do math with sign magnitude numbers, you have to consider the sign bit separately from the rest of the value.

one's complement: Negative numbers are represented by inverting all the bits. Again, this is conceptually simple, but suffers from the fact that there are two representations of 0: 00000000 and 11111111.

two's complement: Negative numbers are formed by taking the one's complement of the number and adding 1. This system avoids the issues explained above: there's only one representation of 0, and it doesn't require any special treatment for the sign bit.

It's worth pointing out that in all three systems, you can tell the sign of a number by looking at the most significant bit. With sign magnitude, you have to move the most significant bit if you change the size of a number's representation: 1101 becomes 10000101 when you move from a 4-bit representation to 8-bit. With one's complement and two's complement, you can instead "sign extend" the number, which means that you just replicate the most significant bit: 1101 becomes 1111101.

So, 5 is 0101. When someone says to me "flip those", it would result
  in 1010 which is 10. So why does ~5 result in -6?

Two's complement is the standard today, so you need to do more than flip the bits. You also need to add 1. To form -5, you start with 0101, flip all the bits to get 1010, and then add 1 to arrive at 1011. You can verify that this really is -5 by changing the sign again: start with 1011, flip the bits to get 0100, and add 1 to arrive at 0101, which is 5.


问:
How can I document someone else's past work?
We're in a bad situation of having very little documentation on customization our past workers made to a business critical system. Lots of changes were done to Crystal Reports, database entities, and proprietary configuration/programming files for our ERP software.

The current documentation generally reads something like this:

This program is run before invoicing. Known bugs: none.

Run this program after installing software X.

Changed the following fields in this report: (with no explanation of how or why)

Our IT shop is small, and in the case of the ERP software, most work was lumped on one person (that's me now) so no one else here knows what all we did. The IT and accounting department know bits and pieces (occasionally quite helpful ones) but it's not enough.

Another problem is our Accounting department seems to think we're well documented. It's true that we kept lots of records of what went wrong, but very little explains what (if anything) was done to fix these problems. We have hundreds of papers explaining bugs, but the documents explaining changes (as shown above) are almost useless.

How can I go about documenting past changes when I don't know what all was done? I can start with documenting what we've changed: Files, database tables ect which we need to have for the system to work. I can also document what we do; when reports are run, why people were told to use X report/program. But when one of these customized things has a problem, I'm always back to square one.

How can I proactively document this stuff for myself and others?

答:
The best you can do is document everything you do know and ask around the company to document anything that others know as well. I suggest centralizing the documentation in a wiki or something similar so that everyone has access to the most up-to-date documentation.

You cannot document something you don't know, so either you attempt to learn and discover why something was done or you just leave it undocumented. This is why company's need to take greater care to document things while those that know are still employed there.

If you are attempting to document any code that you do not understand, I suggest you write unit tests to test the functionality. This way you will better understand what the code does and the tests themselves can serve as documentation.

Good luck!


问:
Should I include multiply license header notice in dual license software?
Is it necessarily if a software released under both of LGPL3 && GPL3 terms have to include both license header notice top of each file?

Or just put GPL header notice? or simply put LGPL3 license text in some file like COPYING.LESSER ?

EDITED:

I am the copyright holder of the project!

答: I am not a lawyer (IANAL), but I don't think it is necessary to add license text at the top of each file. Include the licenses in an external file and distribute this file with your software.</p>


答:
Basically a developer needs full access to the Internet, to search for information, download programs etc.

Therefore a liberal policy is important.   Then it comes down to, can the individual person use it in a "reasonable" amount of time each day, which in turn is measurable by - how long is this project estimated to take, and how long took it really.  If productivity is low, then consider looking at why.  If productivity is high or acceptable then let the developers do as they like.

Title: Would you allow your programmers to use Messenger and social networks like Facebook?

Body:
I had many bosses, each one had a different approach about allowing or not use of Windows Live Messenger, Facebook, and many other Internet sites.

Of course Internet is really needed to research about the best way to solve a specific task. Sometimes you could have a friend online, also a programmer, who knows better about something.

For some managers, internet access would slow down project progress, and on the other hand, allow people to interact and find out brand new solutions.

What would you do?


问:
Flipping the desired bit of an integer number
Suppose you were given an integer number in decimal notation. This when represented in binary will be a series of 0's and 1's. This sequence varies in length with the magnitude of the number. Now suppose you wanted to flip the 'n'th position bit in this sequence of binary numbers, how would you do it?

The result of the program must be the number represented by the sequence with the bit in the 'n'th position flipped.

Edit: This is not a homework question! An intern asked me this question! And all I could do was fumble! So could someone give me a helping hand here! All I can think of is assembly level stuff right now (put it in a register and blah, blah)! But is there a way to do it in C? I have been out of school for quite some time now! Trust me, my only homework nowadays is probably tax returns! :-D

答:
A bit can be turned on by applying bitwise OR with a power of two to the operand.
It is turned off by applying bitwise AND with the complement of a power of two to the operand

Which power to use and how to distinguish 'on' from 'off' flips is left as an exercise for the reader.


答:
Do you have source control?

Can you work out what has changed from that?

If so, then you may be able to map that to business changes, whether new features or bug fixes.

Is it possible to resurrect an old developers mailbox? (not sure if this is viable with privacy concerns or not). There may be lots of information to be gained by trawling through there.

Title: How can I document someone else's past work?

Body:
We're in a bad situation of having very little documentation on customization our past workers made to a business critical system. Lots of changes were done to Crystal Reports, database entities, and proprietary configuration/programming files for our ERP software.

The current documentation generally reads something like this:

This program is run before invoicing. Known bugs: none.

Run this program after installing software X.

Changed the following fields in this report: (with no explanation of how or why)

Our IT shop is small, and in the case of the ERP software, most work was lumped on one person (that's me now) so no one else here knows what all we did. The IT and accounting department know bits and pieces (occasionally quite helpful ones) but it's not enough.

Another problem is our Accounting department seems to think we're well documented. It's true that we kept lots of records of what went wrong, but very little explains what (if anything) was done to fix these problems. We have hundreds of papers explaining bugs, but the documents explaining changes (as shown above) are almost useless.

How can I go about documenting past changes when I don't know what all was done? I can start with documenting what we've changed: Files, database tables ect which we need to have for the system to work. I can also document what we do; when reports are run, why people were told to use X report/program. But when one of these customized things has a problem, I'm always back to square one.

How can I proactively document this stuff for myself and others?


答:
When I try to document something that someone else who's no longer with the project or the company did, I always start the attitude of:  This is a blackbox to everyone including me until I need to change something or explain it to someone else.

The reason that this project is in the documentation shape you have found it in is because documentation of any work is somewhat secondary to getting it running.  So document what you change and if you have figured out what the particular field in the database and what particular block of code does, if for noone else's benefit but your own.


问:
SQL Triggers and when or when not to use them.
When I was originally learning about SQL I was always told, only use triggers if you really need to and opt to use stored procedures instead if possible.

Now unfortunately at the time (a good few years ago) I wasn't as curious and caring about fundamentals as I am now so never did ask to the reason why.

What's the communities opinion in this? Is it just someone's personal preference, or should triggers be avoided (just like cursors) unless there is a good reason for them.

答:
Another use case I've personally come across is for databases that are accessed by more than one program. If you want to implement functionality but not redesign all systems for it, a trigger makes a sensible solution.

For example, I recently worked on a database that had previously existed as solely an office system. When a webapp was written to interface with it, we wanted to implement a notification system (similar to stackexchange, for example), which would be fired by multiple events, such as processing a transaction, and so forth. We were able to implement a trigger so that updates in the office backend fired a trigger to create the notification for the frontend and tell the user that their transaction had been processed by the office.


答:
If you are assuming you are implementing C, you can apply a mask to the variable.

For example:

```<code>a    = 0xF2  // Binary: 11110010
b    = 0xF6  // Binary: 11110110
mask = 0x04  // Binary: 00000100

c = a ^ mask  // Binary: 11110110  -> the 3rd LSB made 0 to 1
d = b ^ mask  // Binary: 11110010  -> the 3rd LSB made 1 to 0
</code>```

Basically, X'Or with 0 keeps the bit as it is. X'OR with 1 flips the bit.

Refer to this: http://en.wikipedia.org/wiki/Bitwise_operations_in_C

Title: Flipping the desired bit of an integer number

Body:
Suppose you were given an integer number in decimal notation. This when represented in binary will be a series of 0's and 1's. This sequence varies in length with the magnitude of the number. Now suppose you wanted to flip the 'n'th position bit in this sequence of binary numbers, how would you do it?

The result of the program must be the number represented by the sequence with the bit in the 'n'th position flipped.

Edit: This is not a homework question! An intern asked me this question! And all I could do was fumble! So could someone give me a helping hand here! All I can think of is assembly level stuff right now (put it in a register and blah, blah)! But is there a way to do it in C? I have been out of school for quite some time now! Trust me, my only homework nowadays is probably tax returns! :-D

Body:
If you are assuming you are implementing C, you can apply a mask to the variable.

For example:

a    = 0xF2  // Binary: 11110010
b    = 0xF6  // Binary: 11110110
mask = 0x04  // Binary: 00000100

c = a ^ mask  // Binary: 11110110  -> the 3rd LSB made 0 to 1
d = b ^ mask  // Binary: 11110010  -> the 3rd LSB made 1 to 0

Basically, X'Or with 0 keeps the bit as it is. X'OR with 1 flips the bit.

Refer to this: http://en.wikipedia.org/wiki/Bitwise_operations_in_C


问:
Is it a problem to have different styles of HTML coding within team?
I with 2 other friends are new to web development. We are learning HTML, CSS, Javascript and are creating simple websites to get a feel of different things. And as HTML is only a markup and not a programming language we have very different styles evolving. I mean whenever we look at each other's code, we tend to put a good amount of time in understanding why the other one does that.

Now we want to build a larger website together and my question is- Is that a problem having very different styles in a team for web development(specifically)?

答:
I would not get too hung up on it, especially with HTML.

I've worked in many places with coding standards, and they are never adhered to rigidly.

That's not to say I disagree with having them a such, just that over time, unless really strictly enforced, people soon stray from them.