问:
UI Developer Interview Question
I keep getting the following question in interviews; and judging from the reactions I've gotten, I'm not giving the best answer. "What methodology do you use for developing user interfaces?" Which seems like a rather broad question.

Besides dividing work between markup, stylesheets, and javascript (control logic), what are the best practices? What am I missing in this question?

Any thoughts?

答:
Its a very broad and open ended question, so there's no "right" answer. With that being said, your answer is being compared to other candidates.

Just judging on what you said, I'd probably try a different approach. Dividing markup / styles / javascript is great from a coding design standpoint. But you could write perfect code in that manner and still have a terrible UI.

Rather than divulge in a long drawn-out description of how to go about UI design, I'd recommend this book. Its not the be-all-end-all book, but it will give you some good ideas.

UI is very broad and subjective. If you think you know it all, that means you're just starting. Best of luck :)

Title: UI Developer Interview Question


答:
My guess is that they are referring to things like progressive enhancement, graceful degradation, paper prototyping, storyboards, etc.  It might also extend into UI testing strategies.

Mentioning those would at least give you some keywords to shape your answer around.

ContentLicense: CC BY-SA 3.0

Title: UI Developer Interview Question

Body:
I keep getting the following question in interviews; and judging from the reactions I've gotten, I'm not giving the best answer. "What methodology do you use for developing user interfaces?" Which seems like a rather broad question.

Besides dividing work between markup, stylesheets, and javascript (control logic), what are the best practices? What am I missing in this question?

Any thoughts?


问:
Basis of definitions
Let us suppose we have a set of functions which characterise something: in the OO world methods characterising a type. In mathematics these are propositions and we have two kinds: axioms and lemmas. Axioms are assumptions, lemmas are easily derived from them. In C++ axioms are pure virtual functions.

Here's the problem: there's more than one way to axiomatise a system. Given a set of propositions or methods, a subset of the propositions which is necessary and sufficient to derive all the others is called a basis.

So too, for methods or functions, we have a desired set which must be defined, and typically every one has one or more definitions in terms of the others, and we require the programmer to provide instance definitions which are sufficient to allow all the others to be defined, and, if there is an overspecification, then it is consistent.

Let me give an example (in Felix, Haskell code would be similar):

```<code>class Eq[t] {
  virtual fun ==(x:t,y:t):bool => eq(x,y);
  virtual fun eq(x:t, y:t)=> x == y;
  virtual fun != (x:t,y:t):bool => not (x == y);
  axiom reflex(x:t): x == x;
  axiom sym(x:t, y:t): (x == y) == (y == x);
  axiom trans(x:t, y:t, z:t): implies(x == y and y == z, x == z);
}
</code>```

Here it is clear: the programmer must define either == or eq or both. If both are defined, the definitions must be equivalent. Failing to define one doesn't cause a compiler error, it causes an infinite loop at run time. Defining both inequivalently doesn't cause an error either, it is just inconsistent. Note the axioms specified constrain the semantics of any definition. Given a definition of == either directly or via a definition of eq, then != is defined automatically, although the programmer might replace the default with something more efficient, clearly such an overspecification has to be consistent.

Please note, == could also be defined in terms of !=, but we didn't do that.

A characterisation of a partial or total order is more complex. It is much more demanding since there is a combinatorial explosion of possible bases.

There is an reason to desire overspecification: performance. There also another reason: choice and convenience.

So here, there are several questions: one is how to check semantics are obeyed and I am not looking for an answer here (way too hard!). The other question is:

How can we specify, and check, that an instance provides at least a basis?

And a much harder question: how can we provide several default definitions which depend on the basis chosen?

答:
In general, the dependencies between propositions form a digraph, which may, as you point out, contain cycles. A minimal complete subset is defined by a set of nodes such that all other nodes are reachable from (at least) one node in the set. I don’t believe there is any language that allows you to specify this directly; in Haskell the typical solution is to document convenient subsets, and keep typeclasses small and simple. Take Eq for example:

```<code>class Eq a where
  (==), (/=) :: a -> a -> Bool
  x == y = not (x /= y)
  x /= y = not (x == y)
</code>```

In this case the minimal complete definitions include (==) and (/=), which is obvious enough that it doesn’t really need to be verified. I would argue that a typeclass with enough complexity to give a programmer pause is too complex, and warrants refactoring.

If you just want to specify a few reasonable minimal sets, you can leave the main definition abstract and derive a typeclass for each. But that quickly becomes cumbersome, and in Haskell you still don’t really know that the user has properly implemented your interface.

But it isn’t your responsibility, as an interface writer, to define behaviour for misuse of the interface.

Title: Basis of definitions

Body:
In general, the dependencies between propositions form a digraph, which may, as you point out, contain cycles. A minimal complete subset is defined by a set of nodes such that all other nodes are reachable from (at least) one node in the set. I don’t believe there is any language that allows you to specify this directly; in Haskell the typical solution is to document convenient subsets, and keep typeclasses small and simple. Take Eq for example:

class Eq a where
  (==), (/=) :: a -> a -> Bool
  x == y = not (x /= y)
  x /= y = not (x == y)

In this case the minimal complete definitions include (==) and (/=), which is obvious enough that it doesn’t really need to be verified. I would argue that a typeclass with enough complexity to give a programmer pause is too complex, and warrants refactoring.

If you just want to specify a few reasonable minimal sets, you can leave the main definition abstract and derive a typeclass for each. But that quickly becomes cumbersome, and in Haskell you still don’t really know that the user has properly implemented your interface.

But it isn’t your responsibility, as an interface writer, to define behaviour for misuse of the interface.


问:
Process of developing software?

Possible Duplicate:

  What to plan before starting development on a project?

I was wondering when you start developing a software what process should you generally go through to do it?

By this I mean after you get an idea, do you just sit down and start pushing out code directly, or is there some planning process that you should generally go through first? (i.e. flowcharts, diagrams etc.)

Just wondering because I just had an idea and am about to embark on my first "real" application but have no idea where to begin. What would you suggest is the steps that should be taken to have a successful developmental cycle?

答:
Sketch out your UI and list some of the things you want the application to do. Start building the application or you'll get stuck in the planning mode. When you run into problems, consult and SO site.

Your first app isn't going to be perfect. Try to observe a potential user working with the application sooner rather than when the whole thing is completed.

Get in the habit of using source control.

It probably won't turn out the way you intended - that's usually a good thing.

Title: Process of developing software?


答:
This may seem silly, but ask them to break down what it is that they really mean in their broad question. More times than not (in my experience), questions like those are asked as a two phase approach:

They know that this is a broad question and unlikely to be answered very well and are looking for you to clarify the question (a form of requirements gathering really)

Once all the pieces of the puzzle are in place, how well do you tackle each subtopic of their original broad question?

Just my two cents :)

Title: UI Developer Interview Question


问:
Using alternative MVC framework
I am new to ASP.NET MVC and EF. I read about open source implementations of MVC pattern like Spring, FubuMVC, Castle etc.

I want to know how flexible these alternatives are when compared with ASP.NET MVC. Which one is widely used and whose help is easily available on the NET?

答:
You don't have any restriction on using Asp.net MVC. You have full rights to use it and abuse it just like Spring or Castle.

The most widely used is Asp.net MVC only because it comes from the desk of Microsoft itself and has great amount of documentation and tutorials at asp.net/mvc.

If you are starting with Asp.net MVC, I would suggest you to go with it and then try out the other frameworks later

Title: Using alternative MVC framework


问:
cost trade-offs for deploying changes to prod, stored procs vs. LINQ
Some context for thisi question: it is not about development time over the entire iteration of development, but just the stage of deploying changes from dev to prod environment. "LINQ" here really means LINQ, ORM, or C# where T-SQL would otherwise be used. And here "stored procs" is just a general term that encompasses database objects which include stored procs, functions, and views. Question was just phrased as "LINQ", "stored procs" since the two are commonly compared in questions. To narrow the scope of the discussion we can assume web applications. Now finally the question is,

What are the trade-offs in the cost of deployment (from dev to prod) between the two approaches?

Some say it's easier to rollback Db schema changes than rollback changes across C# files in a solution. Others say it's easier to version or source control C# code than Db schema objects. If you make changes to LINQ queries, you'll most likely need to recompile the app to push the changes to prod. If you make changes to database schema, then that may require having a T-SQL script run in order to sync the changes to prod.

As with many decisions with programming, the chosen solution may be context-sensitive. e.g. for data structures some situations may call for a hash map, and for others, it may be best to use a stack. Each has its own advantages/disadvantages.

答:
You are asking the wrong question, it isn't about cost it is about RISK.

Database code changes ripple upward and outward where as non-Database code changes ( Application Logic ) ripple downward and inward. This means changes to the things that ripple upward and outward will always be risker.

Change a stored procedure, function, table or constraint or anything really and you can easily break every application that uses that database without any way to know the complete extent of what will be affected. You would have to get every application that touches the database to regression test, and face it, in the real world just having Unit tests much less comprehensive Integration Tests is a rare thing.

Here is a real world example that shows that the cost is determined by the risk. This is just an example, every situation will be different.

A well meaning DBA reordered some columns of a table when doing some
  other un-related work that was requested. It completely broke a bunch
  of apps silently that had SELECT * queries and referred to the
  returned fields by index, since all the columns were mapped to
  String types, the application slowly and silently corrupted tonnes
  of data as data was read and re-written to the database in the wrong
  locations.

This really happened, I had to clean up the mess personally. I was a hired gun contractor at the time so I got the tedious work of fixing the broken code and writing clean up programs to re-order the data. Imagine how much that cost!

Whereas if you change some Application logic, the only thing you directly affect is the application you are working on. (Barring doing something that corrupts the data in the database and other silly things, that can be deterministically tested).

The riskier one will always be orders of magnatitude more expensive to fix when it blows up in production.

Your cost is determined by which is riskier?


答:
Software development is a skill that is learned through study and practice. I would suggest you stop and have a think about what it is you want to achieve before you even begin to do more than sketch out your idea. If you think you can go from zero knowledge and experience to writing your first killer multi-million dollar app then you'll be in for a lot of disappointment.

Your question itself suggests to me that it's likely you've never written any software before. Therefore the key to turning your idea into working software is to start by learning the basics, and then take that experience and apply it to your product idea. You have to start small.  It may well be that your idea has elements to it that can be developed separately, and that may be good as a means to help you progress your project and give you the motivation of working on your own idea for yourself. The flip-side to this however, is that it is only with experience that a good software developer learns how to recognize how to break out project elements into modules, and sub-projects etc.

You'll need to be highly organised, and highly motivated, and you're best bet will be to find someone willing to act as your mentor.  Someone you can trust your idea to so that you can ask questions that go directly to the heart of the problems you will encounter while developing your software. You should also read extensively.  I'm not that convinced that the best software engineers come out of the university system, and most of the best programmers I have ever worked with were self taught, but they read extensively, and are always experimenting and highly critical of everything they do.

I'd suggest looking into Behaviour Driven Development as a guiding process, as it will teach you how to write software in a way that is consistent with most agile development systems used nowadays, and if you stick to its principals, you'll make a lot less process-oriented mistakes going forward and your efficiency will also receive a kick from day one. A book that you might find helpful would be Head First Software Development, particularly if you find yourself needing to work with others, but also as it covers the basics well, without attempting to lock you into a specific development methodology.

Good luck.

Title: Process of developing software?

Body:
Possible Duplicate:

  What to plan before starting development on a project?

I was wondering when you start developing a software what process should you generally go through to do it?

By this I mean after you get an idea, do you just sit down and start pushing out code directly, or is there some planning process that you should generally go through first? (i.e. flowcharts, diagrams etc.)

Just wondering because I just had an idea and am about to embark on my first "real" application but have no idea where to begin. What would you suggest is the steps that should be taken to have a successful developmental cycle?


问:
Make a big deal out of == true?
There is a colleague of mine who constantly writes:

```<code>if (someBool == true)
</code>```

It drives me up the wall!  Should I make a big deal of it or just drop it?

答: use it as an opportunity to teach him. he will respect you more if you do. wouldn't you want someone to do the same for you?</p>

ContentLicense: CC BY-SA 2.5

Title: Make a big deal out of == true?


问:
As a programmer, what am I supposed to know like the back of my hand?
I am talking of stuff related to programming only and not system or network administration.

I am about to finish college and get a programming job, so I am interested to know about this. Although this may seem a subjective question, I think this is not quite and falls in the category of best practices.

I don't think a programmer can know everything about OS he works on, all the APIs of the framework he works on, all the features and quirks of the languages he works with, all the data structures and algorithms, all the settings for his compiler, linker, IDE etc. I don't think it is practical either. Or can he?

The usual answer is "most". What is this most? If you were to interview a programmer with about 5 years experience, what would you expect him to know? Or lets say if you were to attend an interview and you have about 10 years experience behind you, what would you brush up on?

答:
Know your algorithm and data-structures thoroughly. Know how to accomplish common tasks with the language/framework and how an expert would do the same. Work, make mistakes, improve and let your experience teach you more for as long as you are in the industry.

My checklist for an interview would be

Sorting, Searching, graph algorithms and basic of Dynamic Programming.

Arrays, matrix, stacks, queues, linked lists, trees and hash tables.

Object Oriented Programming and Testing concepts

Don't forget to keep in mind the time and space complexity of your solutions if you are aiming for one of those big firms people dream to get in :).

Best of Luck


答:
You need to know:

How to Think. If you can't think, go work in some other profession.

Know where to look. You don't have to know everything about something, you have to know enough to be useful, and enough to THINK "hey there needs to be a way to do X" and then go look it up.

Know your limits. This means your abilities, your lack of knowledge, the fact that you don't know everything (and never will). A little humility goes a long way.

Title: As a programmer, what am I supposed to know like the back of my hand?

Body:
I am talking of stuff related to programming only and not system or network administration.

I am about to finish college and get a programming job, so I am interested to know about this. Although this may seem a subjective question, I think this is not quite and falls in the category of best practices.

I don't think a programmer can know everything about OS he works on, all the APIs of the framework he works on, all the features and quirks of the languages he works with, all the data structures and algorithms, all the settings for his compiler, linker, IDE etc. I don't think it is practical either. Or can he?

The usual answer is "most". What is this most? If you were to interview a programmer with about 5 years experience, what would you expect him to know? Or lets say if you were to attend an interview and you have about 10 years experience behind you, what would you brush up on?


答:
Having roughly 10 years of experience myself, I'd brush up on algorithms (sorting, data structures, graphs). The biggest problem for me is that my last few years have been spent either in a leadership role, or dealing with higher level architectural problems that don't generally require lower level algorithm design and analysis as almost anything that you'd ever need at that level has already been written, optimized to hell and has been battle tested.

I'd also spend some time on projecteuler.com and interviewstreet.com solving problems to help me apply those newly re-learned learnings to help 'em stick.


答:
Programmer Competency Matrix is a good enough checklist, and it's an easy, informative read, from a single source.

Norvig's classic blog on "Learning to Program in 21-Days" is also a good read.


答:
Learn maths. Programming is mathematics if you remove the visual effects.

Use the right language for your program. Then, know at least the capabilities of the languages.

Spend some time on algorithm before coding. If you are coding as a member of a group, study the algorithm together.

If running speed is a matter and if you are free to fix the code for an architecture, use the routines specialized for your CPU, GPU, etc.

Spend good time for debugging and testing.

Be curious about almost everything about programming. You will learn with time.


答: How to find out what you don't know as quickly as possible ...</p>


答:
I'd like to comment on this because I think that even though this question has probably been asked a lot in these forums, it doesn't matter, you get different perspectives every time it's asked.

With that, here's my experience and I guess "wisdom or insite" into our profession.  Some of this will overlap with what others have already stated but I'm listing my experience and then my philosophy/opinion/suggestions to you for each

1) Yes, as others have stated, you do need to have some level where you're able to digest complex ideas, process, and be able to work through and come to your own solutions in code to problems.
   On the other hand:  You can learn to become a better problem solver over time if you have a lot of positive motivation to keep sticking with it, work hard, and ask a lot of questions.  Most developers who say they know everything or try to appear like they do simply hide the fact that they've asked a lot of questions, worked their ass off in code, etc. to get to where they are at and to get as good as they appear to be

2) In our industry, again in my opinion, there is a lot of egos you have to deal with unfortunately.  I don't see this as a good thing and it's especially a trait for a LOT of developers out there.

What you will find in my experience are one of the following type of teams:

"Code & Run" teams.  This means all they care about is getting crap out the door fast, they could care less about code quality (clean code) or code that is maintainable later on.  Stay away from these shops if you can.  It's hard because even if you drill a company in an interview, you won't truly know how the team operates until you get the job and are about 4-6 months into it to see really how they code or if they truly promote teamwork and foster collaboration (ideas, etc.)

Average dev shop that is "ok".  This means they care a little about code quality.  They might have a few good devs on the team who work good in a team and have a positive attitude and then a mix of some devs who could have other traits such as egoistical, lazy, etc.  So I mean it's kind of a hogposh shop but where the code isn't the greatest but tolerable

Great shop.  This shop tries their best to really follow good design patterns.  They may not be experts on design patterns but they know of good practices such as DRY, SOLID, whatever else.  They don't necessarily expect superstars to join their team but they are looking for devs who are at least coding somewhat clean code and have a good amount of experience first.  These are the teams you want to stride for...but you might have to go through a few shops to find good teams

Superstar Shop.  This is a shop that only looks for the absolute best programmers but also best meaning programmers that have it all.  They communicate well and work well as a team (positively with others for the better of the tema).  Keep in mind every shop is gonna tell you yea, we only look for the best.  Most of that is nonsense...they have good intention but a lot of times it's just marketing talk.  But there is a % of shops that truly are looking for top talent.  And you'll know that when you get into the interview and they're asking questions on threading, advanced design patterns, etc.  So..to get to that level and if you want to work on a team that has this kind of expectation, it may take you a few years to get there

Superstar Shop with negative vibes/egos.  There are shops out there that due hire top devs but where the majority of that shop can have a bunch of pricks who are superstars.  So there are teams that just don't tolerate bad code but they are real pricks about it.  It's not a team enviornment and you want to stay away from this crap.  Our industry doesn't need it and neither do you

and one of the following types of developers out there:

a) Huge ego, knows everything, always wants to keep a distance from all, reveals little, has an attitude ...essentially not a team player and not someone you want to work with or have on your team

b) Devs who are there just to do a mediocre job and get the job done and go home.  Personally I guess there is nothing wrong with it from an initial standpoint but at the same time I think our profession needs developers who are passionate and are willing to sacrifice and enjoy their craft to ultimately provide value but also to improve as a developer over the long haul because they care about becoming better

c) Devs who probably could make it but are too lazy, negative, or whatever other traits they possess that just causes hell for everyone but because mostly of laziness factor.  Wouldn't want lazy people on my team...lazy engineers are not what we need in our profession

d) Devs who are good to great developers, who care about teamwork, who are willing to humble themselves, to teach others, to communicate, and to be open to constructive criticism on process or code (code reviews, etc.) and just simply care about being positive at work while working as a developer with all collegues.  You want to work with these kinds of people, a positive supportive dev environment.  Now I'm not saying that a team should be looking for leachers...you need to be able to hold your own weight but you don't want to end up on teams where they expect you to be a "star" developer and to never ask questions...that's a bad environment.  Stay away from that...it's hard to find this environment in my opinion in our profession overall in my and other friend's experience throughout our careers.  You can find good teams but they're harder to find than landing in chaotic shops with bad attitudes.  So know what you're getting into, the grass is not always greener just because developers are so-called "professionals".  I'm sure this can relate to any job probably but I think more so with our profession than most others out there.

3) One thing I learned the hard way is that if you are a perfectionist and care too much about good process and perfect code, it's gonna get you in trouble some day.  Find that balance.  You don't want pure sloppy code and you don't want to waste too much time to the point of your employer getting pissed off because it took you 2 weeks to get a relatively medium sized task done that should usually be done in lets say 3-4 days because you wanted it to be too clean.  A good book to read and good guy to follow in our industry is "Uncle Bob".  I am a big fan of his as are many developers out there.  Read his blog posts on code and buy his book.  I can't say how much wisdom and experience he has to offer people including yourself, who is just coming out of college about our profession in terms of best pratices, attitudes, philosophy, etc.:

his company blog: http://blog.objectmentor.com/articles/category/clean-code (and check out http://blog.objectmentor.com/articles/2009/02/03/speed-kills)

one of his many good books that I feel every developer should be reading or have read and have on your shelf: http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

His personal blog: http://cleancoder.posterous.com/retarded-architecture

And a good video of his at a conference he spoke: http://www.viddler.com/explore/oredev/videos/36/

4) Don't stress yourself out about competing with all the devs you work with.  You need to realize it's going to take you a few years to even master the basics in our profession even if you've done well in CS.  It takes time, work hard, ask questions, research, be patient...and especially since our industry is now in such flux, don't get frustrated if you do not know everything.  Focus on the basics first...know them well for the first few years.  Don't over complicate your worries, you're a Jr. Developer trying to become better and that will happen if you work hard and get good at basic OOP first.  A lot of devs in our industry still don't know the fundamentals because they haven't put the effort into trying to know them and that's a negative.  You want to know the fundamentals first well (Polymorphism, Encapsulation, yada yada).  If you don't have a lot of opportunity to do a lot of OOP in your first few jobs, make a huge effort to research and practice it at home by playing around with code with some fun pet project on the side that you enjoy.

I could make this post longer but I'll stop here.  If you have more questions per my post just reply in the comments and we can continue on discussing.

Ultimately if you are a genius, super smart, smart, mediocre, or suck, no matter who you are at what level, if you want to make it in our profession you are always going to have to work super hard and continually try to learn and improve yourself and aim for the best you can be (code, communication, etc.).  Our profession is not one to take lightly.


问:
Inc/dec vs +=/-=
I'm looking at a programming language design decision that's difficult to make precisely because there seems to be no objective basis for choosing one option over the other. The question is, given that a language doesn't have a ++ operator, would the better choice for an increment operator be as in C:

```<code>a += 1
a += b
</code>```

or as in some versions of Pascal:

```<code>inc a
inc a b
</code>```

(And similarly with -= vs dec of course.)

Considerations I can see for inc:

Slightly shorter for the typical case where the delta is 1.

Less familiar to most programmers.

Eliminates the corresponding *= etc operators, which are much less commonly used.

Is there anything I'm missing?

答: As in other domains, the primary consideration should be given to the users of the language and their needs and habits. Principle of least surprise suggests that the preference should be given to the choice which is consistent with your users' current habits, i.e. if they're primarily C, C++, Java or Python programmers, += is a better choice.

Title: Inc/dec vs +=/-=


答: They are probably expecting you to answer something like "Model View Controller (MVC)" or "Model View ViewModel (MVVM)". And I suppose that if you answer just "Document - View" it would be oh-so-nineties and oh-so-not-kosher-anymore.</p>

Title: UI Developer Interview Question


问:
Is Learning C++ Through The Qt Framework Really Learning C++
The problem I have, is that most of the C++ books I read spend almost forever on syntax and the basics of the language, e.g. for and loops while, arrays, lists, pointers, etc.

But they never seem to build anything that is simple enough to use for learning, yet practical enough to get you to understand the philosophy and power of the language.

Then I stumbled upon QT which is an amazing library!

But working through the demos they have, it seems like I am now in the reverse dilemma. I feel like the rich man's son driving round in a sports car subsidized by the father. Like I could build fantastic software, but have no clue what's going on under the hood.

As an example of my dilemma take the task of building a simple web browser. In pure C++, I wouldn't even know where to start, yet with the Qt library it can be done within a few lines on code.

I am not complaining about this. I am just wondering how to fill the knowledge void between the basic structure of the language and the high level interface that the Qt framework provides?

答:
Don't worry; at first most of your code will just use the framework, but after a while you'll have to extend it, even if just a bit.  Then you'll have to use more and more of C++.

Also remember that you have the whole source of Qt available, the IDE will happily take you to the definition of any function/method/class you want.  The deeper you go, the more C++ you'll see.

Others have mentioned about the difference between Qt C++ and standard C++.  These fall in two camps:

different library: Qt includes all the usual containers: arrays, lists, sets, hashmaps, etc.  They fit together very well and are good implementations, but they're not the STD variety.  Still, in recent versions (4.1 and later, I think) they have 'STD-like' APIs in addition to the old variety (and a Java-like API).  In the end, the design choices (when to use an array, when to use a hashmap) are the same, so changing to STD for non-Qt projects is not so hard.

moc syntax additions: mostly for signal-handling, but also a couple of nicer loop constructions.  Lots of people feel this tool means it's not C++ anymore; but IMHO, they feel just like slightly smarter macros.  A good loosely-coupled signal handling is a huge advantage of a good framework, and it's notoriously hard to do on a static typed language.  In modern C++, it's doable with a heavy dose of templates; but that was far from standard when Qt first got moc.  In the end, if you later want to do non-Qt projects, first check if you'll be using any framework and if it has signals.  If yes, then most of what you're used to do with Qt will apply, so no 'harm' in learning Qt first.


答:
It would be better to approach this question with an aesthetic angle rather than being totally technically. By aesthetic, I mean the following

Have a look at the company's website and compare it with the layout of an another company.

Research a few layout designs on the web

Focus on how you would present the design and would collect the data for presenting the design.

Always give priority to the ease of use rather than heavy-duty functionality

Style your answer with the above points and then stress on the methodology you would use to solve them.

The above points are in addition to the strong theoretical foundations you must be expected to answer in interviews. By methodology, I perceive the interviewers are expecting you to define an application, its layout and the ways in which you create it. Try to be holistic in your approach in answering broad questions. Point some latest improvements in browser technology that could make the UI better. You could get more specific information on the UI site.

Title: UI Developer Interview Question


答:
Considering that Qt has its own meta-compiler that you have to process your source files with, it's hard to consider Qt code to be "just C++".

But more importantly, the style of C++ that Qt uses and encourages is something that, to the rest of us, was last seen around 1995.

Really, it's an attempt at making C++ as Java-like as at all possible. It misses out on, or discourages, all the amazing things that actually make C++ worth using today. Instead, you're locked into a subset which most of all feels like an inferior Java.

So if the goal is to learn C++, I'd say no, stay away from Qt. Perhaps take a look at Boost instead, if you want to use an established library as a starting point. Boost embodies the practices that are considered good today.

But honestly, if you want to learn the C++ language, then pick up a good textbook, and focus on the language.

Writing a web browser, no matter how you do it, will at best teach you about web browsers. It won't teach you much about the language you're using.

C++ as a language does not have a WebBrowser class built in. If you read the C++ standard, it says nothing about browsers. It doesn't even mention GUI applications.

That's because those things are built on top, provided by libraries such as Qt. C++, like any programming language, is about logic, about how to express that logic. And yes, that means working with arrays and pointers and loops and all those things.

Would you be able to write a web browser using just those built-in tools, given sufficient time? Would you know how to express the program logic involved?
If not, then you need to spend more time on loops and pointers, and less calling new QWebKit() and just piggybacking off ready-made libraries.

The "philosophy and power of the language" is in arrays and lists and loops, not in web browsers.

Title: Is Learning C++ Through The Qt Framework Really Learning C++

Body:
The problem I have, is that most of the C++ books I read spend almost forever on syntax and the basics of the language, e.g. for and loops while, arrays, lists, pointers, etc.

But they never seem to build anything that is simple enough to use for learning, yet practical enough to get you to understand the philosophy and power of the language.

Then I stumbled upon QT which is an amazing library!

But working through the demos they have, it seems like I am now in the reverse dilemma. I feel like the rich man's son driving round in a sports car subsidized by the father. Like I could build fantastic software, but have no clue what's going on under the hood.

As an example of my dilemma take the task of building a simple web browser. In pure C++, I wouldn't even know where to start, yet with the Qt library it can be done within a few lines on code.

I am not complaining about this. I am just wondering how to fill the knowledge void between the basic structure of the language and the high level interface that the Qt framework provides?


问:
OOP - How to handle multiple instances of a class
In OO programming, what's the preferred way of handling multiple instances (objects) of a single class? Say you want to write a program where a random number of circles get drawn on screen, where every circle is an instance of a Circle class, and when you click a button, every circle changes color.

How would you do that?

I see two ways, either to use a static variable (array) in the class holding all instances, along with a static function which loops through that array and calls a recolor method on each instance. Or to use the same variable and method, but instead put it in a separate class, maybe called CircleManager.

答:
Basically the direction of your thoughts is correct. I would generalize the array to a collection, of which the array is just one. There are many different types: lists, maps, sets etc. to choose from according to your needs.

The collection can be maintained inside another class object if you wish so. This is a design question, which is hard to answer without more details, including the programming language you are using. In some languages, everything is inside some class, so you have no choice in this respect. In others (like C++) you do.

Typically in modern GUI frameworks, clicking a button generates an event, which is then handled by some entity registered to get notifications about that type of event. You may choose to register a single controller object (CircleManager if you want), which then iterates through each circle and changes their color. Or you may register each individual Circle as a listener to the button click, so then each gets notified in turn and changes its color independently.


答:
Since this rather a broad question, I would try to answer it in a general context and then with the circle example you have mentioned

General Explanation

If you are creating multiple instances of your class and you want the instances to communicate with each other, looping them as a collection would be ideal as pointed out by Peter Torok. Read your language documentation to implement this as this may vary across languages. This is OK in case all the instances would be called by a single program or would be executed in totality. I don't recommend storing the data inside the classes as static variable as this would make the class somewhat rigid to modify in future.

But in case you want to create multiple instances of your class and multiple collections of your class instances, then it would turn tricky as you need to exchange information among classes and if the classes are stateful, then it would take some real good work

Circles Example

In this case, you can wrap your class with an another class that would draw a specified number of circles and a click action (assuming general GUI components) that would redraw the circles.

```<code>class CircleWrapper(number):
   constructor creates the required number of circles by calling the circle class with draw method
   click event that calls the recolor method on each of the circles

class circle ():
  draw
  recolor
</code>```

CircleWrapper(10)creates 10 circles. Clicking the GUI invokes the recolor method. Wrapper methods aren't given in detail in the above example. Though this involves an extra call, it is easier to extend the model and to add run-time changes and validations.

Title: OOP - How to handle multiple instances of a class

Body:
In OO programming, what's the preferred way of handling multiple instances (objects) of a single class? Say you want to write a program where a random number of circles get drawn on screen, where every circle is an instance of a Circle class, and when you click a button, every circle changes color.

How would you do that?

I see two ways, either to use a static variable (array) in the class holding all instances, along with a static function which loops through that array and calls a recolor method on each instance. Or to use the same variable and method, but instead put it in a separate class, maybe called CircleManager.

Body:
Since this rather a broad question, I would try to answer it in a general context and then with the circle example you have mentioned

General Explanation

If you are creating multiple instances of your class and you want the instances to communicate with each other, looping them as a collection would be ideal as pointed out by Peter Torok. Read your language documentation to implement this as this may vary across languages. This is OK in case all the instances would be called by a single program or would be executed in totality. I don't recommend storing the data inside the classes as static variable as this would make the class somewhat rigid to modify in future.

But in case you want to create multiple instances of your class and multiple collections of your class instances, then it would turn tricky as you need to exchange information among classes and if the classes are stateful, then it would take some real good work

Circles Example

In this case, you can wrap your class with an another class that would draw a specified number of circles and a click action (assuming general GUI components) that would redraw the circles.

class CircleWrapper(number):
   constructor creates the required number of circles by calling the circle class with draw method
   click event that calls the recolor method on each of the circles

class circle ():
  draw
  recolor

CircleWrapper(10)creates 10 circles. Clicking the GUI invokes the recolor method. Wrapper methods aren't given in detail in the above example. Though this involves an extra call, it is easier to extend the model and to add run-time changes and validations.


答:
If your going to use an open source alternative .NET "framework" I would recommend Nancy

Nancy has a significant amount of community activity and if you look at the commit history you see it's actively being worked on.

It's a significantly more lightweight web framework that's similar to Ruby's sinatra. This means you can use it to handle the basic web things you need

Routing

Views

Interaction with HTTP servers

The goal of the framework is to stay out of the way as much as possible and provide a super-duper-happy-path to all interactions.

It's a lightweight cross platform framework that does the minimal amount you need, doesn't dictate anything about the application architecture you should be using and then just get's out of your way.

Title: Using alternative MVC framework

Body:
I am new to ASP.NET MVC and EF. I read about open source implementations of MVC pattern like Spring, FubuMVC, Castle etc.

I want to know how flexible these alternatives are when compared with ASP.NET MVC. Which one is widely used and whose help is easily available on the NET?


问:
Can you call any php model class in an MVC from the controller?
I'm creating a simple MVC at the moment and am wondering if it's 'correct' to be able to call any model class directly from the controller to get the data to send to the view?

I have the following folder structure:

```<code>.htaccess
index.php
/controller
/model
/templates
</code>```

I also have the needed model classes within the /model folder, at the moment I've tried playing with a /model/model.class.php to try and build all parts of the site but it's already starting to become huge and I think it might be better to completely cut it out.

I'm thinking the better approach is to use:

```<code>elseif($_GET['type'] == "Profile") {
    $profile = new thread($userId);
    $comments =  $profile->getComments();
    require "templates/profile.php";
}
</code>```

The above is a brief example but is that how a controller could/should/might look or was the first approach better or am I completely missing the point of the model and controller communication?

答:
In order to allow for separation of concerns your controllers definitely should be able to access multiple models.  For example, On a blog site you would need a model to manage your posts and another to manage the users.  However when the controller that handles the functionality of retrieving the posts to generate the display view, it likely (depending on how the data has been stored) will need to also access the user model to get names and other such information depending on what the view needs.

As for the rest of your question, I'm not sure if I completely follow your thought process without seeing your code.  However I would suggest that you download a few of the available frameworks such as CodeIgniter, CakePHP, FuelPHP, Zend, or others as found here.  Take some time and get familiar with different implementations.  This will help you in that you'll see what others have tried and what you prefer.  I often find it helps to try out other approaches to problems in the process of developing/improving what I'm working on.


问:
How to do lazy loading in a SOA fashion?
For example, I've got a root object exposed in a SOA service, say Invoice (Invoice has line items as children).

Sometimes, I need to retrieve its detail line items. I'm thinking to make it lazy loading, because it's a traffic overhead to transfer line items every time Invoice is required. But in SOA fashion, it seems unlikely. Because all it can expose are Invoice POCOs, with contain no logic. Thus I cannot attach my lazy loading logic to Invoice to instruct it to load lines items when needed.

答:
There is nothing wrong in calling a service again to get the invoice items. On service level:

ServiceInvoice LoadInvoice(Guid invoiceId) will get you the invoice without the details,

List<InvoiceItem> LoadDetails(Guid invoiceId) will get you the lines.

After you've done that, you've lost the OOP part and the code becomes less intuitive on client side. To correct that, you may want to add an additional abstraction layer:

```<code>class Invoice : ServiceInvoice
{
    public List<InvoiceItem> Lines
    {
        get
        {
            return MyService.LoadDetails(this.Id);
        }
    }
}
</code>```

Body:
There is nothing wrong in calling a service again to get the invoice items. On service level:

ServiceInvoice LoadInvoice(Guid invoiceId) will get you the invoice without the details,

List<InvoiceItem> LoadDetails(Guid invoiceId) will get you the lines.

After you've done that, you've lost the OOP part and the code becomes less intuitive on client side. To correct that, you may want to add an additional abstraction layer:

class Invoice : ServiceInvoice
{
    public List<InvoiceItem> Lines
    {
        get
        {
            return MyService.LoadDetails(this.Id);
        }
    }
}


答:
I would suggest you look into publish and subscribe event systems, such as the Qt signals and slots system.

Using this system each graphic object would publish a click event signal, and any other object interested could subscribe to that event, and thus react to the signal.

Your graphic could also subscribe to a 'set color' event, and react accordingly when that event was published by another object.


答:
Yes, you can allow any controller to call any model. That is actually what MVC is about.

Different frameworks solve that problem in different ways. For example, in Zend Framework, you create new model just by creating new object:

```<code>$my_model = new My_Model($someId);
</code>```

Now it is autoloaders problem to find the physical location of the file this model is in, and require it. You are also able to configure autoloader, in case you want non-standard directory structure.

In Magento, for example, model loading is done via static method:

```<code>$my_model = Mage::getModel('my/model', $someId);
</code>```

In general this does exactly the same thing as above.

As of the directory structure, make sure you don't bloat the entire /model directory. Split them in subdirectories, like this (for My_Model example):

```<code>/model
 - my/
    model.php
    something.php
 - post/
    post.php
    author.php
 - comment/
    comment.php
    foo.php
</code>```

You can also namespace your models, and make them a little bit more like Javas packages, since this is supported in PHP 5.3 above (if I recall correctly). Zend Framework's autoloader already does this by either simulating namespaces or actaully using them (PHP 5.3 and ZF 2.0 only). To make your life easier, you may use some kind of autoloader. I'd suggest you use the one from Zend Framework, or you can just write one yourself.

Title: Can you call any php model class in an MVC from the controller?

Body:
I'm creating a simple MVC at the moment and am wondering if it's 'correct' to be able to call any model class directly from the controller to get the data to send to the view?

I have the following folder structure:

```<code>.htaccess
index.php
/controller
/model
/templates
</code>```

I also have the needed model classes within the /model folder, at the moment I've tried playing with a /model/model.class.php to try and build all parts of the site but it's already starting to become huge and I think it might be better to completely cut it out.

I'm thinking the better approach is to use:

```<code>elseif($_GET['type'] == "Profile") {
    $profile = new thread($userId);
    $comments =  $profile->getComments();
    require "templates/profile.php";
}
</code>```

The above is a brief example but is that how a controller could/should/might look or was the first approach better or am I completely missing the point of the model and controller communication?

Body:
Yes, you can allow any controller to call any model. That is actually what MVC is about.

Different frameworks solve that problem in different ways. For example, in Zend Framework, you create new model just by creating new object:

$my_model = new My_Model($someId);

Now it is autoloaders problem to find the physical location of the file this model is in, and require it. You are also able to configure autoloader, in case you want non-standard directory structure.

In Magento, for example, model loading is done via static method:

$my_model = Mage::getModel('my/model', $someId);

In general this does exactly the same thing as above.

As of the directory structure, make sure you don't bloat the entire /model directory. Split them in subdirectories, like this (for My_Model example):

/model
 - my/
    model.php
    something.php
 - post/
    post.php
    author.php
 - comment/
    comment.php
    foo.php

You can also namespace your models, and make them a little bit more like Javas packages, since this is supported in PHP 5.3 above (if I recall correctly). Zend Framework's autoloader already does this by either simulating namespaces or actaully using them (PHP 5.3 and ZF 2.0 only). To make your life easier, you may use some kind of autoloader. I'd suggest you use the one from Zend Framework, or you can just write one yourself.


答: Research shows that code with many redundancies correlates strongly with errors. Here's an interesting paper on the matter (PDF alert).</p>

Title: Make a big deal out of == true?

Body:
There is a colleague of mine who constantly writes:

```<code>if (someBool == true)
</code>```

It drives me up the wall!  Should I make a big deal of it or just drop it?


答:
Your question implies that a new feature of your web app can be deployed either by changes to stored procs or by changes to the app. To my experience, this is very seldom the case. Most often you have either

just exchange the app (and keep the database as it is)

or exchange the app and change the db

Obviously the second step needs more efford than the first.

Only exception from that is when you app is especially designed for generically executing queries or stored procs, where the queries itself are considered to be a form of data, from among the user or the app can choose dynamically which one to execute Do you have such an architecture in mind?.

Title: cost trade-offs for deploying changes to prod, stored procs vs. LINQ

Body:
Some context for thisi question: it is not about development time over the entire iteration of development, but just the stage of deploying changes from dev to prod environment. "LINQ" here really means LINQ, ORM, or C# where T-SQL would otherwise be used. And here "stored procs" is just a general term that encompasses database objects which include stored procs, functions, and views. Question was just phrased as "LINQ", "stored procs" since the two are commonly compared in questions. To narrow the scope of the discussion we can assume web applications. Now finally the question is,

What are the trade-offs in the cost of deployment (from dev to prod) between the two approaches?

Some say it's easier to rollback Db schema changes than rollback changes across C# files in a solution. Others say it's easier to version or source control C# code than Db schema objects. If you make changes to LINQ queries, you'll most likely need to recompile the app to push the changes to prod. If you make changes to database schema, then that may require having a T-SQL script run in order to sync the changes to prod.

As with many decisions with programming, the chosen solution may be context-sensitive. e.g. for data structures some situations may call for a hash map, and for others, it may be best to use a stack. Each has its own advantages/disadvantages.


问:
Is it important/essential to learn software development methodologies for beginners?
I'm a student and I've been programming for not very long.
Particularly, I'm learning CodeIgniter framework - The book I'm reading is "Professional CodeIgniter". In the book, the author mentioned Agile Methodologies ( and I find it somewhat little bit difficult to understand ).

I want to know if it is essential to learn the methodology first before starting to produce software or should I learn coding to be good at it first?

答:
If you are using a book to learn your first language, then there is no need to learn agile, scrum, xp... yet.

If by student you mean that you are working on a degree in CS, then you will need to learn about these development methodologies in the next few years. You of course won't know which one your employer will use until you get a job.


答:
If you are working alone through your studies, then it's not important to stop and review all the possible software development methodologies (or even the top five!) before you learn the language and the processes taught in whichever book you're reading.

However, if you take a moment and familiarize yourself with the basics -- and here I mean even the "I read it in Wikipedia" basics -- of a few development methodologies, then you will be ahead of the game. As you were learning the basics of a language and working through books that (I hope) have example projects to do some questions like "how might I approach a problem like X when working in a Agile environment" or "how many of these tasks could I do in 2-week sprint".

A familiarity with multiple methodologies at any point while a student will prepare you for any of a number of situations you might be in as a future employee -- because you don't know what methodologies your future employers will want you and your team members to use.

Title: Is it important/essential to learn software development methodologies for beginners?

Body:
I'm a student and I've been programming for not very long.
Particularly, I'm learning CodeIgniter framework - The book I'm reading is "Professional CodeIgniter". In the book, the author mentioned Agile Methodologies ( and I find it somewhat little bit difficult to understand ).

I want to know if it is essential to learn the methodology first before starting to produce software or should I learn coding to be good at it first?


答:
Essential?  No.  Helpful?  Sure.

I think methodologies are MUCH easier to learn than how to code well.  So I would definitely start there.  Being an excellent developer will certainly be advantageous when applying for jobs and will make you a valued member of any team.

That being said, being familiar with different methodologies can also increase your value as an employee.  Different companies will use different practices, so being familiar with them can only help you in the long run.  Or in a situation I've faced recently - my company started transitioning from waterfall to agile/scrum - and the couple of guys who were familiar with that were leaned on to be leaders during that transition.

It's really like comparing apples to oranges.  You should learn both and try to be good at both.  I guess if I had to pick one for what's going to be most advantageous in the long run though, I would pick coding.


答:
I think that += is more universal, since you can extend it to other operations as well without having to introduce new keywords:

*=, &=, |=   and more...

It is no problem to introduce a new operator like *= later, but introducing new keywords is problematic, since they can conflict with identifiers in existing code.

Title: Inc/dec vs +=/-=

Body:
I'm looking at a programming language design decision that's difficult to make precisely because there seems to be no objective basis for choosing one option over the other. The question is, given that a language doesn't have a ++ operator, would the better choice for an increment operator be as in C:

```<code>a += 1
a += b
</code>```

or as in some versions of Pascal:

```<code>inc a
inc a b
</code>```

(And similarly with -= vs dec of course.)

Considerations I can see for inc:

Slightly shorter for the typical case where the delta is 1.

Less familiar to most programmers.

Eliminates the corresponding *= etc operators, which are much less commonly used.

Is there anything I'm missing?


问:
Should one use pseudocode before actual coding?
Pseudocode helps us understand tasks in a language-agnostic manner. Is it best practice or suggested approach to have pseudocode creation as part of the development lifecycle? For instance:

Identify and split the coding tasks

Write pseudocode

Get it approved [by PL or TL]

Start Coding based on Pseudocode

Is this a suggested approach? Is it practiced in the industry?

答: I use comments as a kind of very high-level pseudo code, in that I write the comments before I write the code. I find that thinking through the entire problem, even at a high level, improves my code considerably.</p>


问:
Why special characters are deemed risky in URL and query strings?
From a security perspective, the special characters like '&' or  are a big no no in URLs and query strings. I could find the articles that explained the ways to bypass this restriction, but could find something that explained with example how can this be a security risk.

Please explain the risks of these special characters. The question is simpler and I could google a bit more to find the answer. But the reason I am asking it here is that it will help someone in the future. Besides the level of detailing and specification one gets here, cannot be learned anywhere else.

答:
In ASP.NET, those characters are blocked by default to prevent a beginner developer introducing a security hole in the application.

Consider the following scenario:

On a home-made blog, users can post comments.

Those comments are stored in the database.

The comments are loaded later and displayed to visitors.

When submitting something containing HTML reserved characters, there are chances it will be saved as is in the database (and in fact, it must; escaping HTML characters on this level is rather a bad practice).

Later, the same comments are displayed on a page, as is. The developer forgot to escape HTML characters.

Now anybody can post arbitrary HTML code on the page, including malicious JavaScript.

Note that if this is the default behavior in ASP.NET, you can still disable it, either if the users are expected to submit HTML content, or you don't care either because you'll never display the submitted content, or because you:

are sure the content is escaped properly each time it is displayed,

have made the proper tests to ensure that the content is really escaped,

have audit and security checks of your code.


问:
C vs C++ for a Java (and possibly python) Programmer
I am a Hobbyist Java programmer and I would like to further my programming skills by learning C or C++ and Python.

I have read many C vs C++ articles but none of them contain the information I'm looking for.

I would like to know if it is better to learn C or C++.  In most articles I read most people recommend C++ saying that it is better because it is OO and is easier to write GUIs in or they don't recommend C saying that you will learn bad FO habits.

But I can program in Java which is OO so the FO habits won't stick. As for the GUI, I think python might be better suited at handling that.

I would also like to know which is better for python. i.e. which works more well with python or which runs faster with python etc.

So do you recommend C and python and java or C++ and Python and Java

P.S I do most of my programming on linux.

答: Depends on what you want and need to learn.  C++ is fairly "concept compatible" with Java, so you can come up to speed with it more quickly.  But learning C will force you to learn about pointers and storage management more quickly and deeply.</p>

OwnerDisplayName: Moyamo


答: Since you appear to want to learn lots of languages at once, you could try learning Python, C and C++.  This way you would be able to answer your own question from experience.</p>

Title: C vs C++ for a Java (and possibly python) Programmer

Body:
I am a Hobbyist Java programmer and I would like to further my programming skills by learning C or C++ and Python.

I have read many C vs C++ articles but none of them contain the information I'm looking for.

I would like to know if it is better to learn C or C++.  In most articles I read most people recommend C++ saying that it is better because it is OO and is easier to write GUIs in or they don't recommend C saying that you will learn bad FO habits.

But I can program in Java which is OO so the FO habits won't stick. As for the GUI, I think python might be better suited at handling that.

I would also like to know which is better for python. i.e. which works more well with python or which runs faster with python etc.

So do you recommend C and python and java or C++ and Python and Java

P.S I do most of my programming on linux.


问:
Employer appeal; OOP use in mainstream; solutions that blossom with OOP
I'm currently in the process of what I hope to be a career change into the programming field.  Despite my wide range of knowledge in the field and additional exposure to concepts in college (which in the end left a lot to be desired), I feel I might be missing out on what really matters when appealing to employers.

I found this post https://stackoverflow.com/a/1991453 to be specific to my predicament.  Importantly:

I've seen a lot of terrible C++ code and it's not just from people who don't understand the concepts. I've seen a lot of coders who know exactly what an object is and can explain polymorphism and all those technical OOP terms perfectly. But if they don't know when to use it, they'll never be able to take full advantage of it. I know because I was like this myself. I had read a book on OOP in high school which explained all the concepts, but I went years before I actually used them because I didn't see when they'd actually benefit my code.

I am comfortable with OOP concepts but a little rusty with supporting languages like Java, C# (my favorite for OO), and even C++.  The reason I can't claim to be at least proficient in this area is because I'm not really sold on OO design; everytime I set out to solve a problem that can be done in OOP, I find myself forcing its use and end up making a procedural solution in C which I believe to be a much more elegant program.

I guess this involves three questions: Can I still (honestly) sell myself as being valuable to an employer given my skill-set strengths and weaknesses as explained above? Is there any projects or problems I can tackle solo (for practice) that is just smarter to do with OOP?  And given an object strong project, what language should I concentrate on?

答: First, not every application should be shoe-horned into the OO paradigm. Procedural programming is very much alive and a viable alternative to OO for some cases (javascript and php for instance). If you can indeed cleaner, more expressive, and more effective code in a procedural style than a coworker could using objects, then you will certainly have value to an employer. All that being said, any employer hung up on buzz-words (whose money still spends) or who employs an application designer whose design you are expected to implement, may be less than satisfied if you are (uncertain? unconvinced? I know I was unconvinced for a year or two) about OO concepts. I would suggest you try a book on design patterns (Head First Design Patterns is great) to perhaps take your OO understanding to the next level. Hope this helps.</p>

OwnerDisplayName: Tim


答: Ack. I'm that guy.  The shame, the shame.  It's how I learned, and it's how I "auto-format" in my head.  The only time I use Joel's prefered syntax is when the bool variable has a verb prefix like "is."  I need the verb, be it "is," "can," "did," or else I need the == to provide the verb "equals."  I might never break that habit, so I'll understand if you don't say 'hello' to me on the street.</p>

Title: Make a big deal out of == true?


答:
I think the most common misconception about OOP is that it's supposed to make writing software much easier. That's where some of the criticism comes from, because when writing software, OOP often means more and sometimes even less natural code. That's what makes it hard to see the benefits of OOP, as everyone who starts programming just writes new programs and never has to maintain existing ones.

However, the real benefit of OOP only shows when you have to maintain software over the years, while constantly changing parts of the program in ways nobody expected when they were first written.

You should see OOP as a way to make sure that local changes to the software stay local and don't affect the rest of the program. In this sense classes are sort of explicit placeholders for future changes. In a procedural program it is often hard to see where you have to change the code to add a completely new feature, without affecting anything else.

Surely you can write procedural programs that are also extensible, but you have to think about it and design it properly. OOP provides you with a general idea of how programs can be structured to keep them maintainable, which means that don't have to think about design that hard! The same goes for other programming paradigms, OOP isn't necessarily the just the most common right now.

So in conclusion I think the only way to really understand OOP is to change and add features to existing software. This is the most common task for programmers anyways, and it's supposed to be easy! Not having a good design makes it harder than it has to be.

That sort of makes it hard to answer your question, as any project can benefit from OOP if it's complex enough and needs to be maintained and expanded. I think projects that can have any number of unforeseen features, such games or bots would be good examples. You can also work on a open source program, that is in general the best way to practice advanced programming.

Title: Employer appeal; OOP use in mainstream; solutions that blossom with OOP

Body:
I'm currently in the process of what I hope to be a career change into the programming field.  Despite my wide range of knowledge in the field and additional exposure to concepts in college (which in the end left a lot to be desired), I feel I might be missing out on what really matters when appealing to employers.

I found this post https://stackoverflow.com/a/1991453 to be specific to my predicament.  Importantly:

I've seen a lot of terrible C++ code and it's not just from people who don't understand the concepts. I've seen a lot of coders who know exactly what an object is and can explain polymorphism and all those technical OOP terms perfectly. But if they don't know when to use it, they'll never be able to take full advantage of it. I know because I was like this myself. I had read a book on OOP in high school which explained all the concepts, but I went years before I actually used them because I didn't see when they'd actually benefit my code.

I am comfortable with OOP concepts but a little rusty with supporting languages like Java, C# (my favorite for OO), and even C++.  The reason I can't claim to be at least proficient in this area is because I'm not really sold on OO design; everytime I set out to solve a problem that can be done in OOP, I find myself forcing its use and end up making a procedural solution in C which I believe to be a much more elegant program.

I guess this involves three questions: Can I still (honestly) sell myself as being valuable to an employer given my skill-set strengths and weaknesses as explained above? Is there any projects or problems I can tackle solo (for practice) that is just smarter to do with OOP?  And given an object strong project, what language should I concentrate on?


答:
Hearing your description makes me want to have 3 classes.

a class for a circle
a class for the circle container (say, Circles) ;)
a class for your application logic

The Circles class hold and retrieve different circles to be interacted with. An instance of it could be part of the application class.

This is informed by the Single Responsibility Principle: Circle is responsible for holding state about a single Circle, not multiple Circles. Circles is simply responsible for holding the collection of circles. The application then can have logic which ties the UI to the Circle data or whatever the heck you need to do.

As you add stuff to this (say, what if you want someone to interact with the circles using their mouse?) then you will obviously need to grow out a more complex object model.

I'd strongly recommend investigating the SOLID OOP principles, as well as looking into things like "Tell, don't ask" etc.


答:
Learn C.

You know a OOP language already and if you want to learn as hobbyist C will keep you more interested. You can learn C++ any time you want. Also learning C might give you better idea of internal working of Linux machine that you may delve into being a hobbyist programmer.

As for what language is better. It would be bad question and possibly worst answer if I choose
 any. They both are adept at doing what they do.


答:
The ampersand (&) character isn't really forbidden, but because it is the separator for query string parameters, using it unescaped in a parameter name or value will cause undesired behavior - for example, if you have a parameter foo=bar&baz and another quux=1, a naive attempt at baking a URL might result in http://www.example.com/home?foo=bar&baz&quux=1; the query string parameters will be parsed as (excuse the pseudo-JSON) { "foo": "bar", "baz", "quux": 1 }. A similar effect can be caused with other special characters (=, @, +, %), if concatenated into a query string unescaped.

Mis-parsing (or rather, wrongly constructing) query string parameters like this is often just a nuisance (values not ending up where you expect them), but often, they can be abused to trick a web application into doing something it rather shouldn't - which would be a security vulnerability.

All web programming platforms provide a way of escaping query string parameters, and many have other ways of constructing query strings for you that take care of escaping. The other way around, BTW, is taken care of automatically: pretty much every web stack decodes query string parameters before handing them to your code, so when you read them back, they are already back in their original form.

The  thing is a different story - by itself, putting HTML (or things that look like HTML) into a query string parameter is not a problem at all, and there may even be legitimate uses for this. However, query string parameters are often inserted into the response HTML, and when that happens, you do have a problem. An example I've seen in the wild used a query string parameter to pass an error message, which was then inserted into a nice red error box; the error message was inserted without further checking or processing, so an attacker could insert

Title: Why special characters are deemed risky in URL and query strings?

Body:
From a security perspective, the special characters like '&' or  are a big no no in URLs and query strings. I could find the articles that explained the ways to bypass this restriction, but could find something that explained with example how can this be a security risk.

Please explain the risks of these special characters. The question is simpler and I could google a bit more to find the answer. But the reason I am asking it here is that it will help someone in the future. Besides the level of detailing and specification one gets here, cannot be learned anywhere else.

Body:
The ampersand (&) character isn't really forbidden, but because it is the separator for query string parameters, using it unescaped in a parameter name or value will cause undesired behavior - for example, if you have a parameter foo=bar&baz and another quux=1, a naive attempt at baking a URL might result in http://www.example.com/home?foo=bar&baz&quux=1; the query string parameters will be parsed as (excuse the pseudo-JSON) { "foo": "bar", "baz", "quux": 1 }. A similar effect can be caused with other special characters (=, @, +, %), if concatenated into a query string unescaped.

Mis-parsing (or rather, wrongly constructing) query string parameters like this is often just a nuisance (values not ending up where you expect them), but often, they can be abused to trick a web application into doing something it rather shouldn't - which would be a security vulnerability.

All web programming platforms provide a way of escaping query string parameters, and many have other ways of constructing query strings for you that take care of escaping. The other way around, BTW, is taken care of automatically: pretty much every web stack decodes query string parameters before handing them to your code, so when you read them back, they are already back in their original form.

The <b> thing is a different story - by itself, putting HTML (or things that look like HTML) into a query string parameter is not a problem at all, and there may even be legitimate uses for this. However, query string parameters are often inserted into the response HTML, and when that happens, you do have a problem. An example I've seen in the wild used a query string parameter to pass an error message, which was then inserted into a nice red error box; the error message was inserted without further checking or processing, so an attacker could insert <script> tags and run malicious javascript, such as reading the current session cookie and posting it back to the attacker's dropbox, which would then allow the attacker to take over the victim's session. This attack vector is commonly referred to as cross-site scripting (XSS), and it's both a common and a serious vulnerability.

However, culling potentially dangerous code from query string parameters is a rather weak and costly defense. The proper way of preventing XSS is to escape ('html-encode'; again, every web programming stack that I know of provides a function to do this) untrusted data when outputting HTML, not when reading it. So in my example above, the correct fix would have been to html-encode the error message before writing it into the HTML page.


答:
In 2012, I actually would argue they are the same -- presuming you have a solid way of deploying database migrations and solid deployment procedures. If you are dealing with deploying database changes -- which do not compile with but are part and parcel with source code -- you take on the same overhead costs weather it be an ORM-based solution or a RPC-based solution (stored procedures are remote procedure calls).

Typically, code changes are cleaner and easier to deploy and especially to roll back in production. Worst case scenario is knocking the app down for 5 seconds to replace files and spin it up. Database schema updates, or even worse restores, can be ugly affairs. Depending on scale, downtime can measure hours.


答:
Also, you state that you're considering using Python for your GUI, but I've not heard that Python's GUI tools are any better than Java's Swing library, one that I feel is quite powerful if you know it well and can be used to good effect.

If anyone has hard data that suggests I'm wrong, please post the link. I'm all about learning.


答:
Depends on what you want to program.

C is often used for stuff like kernels, UI toolkits...etc.

C++ is used for browsers, games, applications that have special performance requirements (CAD, 3D design and the like).

The two languages are really different from one another, even though you can write C programs in C++, the mindset is very different.


答:
As C is a subset of C++ you should concentrate on just learning C++.
I know both languages. I learned C first.
Today I would definitely not start a new project using C instead of C++.
It is important that you learn to use pointers and you can do so with C++, no problem.
You can learn the non object-oriented features of C++ first so that you don't bypass them (stuff like pointers, structures, pointers to structures, arrays, references). Then move on to classes and templates.

By the way, it is easier to learn the Java language having known C++ already than I imagine it would be the other way around. This is mainly because of the pointer arithmetic facility in C++.

There are free compilers for Linux.


答:
Both C and c++ are very exigent languages.

I you learn C first. You will gain a better understanding of how a computer program works, and eventually a better understanding of how C++ works.

I you start with C++. You have to do it carefully because, having the same power than in C, you could get exposed to errors you won't be able to understand without a proper understanding of C concepts. On the other hand, you will directly have the tools to write safer programs (exception, RAII, memory management ...). You will also open your eyes to the whole complexity of this language. C++ is not only a Object Oriented language. It allows generic programming, meta-programming, procedural programming, ...

My personal point of view is that you cannot program in C++ if don't know C. But you never program the C way in C++.

Finally, C, C++, and Java are fairly compatibles with python through SWIG and Jython (for Java).


问:
I'm working on a PaaS similar to Heroku or Google App Engine, and was curious which pricing structure users prefer. Ideas?
My current project is a cloud deployment platform similar to GAE or Heroku. I'm trying to figure out what pricing method works best for us and the users. Assuming that I cannot currently provide a free plan, here are the options:

1) Have fully unlimited scaling (GAE-like), and charge for usage ($5 per project + x cents per CPU hour the project uses on our system, also charge a certain amount for bandwidth in/out, database storage + I/O, r/w data store, memcached, etc.)

This ends up being cheaper (around $20 for a moderately loaded website) and more "fair" for the user (pay only for what you use), but much more complicated with the many different factors that affect final price. This type of architecture is more resilient to what you throw at it, so if you get a traffic spike, it will work perfectly fine, you'll just get charged more.

2) Pay for "application readiness"/specific scalability (have a specific amount of processes per user available to accept requests, maybe $20 a month (3 cents per hour) per process), and for a specific tier of a database. No bandwidth/IO charges (within fair use, of course). Add-ons like email and memcached are extra. (Heroku-like)

This option is a lot more simple, and much easier to project costs on. However, the pricing curve is rather steep. You do end up likely paying more (probably $40-$60 a month for a moderately-loaded website), but all of those miscellaneous costs are completely abstracted.

Which would you more likely pay for? Also, is there another option I may be overlooking?

答: I much prefer the first model. So many sites want to extract $x/month and some of these sites make it very difficult to unsubscribe from. Even if the first model was more expensive, I'd prefer it as I would only be paying if I had a project, in which case, justifying the cost is very easy.


答:
Ok, the correct answer is: "It depends", mostly on what you want to do.

From the sounds of it you want to "improve your programming skills", what do you mean by this?

If you mean you want to find good tools to get stuff done, and solve problems or do something fun/useful, you should choose Python for higher level stuff.  Don't worry about performance so much as you can always optimize it later.

Python is a joy to program with as you don't need to worry about much of the cruft in other languages and typically can focus on the application logic itself.  Python will mainly improve your programming skills in the area of designing/implementing an entire application, OO concepts, and functional concepts as well as introduce a lot of syntactic sugar.  I recommend running import this to get an idea of what the Python community is about.  Python is a different mindset from Java, one where the programmer is treated as an adult that knows what they are doing.  There are very little arbitrary decisions made for you.  Python typically has chosen the simplest/easiest to understand solution for the problems any language needs to solve.  It remains very explicit relative to other scripting languages, so it's very easy to comprehend and read once you get past the syntax difference between it and Java/C/C++.  Python also has bindings to many of the C/C++ libraries/APIs.

If you want to see why Java was created you can code in C++ :).  I really cannot think of a good use case for C++ that doesn't involve a bunch of pre-existing C++ programmers or a great C++ library/api (ie. http://qt.nokia.com/products/).  I personally consider it one of the most complicated programming languages there is.  However, if your goal is simply to learn, it's a pretty darn good language for that, as there a lot of problems to solve and things to know to get your code working well.

Edit: Since I couldn't think of a good use case for C++ I found a great thread where C++ programmers state why they use it :) http://lambda-the-ultimate.org/node/663. But since I cannot condone C++, personally, I also have to link to this funny interview http://harmful.cat-v.org/software/c++/I_did_it_for_you_all

C is a great language for learning for many of the same reasons as C++, but the language itself isn't nearly as complicated.  C and C's concepts are everywhere.  C compliments Python, Java, AND C++ so for a pure learning experience, I would recommend C over any of them. Memory management and pointers are critical concepts to fully grasp.


答:
I think inc and dec are a poor choice, for the following reasons:

They are abbreviations and abbreviations should be avoided. At the same time increase and decrease would be a lot to write.

They introduce extra keywords. A language should have as few keywords as possible, so that programmers are as free as possible in their choice of names.

inc a b is a binary prefix operator. In C-style-ish languages, almost all binary operators are all infix (except array access).

Unlike += and -= they don't emerge from a rule, but are arbitrarily chosen. Once you understand that L o= E means L = L o E, you can use this with any operator. Personally I use *= and /= quite often (scale up, scale down), as well as ||= (set if null (this actually depends on the language)), &&= (good for aggregating conditions).

That last point is the most important one. When designing a language, you want few features that compose well rather than having a lot of idiosyncracies to be memorized.

Your language has "pure" binary operations and assignments. And anyone can write a = a o b already (thus explicitly composing assignment and the binary operator o). Adding inc and dec and whatnot to the cocktail is not good, because it is a non-evident choice, that covers a single case.

As a counter example: adding call by reference for example allows programmers to roll their own inc if it pleases them. That's a powerful feature. Similarly, allowing the combination of any binary operator with an assignment operator also composes well, because it works with any operator.

Title: Inc/dec vs +=/-=


答:
Since you would like to improve your programming skills and already have skills in Java you could go with either of them, c++ will be easier but here is a list of reasons for why you might want to learn C

Useful for low level interactions with hardware ( It's useful for interfacing with electronics )

Useful for appreciating ( and understanding ) other programming languages and paradigms ( like OOP )

Useful for learning how memory management works and the problems associated ( something you might take for granted in garbage collected environments like Java )

Systems programming ( Linux tools like Lex which generates Parsers and many many other tools are C based )

Stuff that are in other languages ( like Mutabality and Reference types Vs Value types ) will be more clear

So if you want to learn a lower level language go for C and anyway you will have python for a high level scripting language


问:
Can we guarantee a program will never go wrong?
We have a system here. Recently there is a wrong calculation in one of the number in the report generated by the system. Through out our experience, we've never encounter any problem/error in this system for some years.

Because the writer of this system had already gone, we can hardly trace the programs. But we've verify the input data, the setting and they are right.

Now my question is, will a computer program suddenly go wrong without any logical reason? If I slam on the server machine, will one of the number which the computer is calculating, become another number and make the calculation wrong?

I agree my idea there is quite mad, but I just want to know, how can we know the problem is not caused by the program and the input, but some other factors?

P.S. This mad system has no log.

答:
Hardware and software environments are in a constant state of flux. Moving parts, electricity, , temperature, dust, and OS code changes are examples.

Therefore I do not think it is even probable or expected that a computer software program will always behave the same since the environment is always changing.

Software can run for a long time as expected , but eventually either a small change to the host OS software will change which would effect the program in question or the hardware will value.

I am talking about current day computers.


问:
What should a GetSelectedIndex method return when no rows are selected
I'm creating a UI table component that returns an array of selected indices.

Some typical return values would be

```<code>var myRetVal1 = [0];//one value selected
var myRetVal2 = [0,1,2,3,8,11];//multiple value selected
</code>```

as you can see I'm always returning an array.

I had an idea to return -1 when nothing is selected, but then I thought that might be confusing when in every other condition an array is returned.

So checking for an empty set of values would be either

```<code>//returns -1
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems !== -1){
   //we have data to process
}
</code>```

OR

```<code>//returns []
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems.length > 0){
   //we have data to process
}
</code>```

OR

```<code>//returns null
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems){
   //we have data to process
}
</code>```

Maybe I'm making too big a deal over this, but is there a standard expectation for this type of control?

As I build other controls should they conform to a standard empty return value or should they always return a "empty" version of their expected return type?

答:
I'd be okay with either of the latter. I don't like the first one because you're changing the actual data type returned (int rather than array).

Optimally, I'd go with the second one as it makes more semantic sense. If you're returning an array of selected items, then it makes more sense (again, semantically) to check array.length === 0 than array === null.


答:
I would return an empty array. It bothers me when people return null collections instead of empty collections. The majority of what I would be doing with your return value will be iterating over it, mapping over it etc. and my functions will work correctly with an empty array, but will either break, or have to be modified to deal with null

The worst is when somebody writes a function that returns null for no elements, just the element for 1 element, and an array of elements for multiple elements. It can triple the size and complexity of my code just because I have to check for all the different conditions (I don't mind complex code, but I do mind unnecessarily complex code).

Title: What should a GetSelectedIndex method return when no rows are selected

Body:
I'm creating a UI table component that returns an array of selected indices.

Some typical return values would be

```<code>var myRetVal1 = [0];//one value selected
var myRetVal2 = [0,1,2,3,8,11];//multiple value selected
</code>```

as you can see I'm always returning an array.

I had an idea to return -1 when nothing is selected, but then I thought that might be confusing when in every other condition an array is returned.

So checking for an empty set of values would be either

```<code>//returns -1
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems !== -1){
   //we have data to process
}
</code>```

OR

```<code>//returns []
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems.length > 0){
   //we have data to process
}
</code>```

OR

```<code>//returns null
var selectedItems = tbl.GetSelectedIndex();
if(selectedItems){
   //we have data to process
}
</code>```

Maybe I'm making too big a deal over this, but is there a standard expectation for this type of control?

As I build other controls should they conform to a standard empty return value or should they always return a "empty" version of their expected return type?


答:
Is there any projects or problems I can tackle solo?

Yes, many. Take a simple project around a subject you know something about, say student registration in a college. Focus on a class such as Person. Now the Person may be a professor, an admin, a student, etc. So what is required to maintain registration for a set of courses? Thinking along these lines can help you set a scope for your project. Make sure you cover about 5 classes at the most so that you can focus on the techniques rather than the business itself and begin applying what you know to build an application that solves the problem. Stay away from fancy GUI, or sophisticated database methods since it is not the objective. The objective is to practice OO concepts regardless of whether the data gets saved in a file, XML file, or a database.

Another way, and it may be better, is to pick a book that uses an example in a language you like, say Java or C#. Such books would have "OOP" or "Beginning OO" in their title. Make sure you browse the book and feel like you want to go along with it before you buy it.

When you have covered the basics, you may want to move to more theoretical books about OO Analysis and OO Design including design patterns.


答:
Pseudocode can be useful if you're unfamiliar with the language, or if you need to change mental contexts. On the rare occasion that I write pseudocode, it's on paper. Sometimes just taking your hands off the keyboard and scribbling on paper can help get around a mental block.

But as a formalised part of the development process? No way. It's a sporadically helpful tool for individuals. There are better ways to "know what you're writing before you write it", like:

defining the contract (pre/post/invariant conditions) of the method before you start

TDD

1 and 2 combined (writing tests to execute the contract)

I'd also suggest that getting any sort of approval before you start writing code is likely to cause much more hassle than it's worth. Design reviews (pre-implementation) can be useful, but they need to be at a higher level than individual algorithms.

Title: Should one use pseudocode before actual coding?

Body:
Pseudocode helps us understand tasks in a language-agnostic manner. Is it best practice or suggested approach to have pseudocode creation as part of the development lifecycle? For instance:

Identify and split the coding tasks

Write pseudocode

Get it approved [by PL or TL]

Start Coding based on Pseudocode

Is this a suggested approach? Is it practiced in the industry?


问:
Any changes/improvement for LINQ 2010 vs LINQ 2008
I'm VB.NET user and now learning LINQ. The book I'm reading now focus on LINQ 2008 VB.NET. I want to know whether there are changes/improvement in LINQ 2010?

p/s: I'm reading this book: Pro LINQ Language Integrated Query in VB 2008

答:
It appears that most of the improvements between linq in .NET 3.5 and linq in .NET 4.0 have to do with improved capabilities in the System.Linq.Expressions namespace.

http://community.bartdesmet.net/blogs/bart/archive/2009/08/10/expression-trees-take-two-introducing-system-linq-expressions-v4-0.aspx

VB.NET 2010 adds support for multiline lambda statements.

http://www.simple-talk.com/dotnet/visual-studio/visual-studio-vb-2010-enhancements/


答:
To hit this from a different attack angle, Is there anything preventing you from using your domain expertise in your primary profession to write software? Can't you imagine an application that would make it easier to do your current job? I don't know what a sports performance coach does, but I can imagine that keeping records of the progression of the people you are coaching and charting that progress could come in handy for you and for the people you mentor.

If you build an app, using OO techniques or otherwise, you'll get some experience applying those techniques. If you partner with another friend with software development skills, you'll start to understand the software engineering problems (branching and merging code, for example, and real world team collaboration problems). If you ship the app (by offering it for free or for a fee to your peers in your current work), you'll get the rest of the experience needed to understand how to support and maintain an application. As you maintain the application, you'll hopefully come to understand the weaknesses of your initial design as you start accommodating feature requests and bug fixes.

Of course, this presumes that you don't have an urgent need to replace your current job, but when you're done, you'll either have the makings for a small business or enough experience to convince someone else to employ you.


问:
Why is it good not to rely on changing state?
This question arises out of the question https://softwareengineering.stackexchange.com/questions/25569/is-haskell-worth-learning

Generally a few often repeated statements are made, about how Haskell improves your coding skills in other languages, and furthermore, this is because Haskell is stateless, and that's a good thing.

Why?

I've seen someone compare this to only typing with the left hand, or perhaps closing your eyes for a day and just relying on touch. Surely there is more to it than that?

Does it relate to hardware memory access, or something else which is a big performance gain?

答:
A simplified answer is: when you see a name in a purely functional language you know what the associated value is by a simple lookup of its definition. If you have mutable variables, you can only tell by which of the several assignments to it was executed last, so you have to also analyse control flow, which in turn might be conditional, leaving you with multiple possibilities. To get an exponential explosion you only need to consider that the RHS of the assignments are themselves dependent on variables, so you have to recursively analyse them too.

The bottom line in the above analysis is that it is untenable without comments explaining the intent, invariants, and semantics: these may be hard to interpret, and it may be hard to verify the semantics are adhered to in the actual code.

This answer is basically an expansion of @Javier's point 1.

I think it is also an explanation of the popularity of the fraudulent OO regime: with OO the mutable state is encapsulated which makes analysis a lot easier by localising the mutations to some extent, and permitting much more robust expression of and verification of semantics.

Having noted that, functional programming is not the answer. The right answer is a system which supports both inductive (functional) and coinductive (procedural) programming, so the right tools can handle both stateless and stateful programming. It's just that the constructive (functional) theory is well established whereas the theory of state management is still in its infancy.