答:
If your application is doing XML operations and has JUnit tests then the only real dependency there is the dependency to junit.jar.  Your application should not need any Eclipse specific libraries on the classpath.

You sound as if you do not have a complete understanding of what the classpath is and how it relates to the compilation and execution of Java code.  I highly recommend that you learn how to develop a simple application with a text editor and the command line.

As far as submitting your code, you can compile and package your code into a JAR file, and submit this along with junit.jar and a simple batch file or shell script that will execute the Java virtual machine to run your program.

Another way would be to compile your program, unpackage junit.jar, and package it all together into an Executable Jar file.  All of your classpath dependencies will be self contained within the one file and on most operating systems it can be launched as a typical executable.

Title: Submitting Java Code with Junit unit test

Body:
I have mostly worked on simple java programs and compiled and run them with Eclipse on Windows. So, I have no experience of using command prompt for compiling Java projects and do not have much info about what actually happens beneath the play button in Eclipse.

Now I have to submit a Java application which will have basic operation on XML. My project also will have (JUnit) Unit Test.

My question is related to submission of this Project.

Which files would be necessary to submit the code. So, it executes
properly?

Does choosing Eclipse as an IDE or junit as a unit testing framweork
produces any dependenices i.e the executor of the program should
have eclipse/libraries to execute the program on his machine?


问:
How to implement Cache in web apps?
This is really two questions. Im doing a project for the university for storing baseball players statitics, but from baseball data I have to calculate the score by year for the player who is beign displayed. The background is, lets say 10, 000 users hit the player "Alex Rodriguez", the application have to calculate 10, 000 the A-Rod stats by years intead of just read it from some where is temporal saved. Here I go:

What is the best method for caching this type of data? Do I have to used the same database, and some temporal values on the same database, or create a Web Service for that?

What reading about web caching so you recommend?

答:
Insanity: doing the same thing over and over again and expecting different results.

Albert Einstein

Calculate it once store the result in the database.

Only purge this result if the underlying data changes.

When a user requests the statistics of a given user, fist check the cache. If one exists return this immediately, otherwise do the calculation and store it.

ContentLicense: CC BY-SA 3.0

Title: How to implement Cache in web apps?


问:
What should happen at the start of a software project startup?

A quick introduction

My college semesters include a 8 week project working for an actual company with a software need in order to get some much needed practical experience. I have just started such a project with 5 other students. We're required to spend roughly 40 hours a week per student on this project. We're working with SCRUM as the software development method, this was assigned by our teachers.

The question

Day one of the project just ended which has created some questions for me as to how to start a project in the 'real world'. Our first day included working on a project planning document (not sure what the English term is), creating a appointment with the company for an introduction and the opportunity to start specifying the requirements and setting up some standards for the behavior within the group.

However these items didn't take that long to finish. We've made some concrete plans for tomorrow and the day after we'll meet the company. This still leaves several hours of 'work-time' unspent. Is it usual not being able to fill every hour of a day for work at the start of a project or are we simply too inexperienced to see what work needs to be done at this stage of a project, or are we, perhaps, going through the above list too fast?

How does this work in the 'real world'? Do you spend your time wondering 'what should I do now', or do you have a clear view of what you're supposed to do at that moment?

答:
Yes, starting a project is slow and will often not fill the whole day due to the need to concert with others which may have their own schedule. (Some other questions have proposed things you may want to consider, but the company partner in your project may also have requirement for them, speak about those and be ready to propose something if it doesn't matter for them).

Back to what I think is the core of your question.  In my practice, starting a project is made incrementally -- only part of the team start work on the new project and only partial time -- while completing the previous one.


问:
Why do we need private variables?
Why do we need private variables in classes?

Every book on programming I've read says this is a private variable, this is how you define it but stops there.

The wording of these explanations always seemed to me like we really have a crisis of trust in our profession. The explanations always sounded like other programmers are out to mess up our code. Yet, there are many programming languages that do not have private variables.

What do private variables help prevent?

How do you decide if a particular property should be private or
not? If by default every field SHOULD be private then why are there
public data members in a class?

Under what circumstances should a variable be made public?

答:
It has nothing to do with trust or fear of attacks, it is solely about Encapsulation -- not forcing unnecessary information on the user of the class.

Consider private constants -- they should not contain secret values (those should be stored elsewhere), they can't be changed, they don't need to be passed into your class (otherwise they would have to be public).  The only possible use for them is as constants in OTHER classes.  But if you do that, those classes now depend upon your class, to do work that is unrelated to your class.  If you change the constant, other classes might break.  That's bad from both sides -- as the writer of your class, you want the freedom to change as much as possible, and don't want to worry about things outside your control.  A consumer of your class wants to be able to depend upon the exposed details of your class, without worrying about you changing it and breaking their code.

A consumer of your class wants to know everything needed to INTERACT with your class, and does not want to know anything about your class that doesn't change how they do so: it is useless trivia.  If you have used a langauge with reflection, how often have you used it to learn not how some class does something or where it is throwing an exception unexpectedly, but simply the name of the private fields and methods?  I'm betting never. Because you have no use for that knowledge.

Title: Why do we need private variables?


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

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

答:
Make everything as simple as possible, but not simpler.

-- Albert Einstein (for me, via Scott Myers). Emphasis added.

LastEditorDisplayName: Roger Pate

ContentLicense: CC BY-SA 2.5


答:
My internal alarm is ringing when I see the opportunity to start specifying the requirements and these items didn't take that long to finish together. While other answer provide great ways to set up an healthy environnement, be sur that one of the biggest peril is under specifications. So you might spend some time on this phase. It can be a week (full-time) in your 8 week project.

The hard part is finding the missing spec, and the things that are not working in the current specs. It is really difficult to criticize your own work. What you should do is a bit or role playing. Some people are the client, and the other the project members. The client is someone who will judge your work (teacher, mentor...). He could be an external member of the project (find someone with some experience with this kind of project). Iteration should go this way:

client reads the requirements

client ask questions about missing requirements, feature specification, possible failures assessement, tests organization, framework choice...

project team answers & update the documents

One you knwo what you want to do you may begin to set up a workflow for your team.

At the end of this work you should have a set of features with basic task breakdown for each of them. Set up milestones (week 3 we need to have finished milestone 1 & 2, week 6 we need to have stable source code to test it on weeks 7 & 8 and stick to small bugfix + documentation writing ...). When you start a milestone, publish a list of tasks somewhere (you can use an excel sheet or even a bug tracker for this) and agree on who starts with what. When someones finishes his task, he takes another one (and communicates about it). Before that, someone else should have a quick look at what he has done to check if it is correct and complete.

Setting up all this workflow is kind of hard for beginners, but is far more important than having a nice wiki service. You need to take at least a week to think about how you will work. You don't need to apply the organization I have described here (this is just really an exemple) but you should take some time to think about anything that works with you, and set up the necessary tools. The goal is to engage everyone. There should always be an easy answer to the question "what should I do now?".

Title: What should happen at the start of a software project startup?

Body:
A quick introduction

My college semesters include a 8 week project working for an actual company with a software need in order to get some much needed practical experience. I have just started such a project with 5 other students. We're required to spend roughly 40 hours a week per student on this project. We're working with SCRUM as the software development method, this was assigned by our teachers.

The question

Day one of the project just ended which has created some questions for me as to how to start a project in the 'real world'. Our first day included working on a project planning document (not sure what the English term is), creating a appointment with the company for an introduction and the opportunity to start specifying the requirements and setting up some standards for the behavior within the group.

However these items didn't take that long to finish. We've made some concrete plans for tomorrow and the day after we'll meet the company. This still leaves several hours of 'work-time' unspent. Is it usual not being able to fill every hour of a day for work at the start of a project or are we simply too inexperienced to see what work needs to be done at this stage of a project, or are we, perhaps, going through the above list too fast?

How does this work in the 'real world'? Do you spend your time wondering 'what should I do now', or do you have a clear view of what you're supposed to do at that moment?


问:
Is there a sequence to read through the Android developer site for a user new to Android?
To summarize: I can buy a book, people say "Just read the developer site", I like to be spoon-fed the early learning piece for a technology, what path through the developer site will give me that spoonfeeding I need (that is, examples tied directly to the section being discussed, a clear path, etc.).

I keep seeing that I don't need to buy an Android development book, that I should just read the Android developer site, because it has everything I need to know. I see it more as drinking from a fire hose.

But I'm one of those people who likes to be walked through the basics. I like to build up my knowledge, rather than being dropped into reference documentation. I also like to make sure I have see all/most of the topics covered. I'd hate to develop the wrong thing, because I don't know about Fragments, Content Providers, or whatever.

So, since it's a great resource, better than any book (we don't need no stinking books), how do I traverse the site to get the information provided in the same way as a book would lay it out?

答:
After going through the developer site I believe that my original premise is correct.  If you want a clear (guided even) overview of the topic, use some other source first.

I was able to use Android Boot Camp 2012 to get an overview of the topic.  (Of course, it's not that great for reference back to later)

After that, I'm better able to read what's on the developer website and put the pieces into a good context.

This just in... Android Training, including some beginning training


答:
There are some good answers citing the benefits to future maintainers and users of a class.  However, there are also benefits to the original design.  It provides a clear demarcation point between when your goal is to make things easier on yourself, and when your goal is to make things easier on the class user.  When you choose between public and private, it signals to your brain to switch to one mode or the other, and you end up with a better API.

It's not that languages without privacy make such design impossible, just less likely.  Instead of being prompted to write something like foo.getBar(), people are inclined to think a getter isn't necessary, because it's easier to write foo.bar, but then that decision isn't revisited when you later end up with longer monstrosities like obj.container[baz].foo.bar.  Programmers who have never worked in a stricter language may not even see what's wrong with that.

That's why in languages without privacy people will often adopt naming standards that simulate it, such as prepending an underscore to all "private" members.  It's a useful signal even when the language doesn't enforce it.

Title: Why do we need private variables?

Body:
Why do we need private variables in classes?

Every book on programming I've read says this is a private variable, this is how you define it but stops there.

The wording of these explanations always seemed to me like we really have a crisis of trust in our profession. The explanations always sounded like other programmers are out to mess up our code. Yet, there are many programming languages that do not have private variables.

What do private variables help prevent?

How do you decide if a particular property should be private or
not? If by default every field SHOULD be private then why are there
public data members in a class?

Under what circumstances should a variable be made public?


问:
What does good command over an API really mean?
I have seen many organizations looking for developers who have good command over Facebook, Google and other API's. Now I am a bit confused about it. I have developed Facebook fanpages, embedded facebook buttons to websites and used google maps API too but the thing is that these API's are very large to completely master.

How much exactly do a good command over an API mean?

答:
An understanding of how the practices that the API is built on (does it require a key, web server, json, rest, authentication, get lists 1st, whatever).  Do some trivial, and then non-trivial samples for yourself.  Finally, build a good understanding of how the api documentation is laid out, so you can find items quickly.

That would be enough for me.


问:
How important is knowing functionality before coding?
I work for a software development company where the development work has been off shored to us. The on shore team handle the support and talk directly to the clients. We never talk to the clients directly we just talk people from the on shore team, who talk directly to the clients.

When requirements come, the on shore team talk to the clients and make requirement documents and inform us. We make design documents after studying the requirements (we follow the traditional waterfall model).

But there is one problem in the whole process: nobody in the either off-shore or on-shore team understand the functionality of the application completely. We just know its a big complex web app handling complex order processing, catalog management, campaign management and other activities. We struggle with the design document as the requirements would not be clear. It then goes into a series of questions/answers back and forth between the on shore team, off shore team and clients. We would often be told to understand functionality from the code. But that's usually not feasible as the code base is huge and even understanding a simple menu item take days if not weeks. We tried telling the clients to give us knowledge transfer about the application but to no avail. Our manager would often tell us to start coding even if the design document is not complete or requirements are not clear. We would start by coding the part of the requirements that seems clear and wait for the rest.

This usually would delay the deployment by a month. In extreme cases we would have very low errors in the development and production but the clients would say that's not what they asked. That would start a blame game and a series of change requests and we would end up developing something very different.

My question is how would you do development work if you don't know the functionality of the app fully?

UPDATE

The development methodology it isn't really my choice and I am not my team's lead. It is the way it began. I tried to tell people about the advantages of agile but to no avail. Besides I don't think my team has the necessary mindset to work in an agile environment.

答:
Here's some things that will help overcome the problems:

Improve communication between the two teams. Ask the other team to compress the requirement to 3 words, and then programmer will implement those words exactly. The words just need to be correct. Nothing will be implemented without those words. Every word gives you 2000 lines of code. Implementation begins when a new word is known.

If a word is not immediately clear to your programmers, they are allowed to ask single question. The question again have to be correct one. It needs immediate answer -- the answer cannot wait a roundtrip from other side of the world, but it needs to be known beforehand. Implementation starts immediately after receiving the answer and the answer will be followed to the letter.

If during implementation there are unclear or fuzzy requirements, the way to resolve them are to first look at the (existing) 3 words. If it still is unclear, then programmer makes the best guess possible. Any delay in this process is absolutely forbidden; and asking help from the other team is not the right way to resolve it -- they already had their chance of changing the requirements by deciding correct 3 words.

If after all this, the requirement is still unclear or impossible to implement, the correct way to handle is to reject those 3 words that caused the trouble, and move to next words. Any rejected words will be collected and passed to the other team, and they will need to modify the words before re-entering them to the system. Rejecting words always moves the deadline and implementation will need to be planned again.

Teams would need to be evaluated based on how many rejected words they have. After requirement has been implemented, it is fixed forever and can no longer be changed. Any attempts to change already implemented features will be rejected.

The actual problem with the question is that it assumes that more information makes implementation easier. This is not true. The more freedom your programmers have, the easier the implementation. Compressing the requirements allow communicating large amounts of information without restricting too much what programmers are allowed to do.


问:
Catching an error?
Is catching an error with try ... catch a better practice than catching an error with proper analysis/error check? For instance, removing from an empty list: Does surround with a try catch clause considered as a more efficient way than testing if the list is empty beforehand?Or is it the same? Thanks.

P.S: If a similar question was previously asked on the forum please feel free to refer it.

答:
When to Check in Code

standard things like removing from an empty list, etc.

When to use Try...Catch

external access to networks

external access to file-system

external access to databases

etc

Title: Catching an error?


答: Definitely, you need to know how to build a simple app that uses it, or even, depending on the API, a not-so-simple more useful app. You should be able to find answers easily in the documentation, of course, for the bigger APIs, you do not have to know the whole thing. Basically you should have an understanding of the API and be able to build application utilizing the API.

Title: What does good command over an API really mean?

Body:
I have seen many organizations looking for developers who have good command over Facebook, Google and other API's. Now I am a bit confused about it. I have developed Facebook fanpages, embedded facebook buttons to websites and used google maps API too but the thing is that these API's are very large to completely master.

How much exactly do a good command over an API mean?


问:
Which things instantly ring alarm bells when looking at code?
I attended a software craftsmanship event a couple of weeks ago and one of the comments made was "I'm sure we all recognize bad code when we see it" and everyone nodded sagely without further discussion.

This sort of thing always worries me as there's that truism that everyone thinks they're an above average driver. Although I think I can recognize bad code I'd love to learn more about what other people consider to be code smells as it's rarely discussed in detail on people's blogs and only in a handful of books. In particular I think it'd be interesting to hear about anything that's a code smell in one language but not another.

I'll start off with an easy one:

Code in source control that has a high proportion of commented out
  code - why is it there? was it meant
  to be deleted? is it a half finished
  piece of work? maybe it shouldn't have
  been commented out and was only done
  when someone was testing something
  out? Personally I find this sort of
  thing really annoying even if it's just the odd line here and there, but when you see large blocks interspersed with the rest of the code it's totally unacceptable. It's
  also usually an indication that the rest of
  the code is likely to be of dubious
  quality as well.

答:
C++ code with explicit delete statements (unless I'm looking at the innards of a smart pointer implementation).  'delete' is the 'goto' of memory management IMHO.

Closely related to this, code like:

// Caller must take ownership
Thing* Foo::Bar()
```

(And count yourself lucky if there's the comment!).  It's not like smart pointers are rocket science.  std::auto_ptr is made for this sort of thing (documenting and enforcing the intent expressed in the comment) and been part of the standard for ages now.

Together these scream unloved legacy code, or maintainers with a mindset stuck somewhere in the early 90s.

Body:
C++ code with explicit delete statements (unless I'm looking at the innards of a smart pointer implementation).  'delete' is the 'goto' of memory management IMHO.

Closely related to this, code like:

// Caller must take ownership
Thing* Foo::Bar()

(And count yourself lucky if there's the comment!).  It's not like smart pointers are rocket science.  std::auto_ptr is made for this sort of thing (documenting and enforcing the intent expressed in the comment) and been part of the standard for ages now.

Together these scream unloved legacy code, or maintainers with a mindset stuck somewhere in the early 90s.


答:
What do private variables help prevent?

It's about making it clear what properties and methods are interface and which ones are actually core functionality. Public methods/properties are about other code often other developer's code using your objects. I've never worked on teams of 100+ on the same project, but in my experience of maybe teams of 3-5 with up to 20 other developers using stuff that I've written, the other concerns seem silly.

Note: I'm primarily a JavaScript developer. I don't generally worry about other developers viewing my code, and I operate in full awareness that they could simply redefine my stuff at any time. I assume they're competent enough to know what they're doing first. If not, it's unlikely I'd be working on a team that doesn't use source control.

How do you decide if a particular set of properties should be private or not? If by default every field SHOULD be private then why are there public data members in a class?

I used to think it was silly to put getters and setters on private properties when you weren't really performing any kind of validation or other special treatment of the property to be set. I still don't think it's always necessary, but when you're dealing with large scale, high complexity, but most importantly a lot of other devs relying on your objects behaving in a consistent manner, it can be useful to do things in a consistent and uniform way. When people see methods called getThat and setThat, they know exactly what the intentions are, and they can write their objects to interact with yours with the expectation that they'll always get tomatoes rather than tomahtos. If they don't, they know your object is giving them something it probably shouldn't, which means it's allowing some other object to do something with that data it probably shouldn't. You can control that as the need arises.

The other big advantage is that it's easier to have your objects hand off or interpret values differently from a getter or setter based on some kind of varying state context. Because they're accessing your stuff with a method, it's much easier to change how your object operates later on without breaking other code that depends on it. The important principle being that only your object actually changes the data you've made it responsible for. This particularly important to keeping your code loosely coupled which is a huge win in terms of portability and ease of modification.

Under what circumstances should a variable be made public?

With first-class functions (you can pass functions as arguments), I can't think of a lot of great reasons other than it not being hugely necessary to do so on smaller scale projects. Without it, I suppose you might have members that are getting processed heavily and regularly by other objects to the degree that it seems a bit crufty to constantly call get and sets on an object that doesn't really touch that data itself, but that in itself would make me wonder why the object was responsible for that data. Generally speaking, I would tend to want to re-examine my architecture for flaws before deciding a public data property is necessary. IMO, there's nothing wrong with a language letting you do something that is usually a bad idea. Some languages disagree.

Title: Why do we need private variables?


问:
Does your programming knowledge decrease if you don't practice?
I'm a novice programmer. I study languages such as C, C++, Python and Java (mainly focusing on C++). I'm what you'd call "young and inexperienced" and I admit that because I can't claim otherwise.

As a student, I have many other problems besides programming. I practice programming as often as I can, and especially because my teacher gives me a lot more exercises than the rest of the class (it's a very low level), so oftentimes I spend weeks doing something else such as school projects or sports, or traveling, anything besides programming.

Don't get me wrong though, I love programming. I love to build functional code, to watch as a program comes alive at the push of a button, and to learn as much as I can. The thing is, I simply don't have much time for it.

Straight to the question, now: does your programming knowledge decrease as time passes and you don't practice? You may ask "how much time do you mean?". I don't mean a specific amount of time, but for reference you could take a month-two or even a year as an example.

By knowledge I mean anything from syntax to language functionality.

答: Knowledge does decrease somewhat, you may find yourself forgetting some of the syntax or the more complex aspects of a certain language. At first, it may also be hard to structure your code if you don't practice, but after a while that will come back.</p>


答:
To me, mastering an API generally means an ability to code to that API without having to trace deeper than one level through the documentation, and implies good command of your programming language.

Consider .NET FTP client API as an example. Mastering it does not mean that you should be able to code to it without looking at the documentation at all (although such ability does imply mastery of the API). However, given a task that you want to accomplish, you should be able to locate a method that you need to call, and code a call to that method without visiting other pages in the documentation. For example, if downloading a file requires setting up an asynchronous callback, you should know what that means, and code it without reading additional documentation on asynchronous callbacks.


问:
Open Source sponsored feature development
I am considering to sponsor a development of some particular features in some Open Source tools. I would like the results of the work to be available publicly, and if possible, to be included in the main product line. The features are usually something which is of general use, but not very critical, and no one has currently a plan to develop it. For illustration, imagine I would like to use MinGW for Win32 development, but I miss a post mortem debugging option, I would like this feature to be implemented and I am willing to pay $1000 for it.

Is there some common way how to proceed, or is this wildly per-project dependent? Are there some general guidelines how to contact the product developers, or are there some common meeting places where smart open source people who might interested to participate in such sponsored development meet, which I should visit to advertise the sponsoring option?

Are there some specific ways how to talk about the job to be more attractive to people participating in open source (e.g. it might be more interesting for them to participate in a contest than just to take a payed job, which might have a bit of mundane feel)?

Or perhaps is this something which you think has little chance to succeed, because perhaps money has very little value for open source developers?

Any tips and experiences from someone who has some experience of open source sponsorhip from any side (sponsor or the developer) are welcome.

答:
For any particular feature you want added, go ask the developer/maintainer what they're up for. Most of them have forums, request pages, or an email link somewhere. Sometimes all that is needed is a request. If it's a good idea, they'll implement it. If it's not that important to them, or they're not up for it, you can also ask any other programmer and see if they'd be willing to dive into the open source project and add your feature. Paying them is a pretty good incentive. There are sites for piecemeal work with bounties like this.

From there, you could theoretically submit the patch to the open source project and see if they want to include it. Or if they still don't want it for whatever reason, you could fork the project. Or just hang onto it yourself and feel special as the one guy with the awesome version.

(Also, have you tried DrMingw, a JIT debugger)


问:
What are the advantages of mainframes?
The downsides of Mainframes is well trodden ground; expensive, legacy, dwindling community, etc.

I'm not particularly interested in the downsides, but I am curious if there are any benefits to mainframe hardware/software over the current Intel/AMD & Linux/Windows environment.

I've been told that MFs are particularly good (and better than current servers) at heavy I/O loads. Is this still true?

答: Mainframes have a huge business advantage in that they hardware and software are paid for. This is a big deal, because software development is universally viewed as a cost center. The cost factor often offsets the many well-known disadvantages of mainframes during the cost-benefit analysis.</p>

Title: What are the advantages of mainframes?


问:
Composite-like pattern and SRP violation
Recently I've noticed myself implementing pattern similar to the one described below. Starting with interface:

```<code>public interface IUserProvider
{
    User GetUser(UserData data);
}
</code>```

GetUser method's pure job is to somehow return user (that would be an operation speaking in composite terms). There might be many implementations of IUserProvider, which all do the same thing - return user basing on input data. It doesn't really matter, as they are only leaves in composite terms and that's fairly simple.

Now, my leaves are used by one own them all composite class, which at the moment follows this implementation:

```<code>public interface IUserProviderComposite : IUserProvider
{
    void RegisterProvider(Predicate<UserData> predicate, IUserProvider provider);
}

public class UserProviderComposite : IUserProviderComposite
{
    public User GetUser(SomeUserData data) ...
    public void RegisterProvider(Predicate<UserData> predicate, IUserProvider provider) ...
}
</code>```

Idea behind UserProviderComposite is simple. You register providers, and this class acts as a reusable entry-point. When calling GetUser, it will use whatever registered provider matches predicate for requested user data (if that helps, it stores key-value map of predicates and providers internally).

Now, what confuses me is whether RegisterProvider method (brings to mind composite's add operation) should be a part of that class. It kind of expands its responsibilities from providing user to also managing providers collection. As far as my understanding goes, this violates Single Responsibility Principle... or am I wrong here?

I thought about extracting register part into separate entity and inject it to the composite. As long as it looks decent on paper (in terms of SRP), it feels bit awkward because:

I would be essentially injecting Dictionary (or other key-value map)

...or silly wrapper around it, doing nothing more than adding entires

This won't be following composite anymore (as add won't be part of composite)

What exactly is the presented pattern called? Composite felt natural to compare it with, but I realize it's not exactly the one however nothing else rings any bells. Which approach would you take - stick with SRP or stick with "composite"/pattern? Or is the design here flawed and given the problem this can be done in a better way?

答: This is a factory or repository pattern depending on if the class acts as a go-between or not. It also falls close to a 'manager' class that tends to do too many things. As long as you keep the focus on being a (possibly mutable) source for objects it's a fine approach (imo).</p>


问:
Confused about ASP.NET Ajax, jQuery and JavaScript
Yesterday, I read couple of chapters on ASP.NET Ajax and jQuery from my ASP.NET 4 book and I found those frameworks pretty interesting and decide to learn more about them.

Today, I borrowed some books from library on Ajax and JavaScript. It seems ASP.NET Ajax is different from Ajax and jQuery seems like the "new" JavaScript.

Does it mean that I can skip JavaScript and learn jQuery directly?

On the other hand, the non-ASP.NET Ajax book I borrowed seems to apply to the client side web programming only and looks quite different from what I learned from ASP.NET Ajax. If I'm an ASP.NET developer, I guess I should stick with ASP.NET Ajax instead of client side Ajax right? What about PHP? Is there a "PHP Ajax" similar to ASP.NET Ajax?

It's not that I'm lazy to learn other tools, but I just want to focus on the right ones.

答:
Client side languages are used to decrease server load of requests.

Javascript is a client side scripting language and Jquery is a framework of javascript and is optional.  Js, jquery works in your system itself and performs tasks like password validation, animation in the web page etc, they don't access the database.

Database will be MYSQL, ORACLE and exists in the web host; ASP,PHP are server side scripting languages. You can use ASP or PHP to access the database but SQL is also necessary to work on websites.


答:
Upsides:

Control: it's a unique machine and you can control who, when,for much time the programs run and how much resources it spend.

Administration: since you have one machine, you don't need remote multi-administration software to operate it.

Built-in audit trail: most MF OSes implement audit trails and I've heard of hardwares implement it too (many moons ago, don't remember details).

Security: related to the control item, this means stricter and fine grained security.

Infrastructure: since you have one piece of hardware, you can confine the infra costs in a determined room.

Real-time hardware: in addition with a RT OS, an MF can operate fast in situations where response time delays is not tolerated.

Throughput: MF vs desktops (or grids) is a comparison similar to a car with a 750hp engine (mainframe) vs 10 cars each one with 75hp engines (working together they are a grid, working stand alone they are desktops).

Title: What are the advantages of mainframes?

Body:
The downsides of Mainframes is well trodden ground; expensive, legacy, dwindling community, etc.

I'm not particularly interested in the downsides, but I am curious if there are any benefits to mainframe hardware/software over the current Intel/AMD & Linux/Windows environment.

I've been told that MFs are particularly good (and better than current servers) at heavy I/O loads. Is this still true?


答:
Mainframe had been in business since the days people used to use punch cards for data entry, line printer's for output. PC Have evolved a lot in these few decades and in the current decade we are seeing some breakthrough hardware and software evolution which are trying to make Distributed Server's more secure, stable and robust. Underline, all these technologies are slowly adopting the technologies from Mainframe. But even after all these evolutions today's Intel/AMD Server's running Linux/Windows cannot match the scalability, performance, work-balancing, robustness and stability what mainframe provided. And nevertheless Mainframe is also evolving. So what makes Mainframe stand out of the Crowd?

Huge data processing capabilities. Mainframe historically was capable and designed to handle huge data via batch processing. Hardware and Software capabilities data to be spread across multiple volumes of DASD to be processed diligently and reliably. Today we hear about BigData and the use of Hadoop and the Hive using MapReduce functionality to process unstructured data. But the technology is still at its infancy which Mainframe has been providing since ages. EasyTrieve and DFSORT/ICETOOL provided wonderful reporting and data processing capabilities which is still a challenge to be matched.

As a transaction Processor: Consider a system that authorized millions of Credit/Debit card in 11 sec TAT? I believe no system can match such a timeline what the Authorization System running on TPF system can do.

Reliability: Mainframe is stable and is known to run for months without any downtime. Hot swapping of Disk, Memory and CPU enables seamless operation even when a part fails.

Distributed vs Centralized: Though this is a long standing debate, but proponent of a Centralized system would tell you that it makes it easy to manage, control and is more secured.

Support for Legacy Code: Millions of Lines of Code are running reliably for years and Business Houses find no compelling reason to rewrite it on Non-Mainframe Servers.

Title: What are the advantages of mainframes?


问:
I want to turn VB.Net Option Strict On
I recently found out about strong typing in VB.Net (naturally it was on here, thanks!) and am deciding I should take another step toward being a better programmer. I went from vba macros -> VB.Net, because I needed a program that I could automate and I never read anything about strong typing, so I kind of fell into the VB.Net default trap. Now I am looking to turn it on and sort out this whole type thing.

I was hoping someone could direct me towards some resources to make this transistion as painless as possible. I have read around some and ctype seems to come up a lot, but past that I am at a bit of a loss. What are the benefits of switching? Is there more to it than just using ctype to cast things? I feel like there is a good article that I have failed to come across and any direction would be great.

Would a good approach to be to rewrite a program  that is written with option strict off and note differences?

答:
If I remember correctly, Strict On will make VB.net requires an type for every operation, so code like

```<code>DIM SB as New StringBuilder
</code>```

will not work as it disables late binding completely.

It makes life unnecessarily bureaucratic. If you want an strong typed language on VS.NET, use C# (VB.NET is really an unwanted renter on the building - it remained on VS because of its popularity). Strong-typed without losing late binding.

Title: I want to turn VB.Net Option Strict On

Body:
If I remember correctly, Strict On will make VB.net requires an type for every operation, so code like

DIM SB as New StringBuilder

will not work as it disables late binding completely.

It makes life unnecessarily bureaucratic. If you want an strong typed language on VS.NET, use C# (VB.NET is really an unwanted renter on the building - it remained on VS because of its popularity). Strong-typed without losing late binding.


答:
http://ajaxpatterns.org/PHP_Ajax_Frameworks lists various PHP Ajax frameworks though I don't know how well integrated they are like ASP.Net AJAX.  Part of most AJAX frameworks will involve some client-side code as the J of AJAX is for Javascript.

There were other implementations for getting AJAX functionality before Microsoft put in ASP.Net AJAX where Anthem.Net is one example that I used years ago.

Title: Confused about ASP.NET Ajax, jQuery and JavaScript

Body:
Yesterday, I read couple of chapters on ASP.NET Ajax and jQuery from my ASP.NET 4 book and I found those frameworks pretty interesting and decide to learn more about them.

Today, I borrowed some books from library on Ajax and JavaScript. It seems ASP.NET Ajax is different from Ajax and jQuery seems like the "new" JavaScript.

Does it mean that I can skip JavaScript and learn jQuery directly?

On the other hand, the non-ASP.NET Ajax book I borrowed seems to apply to the client side web programming only and looks quite different from what I learned from ASP.NET Ajax. If I'm an ASP.NET developer, I guess I should stick with ASP.NET Ajax instead of client side Ajax right? What about PHP? Is there a "PHP Ajax" similar to ASP.NET Ajax?

It's not that I'm lazy to learn other tools, but I just want to focus on the right ones.


答:
Is catching an error with try ... catch a better practice than catching an error with proper analysis/error check?

In 99.9% of cases, the shortest, simplest code is the best.

For instance, removing from an empty list...

If you are attempting to remove a specific item from a list, the item is either there or not there.  There is nothing special about an empty list.  Checking for an empty list is redundant, just as this if statement is redundant:

```<code>if (n > 0) {
  for (int i = 0; i < n; ++i) ...
</code>```

If you test for the presence of the item, you will be duplicating the work about to be done by the 'remove' call.  Don't do it.  If the library function throws when the item is not present, go ahead and use try-catch.  Consider extracting a new try_remove function that returns true when the item was removed and false otherwise.

Title: Catching an error?

Body:
Is catching an error with try ... catch a better practice than catching an error with proper analysis/error check? For instance, removing from an empty list: Does surround with a try catch clause considered as a more efficient way than testing if the list is empty beforehand?Or is it the same? Thanks.

P.S: If a similar question was previously asked on the forum please feel free to refer it.

Body:
Is catching an error with try ... catch a better practice than catching an error with proper analysis/error check?

In 99.9% of cases, the shortest, simplest code is the best.

For instance, removing from an empty list...

If you are attempting to remove a specific item from a list, the item is either there or not there.  There is nothing special about an empty list.  Checking for an empty list is redundant, just as this if statement is redundant:

if (n > 0) {
  for (int i = 0; i < n; ++i) ...

If you test for the presence of the item, you will be duplicating the work about to be done by the 'remove' call.  Don't do it.  If the library function throws when the item is not present, go ahead and use try-catch.  Consider extracting a new try_remove function that returns true when the item was removed and false otherwise.


问:
How were some language communities (eg, Ruby and Python) able to prevent fragmentation while others (eg, Lisp or ML) were not?
The term "Lisp" (or "Lisp-like") is an umbrella for lots of different languages, such as Common Lisp, Scheme, and Arc. There is similar fragmentation in other language communities, like in ML.

However, Ruby and Python have both managed to avoid this fate, where innovation occurred more on the implementation (like PyPy or YARV) instead of making changes to the language itself.

Did the Ruby and Python communities do something special to prevent language fragmentation?

答:
Lisp is fragmented because it is such a powerful model, the most amazing language ever conceived. Most languages today borrow things that were first implemented in Lisp, so in a way you can say that every language is part of this particular fragmentation. Smalltalk was for instance heavily inspired by Lisp, and Ruby is heavily inspired by Smalltalk. JavaScript is Lisp in a Java-disguise, and so on.. It's all connected, and every language inventor selects his favorite pieces from other languages.

Another factor is that Lisp is probably the easiest programming concept to implement - which is why it's done again and again and again.


问:
Adding dynamic business logic/business process checks to a system
I'm wondering if there is a good extant pattern (language here is Python/Django but also interested on the more abstract level) for creating a business logic layer that can be created without coding.

For example, suppose that a house rental should only be available during a specific time. A coder might create the following class:

```<code>from bizlogic import rules, LogicRule
from orders.models import Order

class BeachHouseAvailable(LogicRule):

    def check(self, reservation):
        house = reservation.house_reserved
        if not (house.earliest_available < reservation.starts < house.latest_available )
            raise RuleViolationWhen("Beach house is available only between %s and %s" % (house.earliest_available, house.latest_available))
        return True

rules.add(Order, BeachHouseAvailable, name="BeachHouse Available")
</code>```

This is fine, but I don't want to have to code something like this each time a new rule is needed.

I'd like to create something dynamic, ideally something that can be stored in a database.

The thing is, it would have to be flexible enough to encompass a wide variety of rules:

avoiding duplicates/overlaps (to continue the example "You already have a reservation for this time/location")

logic rules ("You can't rent a house to yourself", "This house is in a different place from your chosen destination")

sanity tests ("You've set a rental price that's 10x the normal rate. Are you sure this is the right price?"

Things like that.

Before I recreate the wheel, I'm wondering if there are already methods out there for doing something like this.

答:
This is fine, but I don't want to have to code something like this
  each time a new rule is needed.

I'd like to create something dynamic, ideally something that can be
  stored in a database.

Well, judging from your requirements, you will have to code something. A new logic rule means a new implementation. How can you sanely solve that without logical code? If you have enough fields in a database for every possibility that would most probably lead to unmanageable complexity.

I think what you really want is easy deployment: New rules, probably customized, without the need to redeploy the whole system.

The thing is, it would have to be flexible enough to encompass a wide
  variety of rules [...]

Like I said above: It'll be damn hard to solve such problems solely by configurations if the use case is mildly complex.

I think what you want is extensibility, in addition to easy deployment. So it'd be probably best to create a DSL that suits your needs or embed a scripting language (which you probably don't need if you use Python). Then it's easy to create and deploy new rules. You then just configure the rules to use. The major challenge here is to design the interface to the "mother-system".

In many languages (including many compiled languages), this problem can be overcome with dependency injection and a microkernel pattern as well. Just collect all the rules from all the deployed rules libraries. This eliminates the need for scripting language support, if your business cases allow it (Field Technicians? Technical Support writes new rules while being at the customers site?).

Sure, you can go down that route, package sequences of business rules into workflows and so on, but that just leads to a special form of DSL. Some people call that business process modelling and I have yet to see a system that employs that kind of technology successfully.

P.S.

Advice: And please don't put your rules-files into a blob in a database.


答:
I don't want to have to code something like this each time a new rule is needed.

What would you like to do instead?  The only options are to either use a Turing-complete language, which will be of approximately the same complexity as Python, or to use a simpler but less powerful language.  The second option has been attempted many times, but invariably someone wants to write a rule that cannot be expressed in the rules language.  You already have a fairly expressive language available that allows you to publish new rules with minimal effort.  It will be hard to do much better.

Title: Adding dynamic business logic/business process checks to a system

Body:
I'm wondering if there is a good extant pattern (language here is Python/Django but also interested on the more abstract level) for creating a business logic layer that can be created without coding.

For example, suppose that a house rental should only be available during a specific time. A coder might create the following class:

```<code>from bizlogic import rules, LogicRule
from orders.models import Order

class BeachHouseAvailable(LogicRule):

    def check(self, reservation):
        house = reservation.house_reserved
        if not (house.earliest_available < reservation.starts < house.latest_available )
            raise RuleViolationWhen("Beach house is available only between %s and %s" % (house.earliest_available, house.latest_available))
        return True

rules.add(Order, BeachHouseAvailable, name="BeachHouse Available")
</code>```

This is fine, but I don't want to have to code something like this each time a new rule is needed.

I'd like to create something dynamic, ideally something that can be stored in a database.

The thing is, it would have to be flexible enough to encompass a wide variety of rules:

avoiding duplicates/overlaps (to continue the example "You already have a reservation for this time/location")

logic rules ("You can't rent a house to yourself", "This house is in a different place from your chosen destination")

sanity tests ("You've set a rental price that's 10x the normal rate. Are you sure this is the right price?"

Things like that.

Before I recreate the wheel, I'm wondering if there are already methods out there for doing something like this.


答:
In the title of your question, you ask:

I want to turn VB.Net Option Strict On

In VB.NET there are 2 compiler options: Option Strict and Option Explicit.

1- Option Strict

By default, the Visual Basic .NET or Visual Basic compiler does not enforce strict data typing. To change this default behavior, see the Change the Default Project Values section.

2- Option Explicit (starting from V 2005)

By default, the Visual Basic .NET or Visual Basic compiler enforces explicit variable declaration, which requires that you declare every variable before you use it.

You can read more about this in here: MSDN-KB Support-Article

When the compiler issue an error or a warning it is for your program's correctness sake. In OO the concept of type goes far beyond primitive data types and is the heart of many concepts in OO.

The following paragraph from History of worst software bugs may be worth noting "June 4, 1996 -- Ariane 5 Flight 501. Working code for the Ariane 4 rocket is reused in the Ariane 5, but the Ariane 5's faster engines trigger a bug in an arithmetic routine inside the rocket's flight computer. The error is in the code that converts a 64-bit floating-point number to a 16-bit signed integer. The faster engines cause the 64-bit numbers to be larger in the Ariane 5 than in the Ariane 4, triggering an overflow condition that results in the flight computer crashing."

Title: I want to turn VB.Net Option Strict On

Body:
I recently found out about strong typing in VB.Net (naturally it was on here, thanks!) and am deciding I should take another step toward being a better programmer. I went from vba macros -> VB.Net, because I needed a program that I could automate and I never read anything about strong typing, so I kind of fell into the VB.Net default trap. Now I am looking to turn it on and sort out this whole type thing.

I was hoping someone could direct me towards some resources to make this transistion as painless as possible. I have read around some and ctype seems to come up a lot, but past that I am at a bit of a loss. What are the benefits of switching? Is there more to it than just using ctype to cast things? I feel like there is a good article that I have failed to come across and any direction would be great.

Would a good approach to be to rewrite a program  that is written with option strict off and note differences?


问:
How can describe slow connection issues?
I have been working on a website containing 3d maps, virtual 3d tours, etc. All of the content is large like images and video.

The problem is the site performs well under normal speed connections but  it take more time to load if network is busy or the internet connection is slow. How can I describe this to the customer? Yes, we optimize the content where its possible.

答: Your website has minimum requirements to run correctly. Detail those requirements in a document and give those to the client. If they deem the requirements to be to much, ask them what features to remove to help the speed issue. </p>


问:
Array or Malloc?
I'm using the following code in my application, and it's working fine. But I'm wondering if it's better to make it with malloc or to leave it as is?</p>

```<code>function (int len)
{
char result [len] = some chars;
send result over network
}
</code>```

答:
Variable-length automatic arrays were introduced to C in C99.

Unless you have concerns about backwards comparability to older standards, it's fine.

In general, if it works, don't touch it. Don't optimize ahead of time. Don't worry about adding special features or clever ways of doing things, because you often aren't going to use it. Keep it simple.

Title: Array or Malloc?


答: If your compiler supports variable-length arrays, the only danger is overflowing the stack on some systems, when the len is ridiculously large. If you know for sure that len is not going to be larger than a certain number, and you know that your stack is not going to overflow even at the max length, leave the code as is; otherwise, rewrite it with malloc and free.

Title: Array or Malloc?

Body:
I'm using the following code in my application, and it's working fine. But I'm wondering if it's better to make it with malloc or to leave it as is?</p>

```<code>function (int len)
{
char result [len] = some chars;
send result over network
}
</code>```


答: You could use client-side timers that alert a "bear with us" message when redirecting to a page takes long (generally 10+ seconds is experienced as "long"). Use ajax to have animations running when retrieving data from the database and on the server-side, if it's possible, write the buffer to the client once a certain piece of content has loaded, for example if you're loading a picture album of 100 images, write every 10 images to the client while the next set loads.</p>

Title: How can describe slow connection issues?

Body:
I have been working on a website containing 3d maps, virtual 3d tours, etc. All of the content is large like images and video.

The problem is the site performs well under normal speed connections but  it take more time to load if network is busy or the internet connection is slow. How can I describe this to the customer? Yes, we optimize the content where its possible.


答:
The main difference is that VLAs (variable length arrays) provide no mechanism for detecting allocation failures.

If you declare

```<code>char result[len];
</code>```

and len exceeds the amount of available stack space, your program's behavior is undefined.  There is no language mechanism either for determining in advance whether the allocation will succeed, or for determining after the fact whether it succeeded.

On the other hand, if you write:

```<code>char *result = malloc(len);
if (result == NULL) {
    /* allocation failed, abort or take corrective action */
}
</code>```

then you can handle failures gracefully, or at least guarantee that your program won't try to continue to execute after a failure.

(Well, mostly.  On Linux systems, malloc() can allocate a chunk of address space even if there's no corresponding storage available; later attempts to use that space can invoke the OOM Killer.  But checking for malloc() failure is still good practice.)

Another issue, on many systems, is that there's more space (possibly a lot more space) available for malloc() than for automatic objects like VLAs.

And as Philip's answer already mentioned, VLAs were added in C99 (Microsoft in particular doesn't support them).

And VLAs were made optional in C11. Probably most C11 compilers will support them, but you can't count on it.

Title: Array or Malloc?

Body:
The main difference is that VLAs (variable length arrays) provide no mechanism for detecting allocation failures.

If you declare

char result[len];

and len exceeds the amount of available stack space, your program's behavior is undefined.  There is no language mechanism either for determining in advance whether the allocation will succeed, or for determining after the fact whether it succeeded.

On the other hand, if you write:

char *result = malloc(len);
if (result == NULL) {
    /* allocation failed, abort or take corrective action */
}

then you can handle failures gracefully, or at least guarantee that your program won't try to continue to execute after a failure.

(Well, mostly.  On Linux systems, malloc() can allocate a chunk of address space even if there's no corresponding storage available; later attempts to use that space can invoke the OOM Killer.  But checking for malloc() failure is still good practice.)

Another issue, on many systems, is that there's more space (possibly a lot more space) available for malloc() than for automatic objects like VLAs.

And as Philip's answer already mentioned, VLAs were added in C99 (Microsoft in particular doesn't support them).

And VLAs were made optional in C11. Probably most C11 compilers will support them, but you can't count on it.

ContentLicense: CC BY-SA 4.0


问:
Can a developer get a discount for Microsoft products?
If I would start to focus on the .NET platform and be self-employed, then I probably would like to have some Windows 7, Windows Server 2008, Visual Studio 2010 licenses just for the development environment and for testing, and then a few licenses for the production environment (a Windows Server 2008 Web) and added to that upgrades when new versions is available. This will end up in a quite big amount of money.

Is there any kind of bundle discount that I can get from Microsoft in such a case? And what is the requirement to be able to get that discount?

答: If you are a student you should check out dreamspark. It allows students to get basically any professional level tool for free. Last I checked there was VS 2010, Windows Server 2008 R2, SQL Server 2008 Developer, Expression Studio Ultimate, and a bunch of others.</p>


答:
Generally speaking the stack is the easiest and best place to put your data.

I would avoid the problems of VLAs by simply allocating the largest array you expect.

There are however there are cases when the heap is best and messing around with malloc is worth the effort.

When its large but variable amount of data. Large depends on your environment > 1K for embedded systems, > 10MB for a Enterprise server.

When you want the data to persist after you exit your routine, e.g. if you return a pointer to your data. Using

A combination of static pointer and malloc() is usually better than defining a large static array;

Title: Array or Malloc?


问:
Is the phrase "never reinvent the wheel" suitable for students?
I find myself constantly running into this expression "don't reinvent the wheel" or "never reinvent the wheel" when I ask some questions on SO.  They tell you to use some frameworks or existing packages.  I know where this attitude is coming from since it's unwise to waste time on something others have already solved.  Or it that so?

As a student,  I find by using some code others wrote to solve my problem I can't learn as much as I'd like to, and I gain less insight.  And sometimes I think that phrase is mainly for working programmers facing deadlines and not for students like me.

Is it that bad to "reinvent the wheel"?  Maybe I'm thinking it wrong? Maybe there is a way I can avoid reinventing the wheel and at the same time learn a lot?

答: The answer depends a lot on the context. If you would like to gain more in-depth understanding of data structures by trying your hand at implementing a hash table, "reinventing the wheel" is the best thing you can do. If you are learning how to write compilers and need a symbol table, implementing your own hash map instead of reusing one from the standard library is a complete waste of your time.</p>


答:
I think you make a good point. Most of the programmers on this site are likely working professionals whose goal is pretty much to create quality software as quickly as possible. Reinventing the wheel fails this goal on two counts.

Re-writing code that exists is wasted effort that could be used on the unique parts of your system and makes the project take longer than is necessary.

The first version of any code is more likely to have bugs/unforseen issues. Most libraries and re-usable components have been battle tested and patched multiple times. If you re-invent a hashing algorithm or try to create your own RDBMS (unless that is what the project is) more often than not you are going to end up with inferior results.

That said, in an academic environment the goal is to learn, not deliver software on a budget. Re-inventing a wheel to understand how the spokes or axle work is a great way to accomplish that goal. That's why many programming curricula include a class on building compilers when very few working programmers ever have cause to need to do that.

Title: Is the phrase "never reinvent the wheel" suitable for students?

Body:
I find myself constantly running into this expression "don't reinvent the wheel" or "never reinvent the wheel" when I ask some questions on SO.  They tell you to use some frameworks or existing packages.  I know where this attitude is coming from since it's unwise to waste time on something others have already solved.  Or it that so?

As a student,  I find by using some code others wrote to solve my problem I can't learn as much as I'd like to, and I gain less insight.  And sometimes I think that phrase is mainly for working programmers facing deadlines and not for students like me.

Is it that bad to "reinvent the wheel"?  Maybe I'm thinking it wrong? Maybe there is a way I can avoid reinventing the wheel and at the same time learn a lot?


问:
Introducing Programming To a Mathematician
I currently am a programmer, I'm almost 16 years of age and have pretty much narrowed my careers down to something involving a Computer Science degree or Electrical Engineering degree (I know they are quite different but this question is about my friend) but my friend isn't so sure.

He is very interested in maths and is very good at it and I think he would enjoy programming but he isn't willing to try it (edit he is willing to try but has never done before). Can anyone give me an suggestions for a language or tool that he could dabble in programming (at a reasonably basic level I assume) to solve maths problems or involve some kind of maths.

As I say he enjoys maths a lot but I think he would enjoy programming, the problem is I don't want him to be put off by the stuff that isn't relevant at introductory levels such as memory allocation et al. I know that is very important but the point is that I want him to learn a bit of programming with maths then hopefully if he is interested enough he can start learning programming as programming.

Edit:
Its not that he's completely uninterested - more that he hasn't actively explored the area before, maybe because he isn't informed about it. I wouldn't want to force him to do something he doesn't want to, I see this as more of a little push so that he can learn about programming. If he doesn't like it - fair enough, I can't control that and don't want to but if he turns out to enjoy it - this push will have been the right thing.

答:
Haskell and Mathematica are the way to go, in my opinion. Most functional languages are good for math as well. Python is also good, check out the math documentation.

This module is always available. It provides access to the mathematical functions defined by the C standard.

These functions cannot be used with complex numbers; use the functions of the same name from the cmath module if you require support for complex numbers. The distinction between functions which support complex numbers and those which don’t is made since most users do not want to learn quite as much mathematics as required to understand complex numbers. Receiving an exception instead of a complex result allows earlier detection of the unexpected complex number used as a parameter, so that the programmer can determine how and why it was generated in the first place.

The following functions are provided by this module...


问:
Java Application for handling records(CRUD)
I am new to JavaEE and am faced with a tight situation here.

I have to develop a Java application for (CRUD) handling records and saving and loading an XML concerning that record. Obviously, I won't be asking you to do this for me. What I would be asking you is to give me some hints/pointer. Initially I thought JAXB would be enough for this but after putting a lot of time learning it and implementing the program I realized that it just can create the XML and read it but for update, delete I would have to do something else. Even if it wasn't for update and delete features requirement for my project I would still think that by just using JAXB is not a good implementation.

I was wondering if "REST with Java (JAX-RS) using Jersey" should do the trick for me. ?

答:
JAX-RS isn't really going to help you for this.  Much as JAX-B is for binding and unbinding XML to Java, JAX-RS is about building and consuming RESTful services.  Neither really deals with data persistence.

What you need to look at is an XML database, such as BaseX, which allows you to use XQuery to query and manipulate your XML.


答: If you are a student, and hence don't have a set deadline for your project, it is better to "reinvent the wheel". If you are programming now merely to learn how to program, and not to make money, why take shortcuts that won't help you learn? Why not do it the hard way? But, when you do become a working programmer, people will be skeptical if you don't know how to use frameworks or libraries...


问:
About the book "Peopleware - Productive Projects and Teams"
I've read Peopleware in 2009. It was one of the best book I ever read.

But this book is a little old. I'd like to know, in your opinion, what is and what is not relevant in this book?

答:
I'm pretty sure these were both in Peopleware...

One slightly irrelevant thing I can recall is the story about a bunch of developers in a classic open-plan office (not even cubes, just a grid of desks) taking wire-cutters to the PA speakers in the ceiling, and stuffing tissue paper into the ancient Bell phones (you know, the ones that weighed about five pounds with an actual dial and an alarm-clock-style clapper inside) so that they weren't so distracting when someone called you.  Of course, even this story isn't irrelevant once you view it as a developer team doing what they could to establish a decent work environment.

Also irrelevant today is their defense of actual offices with actual doors and sometimes even actual windows.  Of course, it's only irrelevant not because they were wrong but because that battle has been well and truly lost for over two decades now.

An excellent book, as you say, and one I should reread.


答:
As a student, I would expect you to begin your programming education by first copying a wheel or two to start with, then learning to modify wheels to see how they work, and to understand any limitations. Later you might even create a brand new wheel of your own to see if you can improve on the design, or to show your course supervisor your understanding of the concepts involved.

As a working professional however, I would expect you to have learned which wheel to use to solve any given problem, and when it might be appropriate to modify an existing wheel if it only partially solves your problem.  If you can't find a wheel anywhere, then perhaps you have identified market niche, or you haven't explored far enough, and you would need to be experienced enough to know when it would be appropriate to create a brand new wheel of your own.

The issue of when it is appropriate to re-invent a solution is complex, and it requires time and experience to learn when it might be better to create a brand new version of something that has already been done before. When you have only been developing for a short time, it is better to simply use an existing solution, and to ask your mentors to suggest options. When you have tight deadlines and a lot of uncertainty in a project, using something existing can be a huge time saver, and is always your first choice. You can always refactor to use other solutions later if it is appropriate to do so, even if this means eventually returning to reinvent your wheel.


答:
The answer depends on whether you wish to learn or create.

If learning is the aim, "reinventing the wheel" can give you greater insight and better understanding than using the existing wheels (library functions).

But if creating a complicated product is the aim, then "reinventing the wheel" can be a time consuming practice and will help little the creation of the product.

Nevertheless, if the soul objective is learning provided with enough time and stamina, "reinventing the wheel" is the best option, as it helps to customise every single feature.


答: The one I notice immediately is the frequency of deeply nested code blocks (if's, while's, etc).  If code is frequently going more than two or three levels deep, thats a sign of a design/logic problem.  And if it goes like 8 nests deep, there better be a darn good reason for it not to be broken up.

Title: Which things instantly ring alarm bells when looking at code?

Body:
I attended a software craftsmanship event a couple of weeks ago and one of the comments made was "I'm sure we all recognize bad code when we see it" and everyone nodded sagely without further discussion.

This sort of thing always worries me as there's that truism that everyone thinks they're an above average driver. Although I think I can recognize bad code I'd love to learn more about what other people consider to be code smells as it's rarely discussed in detail on people's blogs and only in a handful of books. In particular I think it'd be interesting to hear about anything that's a code smell in one language but not another.

I'll start off with an easy one:

Code in source control that has a high proportion of commented out
  code - why is it there? was it meant
  to be deleted? is it a half finished
  piece of work? maybe it shouldn't have
  been commented out and was only done
  when someone was testing something
  out? Personally I find this sort of
  thing really annoying even if it's just the odd line here and there, but when you see large blocks interspersed with the rest of the code it's totally unacceptable. It's
  also usually an indication that the rest of
  the code is likely to be of dubious
  quality as well.


答:
Students don't have money budgets to complete assignments, but there are due dates to consider.

As someone who was a student until recently, I think the amount of wheel reinventing that's appropriate depends on what class you're doing the assignment for. You don't want to write your own socket library for a web development and design class (if you can do that and turn the assignment in on time, what are you doing taking a class that easy?), but you'd be missing a great deal if it was an assignment for a networks class. Of course, professors usually take these things into account when they're creating assignments, so you will mostly do work that is related to the class, but sometimes, knowing what you shouldn't write yourself is important too.

That said, once you leave school, it's hard to find the time to build things that already exist. Take every opportunity you get when you can, while you're still in school.

If you get the "Use library X/framework Y" brush-off on SO, preface your question with "I'm writing X by myself to learn more about it"


问:
What Technology can Render Medium Scale 3d Environments in a Web-Browser
I intend to make a web application that displays 3d environments that can be navigated by dragging(with a finger or mouse depending on the platform). The web app will render 3d environments of development sites including contours, water pipeline locations, buildings etc.

I am trying to decide what technology/libraries to use that will create a web-app that will work on Android-Web-Browser, iOS-Safari, IE9, Safari, Firefox and Chrome. And also what technology will provide speed in development. I understand that this is 'asking for my cake and eating it too'/'asking for the moon' but I don't know all the technologies out there - so there may be advanced libraries that can render 3d environments across many web-browsers including the main smart phone ones and I dont know of them.

The 3d rendering would not be highly detailed buildings or water with effects, but rather simple 3d representations of these objects. The environment would be navigable by dragging around and you could view the landscape in layers(view only contour lines, view only underground pipelines, view only sewerage pipes, etc.).

Are there any 3d libraries for web-browsers out there? Is there a way to run OpenGL(or OpenGL ES) through a webbrowser?

What technology would you use if you were making this kind of app/web app that should work on desktop Windows, Android, iOS and WindowsPhone?

Is there any technology I have failed to mention that would be good for this kind of project?

I am tending towards a Browser Driven Web App because I get that cross platform ability(where it even works on linux and MacOS by using compatible web-browsers). Also I know of CSS3 transforms that can create cubes that can rotate in 3d space(NOTE only works for WebKit browsers - so no IE :( ). But I don't know if CSS3 is robust enough to render whole 3d environments? Do you think it could? Maybe I could use HTML5 canvas's for this? Can Google maps create custom 3d maps?

答:
As Raynos has mentioned, WebGL is one way to provide 3D functionality in a browser.  The downsides seem to be that there's very little to no IE support, and I've also heard of people having difficulties with different implementations across browsers.  I also am not sure if WebGL would "provide speed in development", but I guess that depends on how familiar you are with 3D concepts and OpenGL.

I found this article at Opera's dev site to be one of the better introductions to WebGL, although it might be a bit outdated by now.

Another alternative might be Unity 3D, which has a web player supported on the major desktop OSes and browsers (edit: Linux excluded, AFAIK), but needs to be installed as a plugin.   This would prohibit its use as the technology on public-facing sites, since you would lose most of your users right there.  Also, I don't think they have support for the smart phone browsers, but the do have iOS and Android native app export facilities (so, you code once, and compile for the different platforms).  If your users are going to be primarily paying customers, I think there's a chance they would be willing to install the web player or native apps, but you'll have to make that call.  You can't get a much more rapid 3D development environment however, Unity 3D is an extremely slick game engine with many things done for you, out of the box.


答:
I have faced the same situation. It's because of the difference in perception in industry and academics.

If you don't "reinvent the wheel" then you absolutely cannot study anything in school or understand how something works.

Whereas in an industry the objective is to bring out a product in least time and effort.

Personally, I like to go down the rabbit hole and I detest the industry philosophy but thats how businesses are done and you can't complain.


问:
Data indexing frameworks fit for large E-Commerce applications
we wrote and still maintain a large E-Commerce application. Our feature list resembles what you would expect from most shops. We'd like to improve some of our features, and now the search/suggestion list functionality (enter some letters, a JScripted suggestion list appears) has caught our eye.

Currently, we use http://xapian.org/. It has some drawbacks. Firstly, it's not actually the right solution. It has been created to index documents, not ever-changing data in a granularity that an E-Commerce application would need. Secondly, the load on the database is significant when we reindex all data every night.

We'd like a framework that has been designed for indexing database data, which can add to the index easily and without much load, which can supply data changes in the backoffice quickly to the frontend without much load and delay.

I'm aware of the fact that Xapian is Open Source and even Free Software, so we could adapt it to our needs if we decided to invest the time and manpower. But taking a quick look around for a solution more suited seems fair, right?

Oh, and commercial applications are fine, too. FOSS is not required.

答:
Have a look at elasticsearch. It is an Open Source (Apache 2), Distributed, RESTful, Search Engine built on top of Apache Lucene.

It's being used in production for big projects, and several advantages over other search solutions, especially with real-time indexing and scalability.

I'm sure there are libraries to use in python around.


答:
It really depends on what you're doing. If you're trying to understand wheels, it's a good idea to reinvent them yourself. If however you're trying to understand cars, reinventing wheel the wheel or internal combustion engines is generally wasteful and distracting.

So for example, when you're interested in understanding how a fulltext search index might work, it's a good idea to try to roll your own. If you're trying to build an application for document management, it's better to reuse an existing library, because most of your work is getting the application architecture and the user experience right all at the same time.


答:
Yes, it's appropriate to tell students not to reinvent the wheel.  But there needs to be a clear understanding of what it means for a student: write what is germane to the assignment.  It does not mean if the assignment is to write a bubblesort, you copy it off of Wikipedia, nor does it mean to use array.sort or equivalents if your framework or language provides it.  But after you have covered the various sorting algorithms, have written your own bubblesort and quicksort, don't bother rewriting it for each new assignment, use either the built in sorting or what you wrote, don't do the same old thing over again.

Reinventing the wheel is about not wasting time, which is just as applicable to students as it is to professionals -- the difference lies in what there goals are.  Students should be learning, so something that doesn't further their understanding, is a waste of time -- after you have written one bubblesort you know what it does, you know why you don't want to use it on a large set, and rewriting it again and again is a waste of time.  You aren't going to learn anything new on the 25th rewrite.

For students, it doesn't mean don't write what others have written, it means don't redo what you have already mastered -- that time that could be better spent on what you haven't mastered.


答:
To expand on Abhijit's point:

Support for Legacy Code: Millions of Lines of Code are running reliably for years and Business Houses find no compelling reason to rewrite it on Non-Mainframe Servers.

In my experience, this is a rather large issue for the kind of corporations who choose to run mainframes (which are typically rather large investments).  One project I was involved with was an investigation to answer a question:  what technologies should the client (a large bank) choose to replace mainframes with?  The question was actually split into smaller parts, focusing on the OS, the DB, and the implementation language(s) and frameworks.

Even just considering the language, we ran into a fairly major problem: rewriting the existing codebase was estimated to take around 5 years (without growing the development teams greatly, which would bring its own issues).  Obviously this is a major problem in terms of lost opportunity to spend that time developing other software, but beyond that, it's difficult to pick a technology with those kind of timelines in mind.  Java or .Net?  In a 5 year period, what is considered "good code" in either one of them is sorely outdated legacy stuff, with major versions of each coming out every couple of years.

Sitting back and thinking about this, the kind of stability that mainframes provide extends to the actual environment as well, things tend to change slowly; which is a good thing if you have a hundred million lines of code to maintain.

Title: What are the advantages of mainframes?


问:
What are the warning signs of impending doom to watch out for on a project?
Having worked on a failed project is one of the few things that most programmers have in common, regardless of language used, industry or experience.

These projects can be great learning experiences, soul-crushing disasters (or both!), and can occur for a multitude of reasons:

upper management change of heart

under-skilled / under-resourced team

emergence of superior competitor during dev cycle

over/under management

Once you've worked on a couple of such projects, is it possible to recognise at an early stage exactly when a project is doomed to fail?

For me, a big sign is having a hard & fast external deadline combined with feature creep. I've seen projects which were well planned out and proceeding right on schedule go horribly off the rails once the late feature requests started to roll in and get added to the final "deliverable". The proposers of these requests earned the nickname of Columbo, due to rarely leaving the room without asking for "just one more thing".

What are the warning signs you look out for that set off the alarm bells of impending doom in your head?

答:
When the programmers start to win the argument "The code is horrible, we need to start over from scratch." on any mature application.

You may think you can build it better, or understand the problem more fully, but you really don't. Oh, and all those ugly patches? They are fixes to real-world issues that you are going to likely re-introduce in the rewrite.

Plus, one day you are going to have to explain to the project manager why after 6 months of work you are almost up to 85% of the capability and 150% of the bugs the application had when you started out.


答:
To answer the I/O bandwidth part of your question.

This was definitely true up to about five years ago.

However mainframes and large server sites are now using basically the same disk technology under the covers. The mainframe still has a slight advantage with its "channel" architecture which offloads all the I/O activity onto separate processors. This is offset by a certain weirdness in that zOS stopped keeping up with disk technology twenty years ago so you allocate disks in terms of 3390 and 3330 volumes which are hardware devices made in the last century. Its analogous to UNIX still supporting vt100 protocol.

Plus it has a sort utility to die for. It sorts large files faster than most other systems can copy them.

Title: What are the advantages of mainframes?


答:
Lot of thoughts and effort has gone into creating a wheel. The advice is "not to reinvent the wheel" but you can go ahead and reverse engineer the wheel and understand why certain things are done in the way it is done. After this, you may try implementing the wheel in your own way which might result in either of the three logical ends.

You either understand why things are the way they are.

You might optimize it and make it better

You might screw it up and learn how not to do that thing.

To me student should not reinvent the wheel, but try to reverse engineer it & understand the implications.


答:
If you're willing to dabble in Flash, there is open-source Papervision3d. It would likely speed up development, but again, this means problems with mobile devices (iOS at least). There is something called Flash Media Server to counter that, but I can't vouch whether it  would work nicely in an interactive application.

In terms of support on multiple platforms, HTML5 canvas is likely your best bet. There are 3d libraries for it available, but I'm not familiar with them enough to offer a suggestion.

Title: What Technology can Render Medium Scale 3d Environments in a Web-Browser

Body:
I intend to make a web application that displays 3d environments that can be navigated by dragging(with a finger or mouse depending on the platform). The web app will render 3d environments of development sites including contours, water pipeline locations, buildings etc.

I am trying to decide what technology/libraries to use that will create a web-app that will work on Android-Web-Browser, iOS-Safari, IE9, Safari, Firefox and Chrome. And also what technology will provide speed in development. I understand that this is 'asking for my cake and eating it too'/'asking for the moon' but I don't know all the technologies out there - so there may be advanced libraries that can render 3d environments across many web-browsers including the main smart phone ones and I dont know of them.

The 3d rendering would not be highly detailed buildings or water with effects, but rather simple 3d representations of these objects. The environment would be navigable by dragging around and you could view the landscape in layers(view only contour lines, view only underground pipelines, view only sewerage pipes, etc.).

Are there any 3d libraries for web-browsers out there? Is there a way to run OpenGL(or OpenGL ES) through a webbrowser?

What technology would you use if you were making this kind of app/web app that should work on desktop Windows, Android, iOS and WindowsPhone?

Is there any technology I have failed to mention that would be good for this kind of project?

I am tending towards a Browser Driven Web App because I get that cross platform ability(where it even works on linux and MacOS by using compatible web-browsers). Also I know of CSS3 transforms that can create cubes that can rotate in 3d space(NOTE only works for WebKit browsers - so no IE :( ). But I don't know if CSS3 is robust enough to render whole 3d environments? Do you think it could? Maybe I could use HTML5 canvas's for this? Can Google maps create custom 3d maps?


答:
Your best bet is probably a Java applet (or possibly Java Webstart). Java has Java3D for rendering 3D, and it can even use HW acceleration. Disadvantage is that you need a (current) Java plugin, but there are currently no solutions without a plugin.

Longer term, HTML5 + WebGL is probably your best bet, but especially WebGL is still in Alpha and not really ready for production.


答:
Mainframe system have many interesting advantages:

Can be used for complete on-line and batch applications using easily scalable software configurations. You can add 100s of users with almost no change to your software. However, their native interface is limited but can be replaced with GUI front ends.

Can be perfect for back-end SOA based computing environment because of their huge resources and ability to process information.

Software is built using tested and well understood technologies. The core technology concepts have been established and well documented long time ago, developers need to focus on the end user requirements and the business rules not on learning the flavor-of-the day fads.

Systems can be built form simpler components that a typical non-mainframe system. The software architecture in mainframe has few components and technologies and does not involve complex component structure like your typical web applications.

Mainframes can handle the processing of massive data volumes processing without having to resort to parallel programming techniques (which are complex to code).

Mainframes are best when it comes for business continuity aspects since there can't be attacked by viruses and backups of millions of transactions can be performed in minutes. Also, you could replicate the business environment on the same machine or on a different machine and restore the system quickly.

Mainframe have 100s times of storage and CPU power compared to a PC-type server.

Hardware vendor is usually the maker of the core software elements and the software is designed specifically to take full advantage of the hardware.

Title: What are the advantages of mainframes?


问:
Lone Programmer vs. Everything Else
I guess you could call me a "MicroISV" because it's basically just me doing the work to create a product to be sold commercially. I'm sure there are many out there like me, so here's my question:

Besides the programming/coding aspect to get your code out the door, do you DIY or vendor-out everything else? For example, web site creation, internet marketing, accounting/taxes, company minutes, customer support, setting up ecommerce/banking, server management, procurement, etc.

All of those activities seem to be out of the realm of what I'm good at or have the patience/time for, but I don't know if the alternative is too untrustworthy or too expensive to make it worthwhile to try to farm out these tasks to someone else (like a local company, vendors on oDesk, etc.).

I can certainly understand wanting to keep all these tasks "in-house" (i.e. me) to protect strategy, plans, code, private things like bank account numbers, but is it really that much of a risk to outsource these tasks? What is your experience?

答:
I think that rather sooner that later you are going to need an organization to back your product, because an important part of a software's value comes from the ability to support your users and evolve the software from your user's requirements.

At some point you are not going to have enough time do this all by yourself.

You can outsource most of the administrative tasks but upgrading your software and supporting your users (the core of your business) are key to success, so you are going to need a team (could be just two or three people).

Building a team usually takes some time, so my suggestion is to start finding people that work with you in the technical aspects of your product, so eventually you can let them handle those and you start MANAGING the team.

It looks like you are the technical kind of guy, so you need to a) start developing you management skills or b) get someone you know and trust, that has those skills, to become your business partner.

Developing a product by yourself is a completely different game from having a team work together towards that goal, management is key for the latter.

Running a business is a team work beacause it's impossible (IMHO) that one single person can efficiently handle all aspects, specially those regarding strategy, marketing, product development and user support.

So IMHO:

Develop a team for working out strategy, marketing, product development and user support, and

Outsource everything else

Title: Lone Programmer vs. Everything Else


答:
Being a teacher or programming, I constantly battle with the opposite side of the problem: when do I ask students to reinvent the wheel?

Take these simple situations: we're studying sorting algorithm, and I set tasks to write a program that sorts some data; or working on date functionality, and I ask for a calendar.

For both of these, there are countless ready-made libraries and functionality available; but I want the students to avoid them, and develop their own version of a sorting algorithm or of a calendar.

Now take this other one: I set a task to write a simple application for, say, scheduling appointments. This is likely to need sorting, and a calendar, and more. This time "don't reinvent the wheel" applies: I don't want students to struggle with solved problems, but instead assemble existing functionality to obtain a result.

My difficulty is, how much to ask you to recreate the existing, which does get you to learn, and has the advantage of well-trodden problems with know difficulties that I can use to make you practice the craft, and how much I should place you in a real-world setting, where wheels are not reinvented?

To answer your question more directly, two suggestions:

if a teacher tells you to "not reinvent the wheel", they probably say so because they have designed their problem that way. Maybe they want you to try a library, struggle with someone else's implementation of an algorithm, rather than write your own - there's learning in that too, and recreating is interesting but misses the point.

if you have too many exercises assembling library calls, rather than developing algorithms, you could raise with your teachers the question of balance between these activities - highlight you've never been asked to write your own algorithms for, e.g. sort and merge. Communication will never go amiss.


问:
Where and how to mention Stackoverflow participation in the résumé?
I think I have good enough reputation on SO now. Well, this may not be that much as compared to so many other users out there but I am happy with mine.

So, I was thinking of adding my profile link on my résumé - just the profile link and not that "I have this much reputation on SO". Those who haven't seen, can see this question Would you put your Stack Overflow profile link on your CV / Resume?

How would this look like?

Forums/Blogs/Miscellaneous others

No blogging as yet but active
  participant in Stackoverflow. My
  profile link -
  http://stackoverflow.com/users/userId/username

I think of putting this section after Project Details and Technical Expertise sections. Any tips/advice?

Update

MKO has made a very good point -

do you really want a potential
  employer to be able to evaluate in
  detail everything you've ever written
  on SO

I thought of commenting but it would be too long -

 In my questions/answers I put a lot of statements like - "AFAIK ...", "following are my assumptions so far ...", "am I correct to conclude that... ?", "I doubt if it is possible to ..." etc. when I am not sure about something and I rarely involve in fights with other users. However I do argue on topics sometimes if I feel it is necessary and if I have a valid point. I do accept my mistakes and apologize for the same. As we all know nobody is perfect. I must have written many things which may be judged as wrong by a potential employer. But what if the same employer notices that I have improved in the quality of content by comparing old content with new one? Isn't that great?

I also try to go back to older questions/answers and put corrective comments etc. when I feel I was wrong or if I can improve my post.

Of course there are many employers who want you (potential employees) to be correct each and every time. They immediately remove you from consideration when you say a single incorrect thing. I have personally met such an interviewer few months back. He didn't even care to listen to any good thing I had done after he found a single wrong thing.

Now the question is do you really care to work with such people? Or do you like those people who give value to the fact that you are striving to improve every day. I personally prefer the latter.

答:
Base it on the feedback you are getting on your resume. The less job experience you have, the more you may need to rely on: blogs, SO activity, code posting sites, open source contributions, certifications, publications, etc.

Arrange it under a section that makes sense like: Other Activities, Professional Contributions.

SO sites are more likely going to help you indirectly in finding a job. You get to practice communicating in a technical environment. It's a tool to find solutions to problems. There should be enough general information on best practices.

Carpenters don't get hired because they carry hammers; it's because they know how to swing it.