答:
Count me in with the Smalltalk crowd.

However, another thing that'd be useful to teach is that there are more ways than one to skin the OOP horse.  For instance, I've found that a lot of people used to the C++/Java branch of the OOP family tree have a lot of trouble wrapping their heads around how R's S4 class system (itself based on the OOP system of Dylan) works.

I'm a firm believer in the notion that learning a wide range of programming language paradigms is helpful for being able to quickly pick up new technologies in the future, and being exposed to how multiple languages handle OOP concepts can only help.

Maybe the ideal way would be to speak in pure concepts first and then show how different languages implement (or not) those concepts.


问:
Where does form processing belong in an MVC application?
I found  this question on stack overflow and I have a question about one of the answers:

In Zend Framework, forms are typically objects with decorators, but usually (I thought) processing is done using a combination of controllers and models, with the main objective to keep the controller as lightweight as possible, and each object responsible for its own state.

One of the answers said to use the form object itself as the place to encapsulate the form processing members. Is that a good practice?

For some reason that seems awkward to me. But it also seems awkward to do most of the work in either the database abstraction layer (Zend_Db_Table/Row) or the controller. Where is the best place to encapsulate form processing? Should you create separate classes for the form itself and another class for processing the form (which then deals with the DBAL)?

Edit: here is another SO post that asks a similar question, but the OP doesn't get a complete answer.

We want to know: where does each part of the form processing logic belong?

答:
Validation logic belongs in the database, the domain model, and possibly
the view model.

I think most frameworks have Model decorators/attributes to define validation and View helpers to render the View from the Model, including client-side validation shininess. So try to let the framework do all that work for you and focus on the Model.

Business logic belongs both in the Model (domain-dependent logic)
and the Controller (service-dependent logic).

I tend to weight as much logic as I can in domain Model to keep the
Controller light, as you say. But I generally prefer not to inject service
dependencies in my domain layer, so some of that logic has to
happen in the Controller.

ContentLicense: CC BY-SA 3.0


问:
Are there standard strategies for defining job flow and dependencies?
I'm working on a project that involves the chaining of separate jobs into a single master job, though there may be parallel paths in the chain leading up to the final output. Job and chain details will be stored in a database. Eventually what I want to end up with is a GUI in which blocks representing the individual jobs can be moved around and chained up, with the system definition stored in the DB for execution. This will be implemented as C# on top of SQL Server.

I don't want to reinvent the wheel if I can help it. I'm certain there must be some good patterns out there, particularly for how to represent the flow and dependencies in DB tables, but have been unable to find anything that fits the bill.

More than anything, I'm curious if there are any effective schemas people have used to define the jobs, dependencies, etc. Does anyone know of any commonly used strategies?

答: Have you by any chanche got a sql server version that supports integration services? That is a great toolboox for organizing a workflow of jobs just as you describe. For referfence please check: http://msdn.microsoft.com/en-us/library/ms141026.aspx</p>


问:
What language should be used to teach object-oriented design and development in university?
My understanding is that C++ is usually offered as the 1st OOP language, and as the 2nd programming language (after C) in my country (Bangladesh). I've taught it several times, and the problem I've run into is that students often tend to think C++ as an extension of C, i.e. C with cin and cout!
This has lead me to think about teaching Java as the first OOP language in the upcoming semester.

What is your opinion? I would like some suggestions from professional programmers as well as academics.

答:
Do not teach Java. The problem with Java is that all you can learn from it is that inheritance is a hammer and absolutely every problem is a nail. Also, the terminology of Java heavily confuses topics like object orientation and memory management- not what you want to teach poor students who'd be lucky to grok either of those things taught independently.

You want to teach OOP. Not "Objects are our Gods. Inheritance shall be our divine weapon against all programming problems. We shall not question the Garbage Collection algorithm and explore other forms of managing memory. Primitives shall be looked down upon by all. We shall exist purely within the Sacred Laws of the Virtual Machine."

The fact that your students see C++ as "C with cout" is a failure of teaching C first and then not properly upgrading to C++. The usual remedy is just to not teach C at all, as it's really quite redundant to do so and very damaging. Or you could just hire smarter teachers. But that's not very viable because it's really hard to solve this problem after it's been created.

C++ makes a great OOP language because C++ doesn't confuse object orientation with memory management, and it allows you to properly weigh a paradigm when you can use it's alternatives as well if you'd like. How can you learn when not to use OOP if that's all the language offers?


问:
Get 100 highest numbers from an infinite list
One of my friend was asked this interview question -

"There is a constant flow of numbers coming in from some infinite list
  of numbers out of which you need to maintain a datastructure as to
  return the top 100 highest numbers at any given point of time. Assume all the numbers are whole numbers only."

This is simple, you need to keep a sorted list in descending order and keep a track on lowest number in that list. If new number obtained is greater than that lowest number then you have to remove that lowest number and insert the new number in sorted list as required.

Then question was extended -

"Can you make sure that the Order for insertion should be O(1)? Is it possible?"

As far as I knew, even if you add a new number to list and sort it again using any sort algorithm, it would by best be O(logn) for quicksort (I think). So my friend told it was not possible. But he was not convinced, he asked to maintain any other data structure rather than a list.

I thought of balanced Binary tree, but even there you will not get the insertion with order of 1. So the same question I have too now. Wanted to know if there is any such data structure which can do insertion in Order of 1 for above problem or it is not possible at all.

答:
The task is clearly to find an algorithm that is O(1) in the length N of the required list of numbers.
So it doesn't matter if you need the top 100 number or 10000 numbers, the insertion time should be O(1).

The trick here is that although that O(1) requirement is mentioned for the list insert, the question didn't say anything about the order of search time in the whole number space, but it turns out this can be made O(1) as well.
The solution then is as follows:

Arrange for a hashtable with numbers for keys and pairs of linked list pointers for values. Each pair of pointers is the start and end of a linked list sequence. This will normally just be one element then the next. Every element in the linked list goes next to the element with the next highest number. The linked list thus contains the sorted sequence of required numbers.Keep a record of the lowest number.

Take a new number x from the random stream.

Is it higher than the last recorded lowest number? Yes => Step 4, No => Step 2

Hit the hash table with the number just taken. Is there an entry? Yes => Step 5. No => Take a new number x-1 and repeat this step
(this is a simple downward linear search, just bear with me here, this can be improved and I'll explain how)

With the list element just obtained from the hash table, insert the new number just after the element in the linked list (and update the hash)

Take the lowest number l recorded (and remove it from the hash/list).

Hit the hash table with the number just taken. Is there an entry? Yes => Step 8. No => Take a new number l+1 and repeat this step
(this is a simple upward linear search)

With a positive hit the number becomes the new lowest number. Go to step 2

To allow for duplicate values the hash actually needs to maintain the start and end of the linked list sequence of elements that are duplicates. Adding or removing an element at a given key thus increases or decreases the range pointed to.

The insert here is O(1). The searches mentioned are, I guess something like, O(average difference between numbers). The average difference increases with the size of the number space, but decreases with the required length of the list of numbers.

So the linear search strategy is pretty poor, if the number space is large (e.g. for a 4 byte int type, 0 to 2^32-1) and N=100. To get around this performance issue you can keep parallel sets of hashtables, where the numbers are rounded to higher magnitudes (e.g. 1s, 10s, 100s, 1000s) to make suitable keys. In this way you can step up and down gears to perform the required searches more quickly. The performance then becomes an O(log numberrange), I think, which is constant, i.e. O(1) also.

To make this clearer, imagine that you have the number 197 to hand. You hit the 10s hash table, with '190', it's rounded to the nearest ten. Anything? No. So you go down in 10s until you hit say 120. Then you can start at 129 in the 1s hashtable, then try 128, 127 until you hit something. You've now found where in the linked list to insert the number 197. Whilst putting it in, you must also update the 1s hashtable with the 197 entry, the 10s hashtable with the number 190, 100s with 100, etc. The most steps you ever have to do here are 10 times the log of the number range.

I might have got some of the details wrong, but since this is the programmers exchange, and the context was interviews I would hope the above is a convincing enough answer for that situation.

EDIT I added some extra detail here to explain the parallel hashtable scheme and how it means the poor linear searches I mentioned can be replaced with an O(1) search. I've also realised there is of course no need to search for the next lowest number, because you can step straight to it by looking in the hashtable with the lowest number and progressing to the next element.

OwnerDisplayName: Sachin Shanbhag


问:
Domain model for education
Are there any domain models already created for education industry? For example we have Prima IBCS for insurance. I was looking for something along similar lines.</p>

答: A instructor at San Jose State University has a partial example of a domain model for education. There's the National Education Data Model that covers similar ground. The now defunct "E-Len" Project might be of use. Some more focus in regards to what problem you are trying to solve would be useful to better answer your question. The resources listed are links from the first two pages of a Google search.</p>

Title: Domain model for education


问:
Is it an appropriate use of #define to make typing repeated code easier?
Is there any view on whether using the #define to define full lines of code for simplifying coding is good or bad programming practice? For example, if I needed to print a bunch of words together, I'd get annoyed typing

```<code><< " " <<
</code>```

To insert a space between words in a cout statement. I could just do

```<code>#define pSpace << " " <<
</code>```

and type

```<code>cout << word1 pSpace word2 << endl;
</code>```

To me this neither adds or subtracts from the clarity of the code and makes typing slightly easier. There are other cases that I can think of where typing will be much easier, usually for debugging.

Any thoughts on this?

EDIT: Thanks for all the great answers! This question just came to me after doing a lot of repetitive typing, but I never thought there would be other, less confusing macros to use. For those who don't want to read all the answers, the best alternative is to use the macros of your IDE to reduce repetitive typing.

答:
Is there any view on whether using the #define to define full lines of
  code for simplifying coding is good or bad programming practice?

Yes, it is very bad. I have even saw people doing this :

```<code>#define R return
</code>```

to save typing (what you are trying to achieve).

Such code belongs only in places like this.

Body:
Is there any view on whether using the #define to define full lines of
  code for simplifying coding is good or bad programming practice?

Yes, it is very bad. I have even saw people doing this :

#define R return

to save typing (what you are trying to achieve).

Such code belongs only in places like this.


问:
Does F# offer anything particularly useful for database-driven web development?
My organization finally upgraded to MS Visual Studio 2010 this year.  One of the big new features that Visual Studio 2010 offers is the F# programming language.

I understand that F# offers a functional programming paradigm, similar to Lisp.  Unlike Lisp though, F# is compiled into managed code for the .net framework.

Right now, I work in database-driven web application development.  Right now, I'm working with an n-tier application with SQL code on the back end and a C#.net AJAX web application on the front-end.  I would like to know if F# offers anything that would be particularly useful for this type of development.

答:
F# doesn't really do anything that C# cant. They all ultimately compile down to the same CLR so there is no single technology that would be amazingly useful to you. You can even call F# from C# and vice versa.

Depending on the problems your designing F# could provide simpler and more concise code.

Functional languages also lend themselves very well to unit testing. That and that fact that there is much less mutable data means your code if written well will have much less bugs.

I can say from personal experience learning some F# can really improve your C# skills and help you think of problems in a new way.

Learning functional programming concepts can also really help your Javascript (which is itself a functional language).


答:
In C++ this can be solved with operator overloading. Or even something as simple as a variadic function:

lineWithSpaces(word1, word2, word3, ..., wordn) is both simple and saves you typing pSpaces again and again.

So while in your case it might not seem like a big deal, there's a solution that is simpler and more robust.

In general, there's few cases where using a macro is significantly shorter without introducing obfuscation, and mostly there's a sufficiently short solution using actual language features (macros being more of a mere string substitution).

Title: Is it an appropriate use of #define to make typing repeated code easier?

Body:
Is there any view on whether using the #define to define full lines of code for simplifying coding is good or bad programming practice? For example, if I needed to print a bunch of words together, I'd get annoyed typing

```<code><< " " <<
</code>```

To insert a space between words in a cout statement. I could just do

```<code>#define pSpace << " " <<
</code>```

and type

```<code>cout << word1 pSpace word2 << endl;
</code>```

To me this neither adds or subtracts from the clarity of the code and makes typing slightly easier. There are other cases that I can think of where typing will be much easier, usually for debugging.

Any thoughts on this?

EDIT: Thanks for all the great answers! This question just came to me after doing a lot of repetitive typing, but I never thought there would be other, less confusing macros to use. For those who don't want to read all the answers, the best alternative is to use the macros of your IDE to reduce repetitive typing.


问:
What task did Dijkstra give volunteers, which was mentioned in his paper "The Humble Programmer"?
In Dijkstra's paper "Humble Programmer", he mentions that he gave some volunteers a problem to solve:

“I have run a little programming experiment with really experienced volunteers, but something quite unintended and quite unexpected turned up. None of my volunteers found the obvious and most elegant solution. Upon closer analysis this turned out to have a common source: their notion of repetition was so tightly connected to the idea of an associated controlled variable to be stepped up, that they were mentally blocked from seeing the obvious. Their solutions were less efficient, needlessly hard to understand, and it took them a very long time to find them.”

What was the problem Dijkstra gave to the volunteers? What were the solutions?

答:
The "Dining philosophers problem" was the problem presented.

Basically there are 5 philosophers that need to eat. (imagine a plate of never ending food in front of each philosopher), between each plate is a fork (5 plates, 5 forks, 5 philosophers).

A philosopher can only eat if he is holding both the fork to the right and the fork to the left. (only two philosophers can eat at any given time).

A fork may be picked up anytime it is available and put down if it is being held.
  Each fork must be picked up interdependently. (one at a time).

While a philosopher is not eating, they are thinking (the need to alternate states is what drives the problem).

How do you allow each of them to eat and alternate thinking (so the others can eat) without creating a deadlocked system (where one philosopher is holding one fork and waiting for the other, preventing another philosopher from eating).

This has its roots in concurrent systems and is a typical university question presented when discussing Concurrency.

I believe that 4 or 5 "official" algorithms have been developed to solve the problem but a quick search on google for "Dining philosophers problem" will get you a vareity of results.

For details on this problem from Standford U please visit: http://academicearth.org/lectures/dining-philosopher-problem

The wikipedia article is located at: http://en.wikipedia.org/wiki/Dining_philosophers_problem

A Solution from MSDN Magizine is located at: http://msdn.microsoft.com/en-us/magazine/dd882512.aspx

If you read the original version of the paper in the footnotes on page 866 it states: "Proceedings of the IFIP Congress 1965, 213-217. " Solutions of a problem in concurrent programming control."

The problem in concurrency and shared resources is the "Dining Philosophers Problem".  :-)

Hope that helps.


答: This is easy. The size of the list of constant, therefore the sort time of the list is constant. A operation that executes in constant time is said to be O(1). Therefore sorting the list is O(1) for a list of fixed size.</p>

Title: Get 100 highest numbers from an infinite list

Body:
One of my friend was asked this interview question -

"There is a constant flow of numbers coming in from some infinite list
  of numbers out of which you need to maintain a datastructure as to
  return the top 100 highest numbers at any given point of time. Assume all the numbers are whole numbers only."

This is simple, you need to keep a sorted list in descending order and keep a track on lowest number in that list. If new number obtained is greater than that lowest number then you have to remove that lowest number and insert the new number in sorted list as required.

Then question was extended -

"Can you make sure that the Order for insertion should be O(1)? Is it possible?"

As far as I knew, even if you add a new number to list and sort it again using any sort algorithm, it would by best be O(logn) for quicksort (I think). So my friend told it was not possible. But he was not convinced, he asked to maintain any other data structure rather than a list.

I thought of balanced Binary tree, but even there you will not get the insertion with order of 1. So the same question I have too now. Wanted to know if there is any such data structure which can do insertion in Order of 1 for above problem or it is not possible at all.


答:
Can we assume that the numbers are of a fixed data type, such as Integer?  If so, then keep a tally of every single number that is added.  This is an O(1) operation.

Declare an array with as many elements as there are possible numbers:

Read each number as it is streamed.

Tally the number.  Ignore it if that number has been tallied 100 times already as you'll never need it.  This prevents overflows from tallying it an infinite number of times.

Repeat from step 2.

VB.Net code:

```<code>Const Capacity As Integer = 100

Dim Tally(Integer.MaxValue) As Integer ' Assume all elements = 0
Do
    Value = ReadValue()
    If Tally(Value) < Capacity Then Tally(Value) += 1
Loop
</code>```

When you return the list, you can take as long as you like.  Simply itterate from the end of the list and create a new list of the highest 100 values recorded.  This is an O(n) operation, but that's irrelivant.

```<code>Dim List(Capacity) As Integer
Dim ListCount As Integer = 0
Dim Value As Integer = Tally.Length - 1
Dim ValueCount As Integer = 0
Do Until ListCount = List.Length OrElse Value < 0
    If Tally(Value) > ValueCount Then
        List(ListCount) = Value
        ValueCount += 1
        ListCount += 1
    Else
        Value -= 1
        ValueCount = 0
    End If
Loop
Return List
</code>```

Edit: In fact, it doesn't really matter if it's a fixed data type.  Given there's no imposed limits on memory (or hard disk) consumption, you could make this work for any range of positive integers.

Body:
Can we assume that the numbers are of a fixed data type, such as Integer?  If so, then keep a tally of every single number that is added.  This is an O(1) operation.

Declare an array with as many elements as there are possible numbers:

Read each number as it is streamed.

Tally the number.  Ignore it if that number has been tallied 100 times already as you'll never need it.  This prevents overflows from tallying it an infinite number of times.

Repeat from step 2.

VB.Net code:

Const Capacity As Integer = 100

Dim Tally(Integer.MaxValue) As Integer ' Assume all elements = 0
Do
    Value = ReadValue()
    If Tally(Value) < Capacity Then Tally(Value) += 1
Loop

When you return the list, you can take as long as you like.  Simply itterate from the end of the list and create a new list of the highest 100 values recorded.  This is an O(n) operation, but that's irrelivant.

Dim List(Capacity) As Integer
Dim ListCount As Integer = 0
Dim Value As Integer = Tally.Length - 1
Dim ValueCount As Integer = 0
Do Until ListCount = List.Length OrElse Value < 0
    If Tally(Value) > ValueCount Then
        List(ListCount) = Value
        ValueCount += 1
        ListCount += 1
    Else
        Value -= 1
        ValueCount = 0
    End If
Loop
Return List

Edit: In fact, it doesn't really matter if it's a fixed data type.  Given there's no imposed limits on memory (or hard disk) consumption, you could make this work for any range of positive integers.


问:
Purpose of ending tags in SGML/HTML/XML?
There are those tags which have immediate effect (
) and those which affect what is between them (   ).

Closing tag is verbose, and I believe also redundant:

```<code><tag parameters> ... </tag>
</code>```

verbose

Compare to LISP's s-expresions.

```<code>(tag parameters)
</code>```

redundant

Ending tags are not even necessary. These language are context-free and this is not possible there:

```<code><tag1> <tag2> </tag1> </tag2>
</code>```

Basically these should be equivalent:

```<code><tag1> <tag2> </> </>
<tag1> <tag2> </tag2> </tag1>
</code>```

questions

Are ending tags there to aid readability? What is purpose of redundancy in closing tags? I want to understand inside the logic behind desing of this. Thanks. :)

答:
Yes, ending tags are there to aid readability and clarity in case of error.  If a document is malformed and missing an end-tag, how would the developer be sure which tag is missing?

Also, I suspect that having the name in the end-tag aids in SAX-type parsing, allowing the parser to easily identify the type of node that is being ended.


问:
Is object oriented really good for kids?
I read, that Smalltalk was designed for kids or for education. So was it good at it? Better than the other languages? Was it good/easy also for average kid (I read that bright kids enjoyed). Is there any study to back it up? Or is Your experience it is good?</p>

答:
Smalltalk does not seem to be easier to learn or use than any modern language.

May be for the time it has been designed in the 70s... compared to LISP, yes.

Programming has little to do with the used language constructs, and much more to do with concepts like loops, functions, recursion etc.

Object Oriented programs might mach better real-world objects, but this is misleading, as good OO design introduces its own set of design problems.

Any revolutionary feature of an older language compared to a modern one, is either expected to be present, or already discredited.

To finish with an anecdote: While I was little (as English is not my first language), my friends thought 'If you learn English, you've already almost learned to program'. Even then I knew they are so far from the truth.

Fifteen years later, I am fluent in English. Still learning programming, and enjoying it.


问:
How to make security usable in a web application?
I'm in the planning stages of developing a web application that I want to make as secure as possible. I'm pretty clear about how to do that from a technical point of view, but there is one massive potential security hole: I want the site to have users.

As anyone who has ever been a user knows, users forget usernames, forget passwords, sometimes forget that they even had an account with your site. Users respond to phishing emails and give away their credentials. If you do anything that they find too complicated they won't use your site, it has to be simple and all happen in as few clicks as possible, but we have to balance that out by making it as hard as possible for users to accidentally give away their credentials and to keep access to the service as secure as possible.

What I'm particularly interested in are strategies that go beyond the standard username and password combination and ways of recovering or resetting passwords that make things easy for users but hard for anyone trying to steal their account. I know a lot of sites provide an extra user-set security question, but because I don't trust users not to create a stupid question like "what is 1+1" I don't see how this can guarantee security.

Are there strategies that could be useable to the most clueless user but challenging to a determined and targetted attack aiming to break into their account? If not what are the closest things we could get? As a user what are the best/worst sites for this you have encountered and why?

答:
To the OP: Use standard approaches to security on web sites. There will inevitably be moron users that will drown and walk away from your secure site, but that's the nature of the beast. You want security, you'll have to sacrifice some flexibility (and again, there are known practices on security that have worked well from a user-friendly point of view.)

Besides, when a user walks away, it is usually for things other than security (shitty web design, confusing navigation, poor performance, unreliability, etc.) Obtrusive security is usually the result of a poor architecture, and not of security itself. Keep that in mind.

ContentLicense: CC BY-SA 2.5


答:
Silly user, Trix are for kids, not advanced concepts like OO programming and design.  :)

Any language that focuses on starting small, being simple, easy to start a project on, and gives instant results is a good language for kids to start with.  That language for me was pre .NET Visual Basic.  It was easy for me to draw forms, throw pictures up, easily write simple conditional logic within events and being able to press the Play button to see my masterpiece come to life before my eyes.  As a kid writing my own video games was a bragging right and got me passionate enough to pursue this as a career. (now that I have an actual successful career the joy I once held for software development has been brutally mutilated by the reality of the business world).

Introduce kids to visual programming languages that teach them basic concepts while keeping things fun and interesting.  Scratch looks like a promising project.  http://scratch.mit.edu/

Otherwise if you have time and money look into Mindstorms, it is a robotics programming kit offered by Lego.  Simple programming concepts can easily be taught by writing custom programs from custom built robots.  http://mindstorms.lego.com/en-gb/history/default.aspx

Title: Is object oriented really good for kids?

Body: I read, that Smalltalk was designed for kids or for education. So was it good at it? Better than the other languages? Was it good/easy also for average kid (I read that bright kids enjoyed). Is there any study to back it up? Or is Your experience it is good?</p>


答:
In your question title, you ask about HTML, SGML and XML as if they are the same thing, but they are not. In fact, they are very different in precisely that area which you are asking about.

In particular, SGML has both Null End Tags and Implied End Tags (and Implied Elements as well), and since HTML is an application of SGML, it inherits those.

Null End Tags allow you to leave out the name of the End Tag. Instead of

```<code><tag>content</tag>
</code>```

You can also write

```<code><tag/content/
</code>```

Implied End Tags allow you to leave out the End Tag altogether, if it is clear from the context that there must be an End Tag. For example, in HTML, a body element cannot be inside a title or head element, therefore you can write

```<code><html>
  <head>
    <title>The Title
  <body>
</code>```

and both the title and head elements will be implicitly closed.

End Tags are also implied at the end of the document: all elements will be closed in reverse order.

With Implied Elements, you can leave out both Start and End Tags: since p is only allowed within body, the first p will imply a body:

```<code><html>
  <head>
    <title>The Title
    <p>
</code>```

Here, there is a body element in the document, even though there are no body tags.

Putting it all together, you get something like this:

```<code><HTML /
  <HEAD /
    <TITLE / > /
    <P / >
</code>```

This is a complete, 100% well-formed, 100% valid HTML document. (Well, it's missing the DOCTYPE declaration, but if you add one, you can run it through the W3C validator as HTML 1.0, 2.0, 3.2 and 4.01, even as Strict.)

It is semantically equivalent to the following XHTML:

```<code><html>
  <head>
    <title>
      >
    </title>
  </head>
  <body>
    <p>
      >
    </p>
  </body>
</html>
</code>```

Now, which one of the two is easier to read?
(Actually, that's a serious question. I'm particularly interested in what seasoned Lisp programmers have to say.)

Title: Purpose of ending tags in SGML/HTML/XML?

Body:
There are those tags which have immediate effect (
) and those which affect what is between them (   ).

Closing tag is verbose, and I believe also redundant:

```<code><tag parameters> ... </tag>
</code>```

verbose

Compare to LISP's s-expresions.

```<code>(tag parameters)
</code>```

redundant

Ending tags are not even necessary. These language are context-free and this is not possible there:

```<code><tag1> <tag2> </tag1> </tag2>
</code>```

Basically these should be equivalent:

```<code><tag1> <tag2> </> </>
<tag1> <tag2> </tag2> </tag1>
</code>```

questions

Are ending tags there to aid readability? What is purpose of redundancy in closing tags? I want to understand inside the logic behind desing of this. Thanks. :)

Body:
In your question title, you ask about HTML, SGML and XML as if they are the same thing, but they are not. In fact, they are very different in precisely that area which you are asking about.

In particular, SGML has both Null End Tags and Implied End Tags (and Implied Elements as well), and since HTML is an application of SGML, it inherits those.

Null End Tags allow you to leave out the name of the End Tag. Instead of

<tag>content</tag>

You can also write

<tag/content/

Implied End Tags allow you to leave out the End Tag altogether, if it is clear from the context that there must be an End Tag. For example, in HTML, a body element cannot be inside a title or head element, therefore you can write

<html>
  <head>
    <title>The Title
  <body>

and both the title and head elements will be implicitly closed.

End Tags are also implied at the end of the document: all elements will be closed in reverse order.

With Implied Elements, you can leave out both Start and End Tags: since p is only allowed within body, the first p will imply a body:

<html>
  <head>
    <title>The Title
    <p>

Here, there is a body element in the document, even though there are no body tags.

Putting it all together, you get something like this:

<HTML /
  <HEAD /
    <TITLE / > /
    <P / >

This is a complete, 100% well-formed, 100% valid HTML document. (Well, it's missing the DOCTYPE declaration, but if you add one, you can run it through the W3C validator as HTML 1.0, 2.0, 3.2 and 4.01, even as Strict.)

It is semantically equivalent to the following XHTML:

<html>
  <head>
    <title>
      &gt;
    </title>
  </head>
  <body>
    <p>
      &gt;
    </p>
  </body>
</html>

Now, which one of the two is easier to read?
(Actually, that's a serious question. I'm particularly interested in what seasoned Lisp programmers have to say.)


问:
What is the/Is there a right way to tell management that our code sucks?
Our code is bad. It might not have always been considered bad, but it is bad and is only going downhill. I started fresh out of college less than a year ago, and many of the things in our code puzzle me beyond belief. At first I figured that as the new guy I should keep my mouth shut until I learned a little more about our code base, but I've seen plenty to know that it's bad.

Some of the highlights:

We still use frames (try getting something out of a querystring, almost impossible)

VBScript

Source Safe

We 'use' .NET - by that I mean we have .net wrappers that call COM DLLs making it almost impossible to debug easily

Everything is basically one giant function

Code is not maintainable. Each page has multiple files that are created every time a new page is made. The main page basically does Response.Write() a bunch of times to render the HTML (runat="server"? no way). After that there can be a lot of logic on the client side (VBScript), and finally the page submits to itself (often time storing many things in hidden fields) where it then posts to a processing page which can do things such as save the data to the database.

The specifications we get are laughable. Often times they call for things like "auto-populate field X with either field Y or field Z" with no indication of when to choose field Y or field Z.

I'm sure some of this is a result of not being employed at a software company, but I feel as if people writing software should at least care about the quality of their code. I can't even imagine that if I were to bring something up that anything would be done soon, as there is a large deadline looming, but we are continuing to write bad code and use bad practices.

What can I do? How do I even bring these issues up? 75% of my team agree with me and have brought up these issues in the past, yet nothing gets changed.

答:
Start reading Joel on Software (Joel Spolsky / Founder of Stack Exchange) ...

The FIRST thing I would do is perform a Joel Test.

This will allow you to present it as "While I was looking for ways to improve as a developer... I stumbled onto this 12 question test about development environments, so for fun I answered them about where I work." ... This in turn makes it a 3rd party outlining whats wrong with your code and not you personally.

As you read more on Pragmatic Practices you will be improving yourself and implementing things like red / green / refactor and this in turn will allow you to clean up the code base so that is becomes maintainable. (over time)

Hope that helps!
Welcome to Programming (yesterdays code usually sucks) ;-)

OwnerDisplayName: Azkar


答:
"Hey Boss, after Big Project me and the team would like some time, ideally X months, to organize our code. Things that should be able to be done in minutes take hours because it is all very disorganized. If it's not possible to do it right after Big Project, we would like to plan a realistic schedule."

(partially paraphrased from Azkar's comment on the question)

Title: What is the/Is there a right way to tell management that our code sucks?

Body:
Our code is bad. It might not have always been considered bad, but it is bad and is only going downhill. I started fresh out of college less than a year ago, and many of the things in our code puzzle me beyond belief. At first I figured that as the new guy I should keep my mouth shut until I learned a little more about our code base, but I've seen plenty to know that it's bad.

Some of the highlights:

We still use frames (try getting something out of a querystring, almost impossible)

VBScript

Source Safe

We 'use' .NET - by that I mean we have .net wrappers that call COM DLLs making it almost impossible to debug easily

Everything is basically one giant function

Code is not maintainable. Each page has multiple files that are created every time a new page is made. The main page basically does Response.Write() a bunch of times to render the HTML (runat="server"? no way). After that there can be a lot of logic on the client side (VBScript), and finally the page submits to itself (often time storing many things in hidden fields) where it then posts to a processing page which can do things such as save the data to the database.

The specifications we get are laughable. Often times they call for things like "auto-populate field X with either field Y or field Z" with no indication of when to choose field Y or field Z.

I'm sure some of this is a result of not being employed at a software company, but I feel as if people writing software should at least care about the quality of their code. I can't even imagine that if I were to bring something up that anything would be done soon, as there is a large deadline looming, but we are continuing to write bad code and use bad practices.

What can I do? How do I even bring these issues up? 75% of my team agree with me and have brought up these issues in the past, yet nothing gets changed.


答:
Approach management in such a way that you show that you understand the budget impacts of making big changes to the code and the budget impacts of NOT making the changes.  I liked Emilio's wording.

It's important to keep in mind though that "old" code will always be awful.  By this I mean, we all grow as developers constantly.  We write good code, then learn to write better code later and the previous "good" code seems terrible.  Too many developers get caught up in constantly trying to make it better and waste more money in the long run.  It's a balancing act.  That being said, it's always great if you can make it better as you go.  When you go to modify that giant function, split it up!  Eventually you'll get somewhere.


问:
How much data should be required in a request to a webservice?
When recieving data from clients how much data that you provided to them should you require back from them?

For example when clients order a product from a webservice should they just need to provide a product code? The other alternative would be to require the product code product name and product price ect.

I have alway built webservices the former way with the minimum of data returned back to me, however I have just been consuming another web service that requires the vast majority of the data returned back to them. What are the advantages of the second way?

答:
The Zen masters of Web Services would say:

Require the absolute minimum amount of data required to fill out the request.

Reply with as much data as might be useful to a requester.

The reason being that extra data requires extra (and unnecessary) work on the client side an introduces more overhead and more bugs. Sending "too much" data in the reply is generally only a little extra work for the server, it requires no effort for the client to ignore any fields it does not currently need, and, it reduces the number of change requests over the long term. In this way your API will be easier to use and useful to as wide an audience as possible.


答:
Read Joel On Software - things you should never do. Understand his reasoning, then read a few other article on bad software and how to fix it, written by managers, not programmers. Armed with this information you will be able to present a case for fixing it, in terms that managers understand and care about. Hint: Good managers don't spend time and money based solely on programmers opinions and feelings about what must be done.

"This code is crap and needs rewriting" is certainly going to get thrown back at you, even if you are technically correct.

"We can take months off the current project schedule, costing less and make it more reliable." will get their attention (notice lack of mention of the HOW you intend to do this at his stage.

Whatever you say, be certain you are correct. If you say it's bad, your rewrite has to be bloody good.If you say it will take a week, you had better be sure it will be a week, and be good. Any defect in the reworked code will cost you, personally, dearly, regardless of what might have happened had you not done the rework. If someone has been there before you and screwed up or oversold a rewrite, give up, managers don't like being made fools of and won't let it happen twice. By that token, don't screw it up for the guys that follow, you only get one shot at this...

Find ways to spread the cost over a period of time or number of projects. Managers hate risk, speculative investment and negative cash flow - work within your managers tolerances of these. Start with a small, low risk, low cost suggestion. Once you are proved right, you can go for the bigger fish.


答:
First of all, you'll find goofy legacy stuff anywhere you work as a programmer unless you work at a start-up and you're the one who creates the original goofy legacy code. You have to be able to roll with these punches if you plan on having a career in programming.

Secondly, there are often cost considerations to improving old systems. For example, I've seen more than one company that had 10 year old VB6 and classic ASP applications still in operation. In some cases, this was because a big project to move .NET failed badly. In others, the reason was "if it ain't broke, don't fix it". But, in others, the cost of the move is justifiable since problems caused by the legacy system are to big to ignore.

In situations where there has been a big failure in the past it's almost impossible to bring about a change. In that case, polish up your resume and start looking for a new job. If it's not broken, you probably won't have cause to complain about the code itself but that you weren't on a fulfilling and growing career path. If it is broken, and it sounds like it is in your case, that's when you have a chance at change.

The best approach I've seen is not to bite off too much but to begin with incremental changes that will have the most positive impact. Based on your description, better managing change requests would be a place to start. Once that's under control you can start looking into creating a service framework or other incremental design/code improvements.

The worst approach I've seen is to try to make a great leap directly from a legacy system to the latest and greatest, for example, jumping from a working but clunky VB6/Classic ASP/COM+ system to a MVC/Entity Framework system.


答: Talk to the good programmers you know about how they got started in programming.  For programmers of a certain age, my guess is that over 100X more got started with some form of bad-old "street" Basic than anything like Smalltalk, or even Logo.</p>


答:
Does management actually dictate the design?  If you have most of the team behind you, what's stopping you?  Be proactive and decide as a group. Come up with a plan to implement it incrementally.  Then do it.

Does management dictate the development tools you use?  Unless there is a time cost to swapping out a tool management usually doesn't care.  Be proactive and decide as a group what development tools you want to use.  If you need buy off from management then show them a migration plan and cost benefit analysis. Then do it.

Does management dictate the languages you use?  Be proactive and decide as a group what to use instead of VBScript.  Come up with a plan to implement it incrementally and and do it.  If you need management buy off show them the plan. Then do it.

I've got nothing for specs. That's usually highly dependent on the people and processes at your work.  Identifying what is broken and the minimal changes required to fix the process takes time, analysis and understanding of how things currently work and how they should work.  If you know that you can come up with a plan and try and convince management.

You get more change and respect if propose ways of changing that don't involve large amounts of dedicated time with no (or soft) business value to show for it.


答:
Make sure that you're not overreacting. You are fresh, probably haven't worked a lot of (any?) other places, and so aren't prepared for the world of "real life code." Real life code is a horrible thing. It's like your nice school code and your obsessively tweaked personal project code had sex in the basement of a nuclear reactor and the baby grew up in a sewer of toxic waste; it's a hideous mutant.

But assuming you're right, and the code is as bad as you say (i.e. worse than just the typically bad code), then you're right to be concerned. Talk to your team, and determine whether everyone else is on side. It will take work to improve the situation - if the rest of the team recognise the problem but don't care then you're wasting your time.

Being a junior, you probably aren't in a position to lead. If you go to management yourself, as a new hire who is also a junior, your opinion will probably be disregarded. Get your lead developer or one of the most senior guys involved. Again, if none of the senior people are interested then you're wasting your time.

Assuming you can get some senior technical people interested, I'd work towards identifying problem areas and possible solutions. For example, if "everything is basically one giant function" then next time you're working in that 'giant function' maybe you should refactor a little. Again, you need to get everyone onside. If you chip away at little pieces of your problem & improve piece by piece eventually they'll become much less of a problem. Every time you touch a piece of code consider whether it can be improved.

You aren't going to sit down with management and say 'everything is bad and needs to be rewritten'. That makes no sense for them - costs a lot and is potentially very risky. Instead they should be made aware that there are problems, and that there's a plan to slowly improve as changes are made. They should be educated on the benefits of maintainable code. This should come from a senior person that they trust technically and professionally - not from you.

Complete rewrite? Almost always a bad idea.

Ultimately there's not much you can do because you're new.  If no one wants to improve things, then you gather your experience and move to the next place.


问:
What do you think of "Planning Poker"?
Planning Poker

Summary, in case you don't want to read the wiki article:

Get a list of tasks you want to do for the upcoming iteration

For each task:

2.1 Discuss with the group what it entails

2.2 Everyone writes down / selects an estimation of how much effort is required for the task

2.3 Everyone reveals their estimation

2.4 The highest and lowest outliers explain their reasoning

2.5 Repeat until a consensus is reached

Usually something similar to numbers from the Fibonacci sequence like 0, ½, 1, 2, 3, 5, 8, 13, 20, 40, 100 are the allowed values, so you don't get long arguments over close values like 23 vs 27.

Further, the numbers represent a unit-less value of effort, whose value is determined by a baseline task that everyone agrees equals about a 1, and all else is relative to that.

Ultimately, the goal is to get a good feel for a given team's "velocity", which is the number of these points that can be completed in a given iteration.  With that, it's possible to make reasonably accurate estimates of how long any given feature will take.

We did this at iteration planning meetings at one company I worked at, and I thought it was one of the few good things about that particular company.  So, what I'm wondering is, has anyone used this?  Do you think it's a useful tool for estimation?  Does it work in all situations, or does it lend itself to certain teams, projects, etc?

答: I agree with Pavel's points. There's also one other thing that is valuable. It levels the playing field for discussion. Often quiet people are drowned out by more verbal people in a group discussion. Planning poker gives everybody a chance to make their decision before the active discussion begin. And if it the quiet person who provides the "outlier" opinion, they have the full stage on which to present their case. Therefore the technique is empowers the quieter contributors, and ensures full team participation. </p>

Title: What do you think of "Planning Poker"?


答:
I'm generally and advocate of introducing OOP and concurrency earlier in instruction than it is generally done (or at least was done in my time), BUT...

Kids  (I'll assume we're talking about pre-teens) need to learn the absolute basics first, things that we take for granted so much that we don't even realize we know them.  For those of us who first learned at an older age, these might even be things we knew before we learned programming, but things kids may not really grok too well yet.

The idea of sequence is the most basic.  Instructions are run in order. The idea that instructions cause determinisitic changes in the program, and need to be exact.  The idea of branching and looping in instruction sets. The idea that variables hold a value but can be changed and copied. (I still remember that light-bulb moment in seventh grade algebra when I understood what a variable was). Life experience gives us enough to intuit these things, to pick them up quickly once pointed out,  but kids might not have the necessary life experience.  They can understand them once explained and demonstrated, but they will often need that explanation.

To start, I think they need something where they can be guided to the most basic instructions and very quickly see things happening.  Let them get a feel for the relationship between code and actions. Create an environment that allows them to expand the instruction set ("I want to make the turtle go in a circle!") and allows them to move at their own pace such that easy changes can be made easily, but there's a lot of space for more complexity depending on how far and how fast they're able to go.

After they understand the concrete relationships, then I would fairly quickly (letting him set the pace, but nudging him forward as he looks ready) move to more abstraction, such as dividing code into functions, grouping data, connecting functions to state (encapsulation), then objects and polymorphism.  If the kid is still with you, he'll be well on his way and once he gets a solid feel for abstraction, things like concurrency and other advanced programming concepts can be introduced.


答:
Request should contain essential information only in addition to filters (if applicable). Result should contain most important data with which a user can use the information to take a decision. The returned data quantity should be minimal for systems with large number of users.

If you system is well designed to serve the business, it is possible to do this.

GUI validation is required to fall in line with business nature so that the amount of data returned is not excessive. For example, search by name in a bank should not allow single letter search. Get me all names starting with "D" is an odd request that GUI should prevent so that you don't get 100000 names back.

The database and queries should be designed for incremental browsing to serve this purpose.

Title: How much data should be required in a request to a webservice?

Body:
When recieving data from clients how much data that you provided to them should you require back from them?

For example when clients order a product from a webservice should they just need to provide a product code? The other alternative would be to require the product code product name and product price ect.

I have alway built webservices the former way with the minimum of data returned back to me, however I have just been consuming another web service that requires the vast majority of the data returned back to them. What are the advantages of the second way?


答:
I think, C++ suits as the first language better than C. You can think of starting the programming intro course with C++ but without OOP things. Then the curriculum will be like-

Introduction to Programming with C++

Introduction Object Oriented Programming with C++ (in the following semester)

There are several benefits-

This solves the main problem you mentioned- while teaching OOP with C++ to students having prior experience of C, they think that they are just learning a new language, not a paradigm(OOP). But when teaching both the courses with C++, they will know that they are going to learn something new.

You can use easier C++ language constructs like cin/cout, references, std::string etc. I am not saying to leave pointers though. You can still teach pointers after introducing reference without leaving C++. Then it will be much more easier to grasp IMHO.

If you start with C++, you may have to use some member functions of various library classes like std::string, File IO. But don't hesitate. Calling or using a member function of a class does not require OOP knowledge. OOP is required to design a class. And you can keep one or two classes aside in the intro course to give idea about C constructs and the differences between C and C++. Then students will know C also. And my request is- give emphasis on STL and generic programming with C++. Because people use Java for it's huge library support. But many of them doesn't know most of these also exists in C++ STL. Good luck.

Title: What language should be used to teach object-oriented design and development in university?

Body:
My understanding is that C++ is usually offered as the 1st OOP language, and as the 2nd programming language (after C) in my country (Bangladesh). I've taught it several times, and the problem I've run into is that students often tend to think C++ as an extension of C, i.e. C with cin and cout!
This has lead me to think about teaching Java as the first OOP language in the upcoming semester.

What is your opinion? I would like some suggestions from professional programmers as well as academics.


答:
It depends. The basic of idea of object oriented design, that of objects being something you send messages to, can be taught rather nicely. When I saw the researcher behind the project that eventually became Microsoft Kodu talk at Ignite Seattle several years back, any lingering doubts I had about object-oriented designs being a problem for children were eliminated. Some aspects of OO are quite intuitive, after all. There are very specific ideas that map nicely to domains that children (and other curious people) can relate to.

The broader question of whether the abstractions common in good OO designs are well-suited to teaching children? A much harder one. I started with imperative languages (and Logo), and I know plenty about the language of patterns that make OO designs more flexible, but even as a professional I have a little trouble knowing, for any given problem, which abstraction is best. But that balancing act is a large amount of what professional programming is about, and I didn't need to know all of this stuff when I was a hobbyist until a problem I didn't know how to solve nicely came up. So I'm not sure it's a problem, depending on what your aims are in teaching.

As for your specific questions about Smalltalk, I can't answer them, but Squeak, a Smalltalk implementation, could be fun for kids that want to move beyond the basics that they encounter with something like Kodu or, for example, Logo. The only real way to answer whether it's effective for teaching OO is to try.

Since most of my coding as a child was self-directed, and the availability of any community around me was nearly nonexistent, I used the tools that were available with the system I had, which basically meant Basic, Logo, and a modest amount of Assembly (TMS9900 and 6502/8502). It's fair to say that a suitably curious and determined child will surprise you if you provide tools that make simple things fun and hard things possible, and provide adequate mentorship when they get stuck on something. So I am fairly convinced that you could hand the right child Lisp or Perl or C# or Processing or Ruby and they'd figure out lots of things out on their own, and become incredibly frustrated with things you wouldn't necessarily expect to be an issue (which is where an experienced adult can help). But many kids, at least after a certain age, won't even be curious or determined enough to move beyond printing their name a few hundred times on the screen. I'm not really sure how much the language itself matters at the earliest stages of learning about computers, other than it should be relatively low friction to get something visual to happen.


问:
Fastest C++ XML parsing library
I have thousands of .xml files from size 1MB-45MB (no DTDs). I need to parse and further manipulate these XML files before generating separate .xml files with the results of my regex.

What the fastest open-source XML parsing library for C++? Aside from the parsing library, what other approaches can I use to speed up XML parsing?

答:
Is the raw speed of an XML parser or RegEx engine going to make as much of a difference as a faster processor running code that is easy for you to understand & maintain?

From the example you've given I can envisage very big files being processed.  Even so would you not be wiser to try and find a way of breaking up the files and processing them in parallel to increase throughput and leverage multiple cores rather than focusing on relatively small differences in library speed.

Title: Fastest C++ XML parsing library


问:
Stuff every programmer needs while working
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed

答:
A punching bag

Great way to blow off some steam.


问:
What can and can't the Garbage Collector do?
Will the GC take care of all memory management issues (memory leaks) ?

Is there any case where you don't want the GC to take control of some part of your code ?

答:
There are many memory issues (dangling pointers, buffer overruns and similar) and resource issues (memory leaks, other resource leaks). Garbage collector takes care of:

dangling pointers

mostly memory leaks

partially other resource leaks

The language not allowing pointer arithmetic takes care of:

buffer overruns and other cases of invalid pointers

Neither can solve other cases of resource problem where you forget to remove reference to the memory/resource from somewhere, so you can still have memory leak with GC (Exception objects are especially notable for referencing many things you are not aware of).

While GC can help you with releasing other resources than memory by use of finalizers (destructors), it will release those resources with non-deterministic delay, which is often not appropriate for resources like files or network sockets. To handle this kind of resource problems you need some language construct for scoped resources like using statement in C#, RAII idiom in C++ or the latest extension to try syntax in Java 7 and it's still only help, because you need to use it in the code.

Not allowing pointer arithmetic and creating addresses from numbers is needed to be able to run precise garbage collector. Some useful optimizations like compacting can only be implemented in precise collectors (you can only move objects if you can tell for sure what is a reference, so you can update it; you can't do that in C/C++).


答:
I think Java is a bad idea. I hate this language so can't be objective, but learning OOP in an environment where everything is OO may be very confusing. The fact that Java has been made only for OOP does not make it the best in this domain.

In my school, we used OCaml as our first programming language (I was programming long before that but never learned it in course). Dispite the fact it teaches functional programming (which is probably not useful to you), the OO part is very clean and easy to read / understand. For me, it brings together many great things for learning purpose: high level, strongly typed, multiparadigms and a good standard library.

Saying that C++ is the best choice because it's the most useful is not relevant. Programming courses should teach how to learn programming, and not only how to program using a particular language.


答:
In the case of XML, Tim Bray outlines the design goals in his annotated version of the XML spec http://www.xml.com/axml/target.html#sec-origin-goals.

The design goals for XML are:

XML shall be straightforwardly usable over the Internet.

XML shall support a wide variety of applications.

XML shall be compatible with SGML.

It shall be easy to write programs which process XML documents.

The number of optional features in XML is to be kept to the absolute minimum, ideally zero.

XML documents should be human-legible and reasonably clear.

The XML design should be prepared quickly.

The design of XML shall be formal and concise.

XML documents shall be easy to create.

Terseness in XML markup is of minimal importance.

The annotation for goal 10 is:

Terseness is of Minimal Importance

The historical reason for this goal is that the complexity and
  difficulty of SGML was greatly increased by its use of minimization,
  i.e. the omission of pieces of markup, in the interest of terseness.
  In the case of XML, whenever there was a conflict between conciseness
  and clarity, clarity won.

Rick Jelliffe has some more background in http://www.oreillynet.com/xml/blog/2008/01/the_design_goals_of_xml_1.html


答:
What I like is:

A super fast computer.

A large enough monitor. (Debugging in a 17' is horrible).

Super ergonomic chair.

A private room.

Talks via chat or emails only for most of the part.

Quality headphone

Water bottle with fresh lukewarm water.

Calm atmosphere.

A sofa to lie down.

A locker to keep personal things

A book (to scribble some thoughts).

Use which OS, IDE etc (left to the programmer).

Fast internet connection with no restriction (ok adult contents can be restricted. Nothing else.)

I need good friends and fellow programmers of preferably same age.

A girl to flirt with may be ideal since life is so boring. And programmers hardly have got any girl friends. (hah! just kidding)

A free time where we can pursue any hobby that we like.
Food available locally. Needn't go out of the building to have one.

Title: Stuff every programmer needs while working

Body:
I've been tasked with creating a fun and relaxing environment, one thing I know that I want is ergonomic mice and keyboards, others have suggested exercise balls and bands.

What is it that every programmer needs while working? What might not be necessary but would be nice to have anyway?

Note: this question was asked previously, but has been recommended to be posted here. See this link for the previous responses: https://stackoverflow.com/questions/3911911/stuff-every-programmer-needs-while-working-closed


问:
The need for Explicit Type Conversion in C#
Consider the following code:

```<code>DerivedClass drbObj = (DerivedClass)obj;
</code>```

Here obj is of type Object and this is reasonable since Object is the base type of every Class in C#.

Here, since the type of derObj is defined at compile time, what is the need to explicitly use type conversion here. Can't the compiler predict on it's own that it will be of DerivedClass. I understand that, the Conversion type doesn't have to match the Derived type, but for practical purpose, it will only be as useful as the Derived type.

Could someone explain with a small, hypothetical example, as to why the Explicit Type Conversion is necessary when a reference of type Object is being assigned to a derived class.

From what I know, in C, there is no  need to do perform Explicit type conversion from void* to any pointer and the compiler can handle it, based on the type of the pointer to which the converted value is being assigned.

答:
Can't the compiler predict on it's own that it will be of
  DerivedClass.

No? How on earth would it predict that? You want it to solve the Halting problem? Objects may be useless (and a shitty, shitty design) but there are millions of classes derived from Object. How would the compiler know which one to pick?

The reason the cast is necessary is because it could fail at run-time, and the compiler wants to know that you're sure. Explicit casting is much safer than implicit casting.

From what I know, in C, there is no need to do perform Explicit type
  conversion from void* to any pointer and the compiler can handle it,
  based on the type of the pointer to which the converted value is being
  assigned.

That's a bad thing, not a good thing, and conversion != casting. Casts are bad. Try not to use them.


答:
The reason why you have to do this is pretty simple:

Because that's the way the language was designed.

While yes, the C# designers could have decided to infer that your intent was to cast obj based solely on your declaration, they chose not to do so, probably because such an inference would cause more problems than it solved.

I can think of two reasons why they might have chosen not to infer the cast to DerivedObj:

1) Because it's inconsistent.  Though for assignment (as in your example) it may seem logical to perform the inference, there are a ton of situations you would need to perform the cast explicitly, and making the casting behavior consistent makes the language conceptually simpler.  For example, let's say you were writing a piece of code that needed to set the obj's ID to 5, knowing ahead of time that it was a DerivedObj.  You'd still have to do the cast:

```<code>((DerivedObj)obj).ID = 5;
</code>```

2) Because it's dangerous.  Performing the cast at assignment is an "are you sure?" kind of check which makes you think twice about what the object really is before assigning.  I would say that's a feature of the language, and definitely not worth a special-case casting behavior just for assignment.  In fact, if you really created obj by saying obj = new object() somewhere, the cast will fail anyway.

Title: The need for Explicit Type Conversion in C#

Body:
Consider the following code:

```<code>DerivedClass drbObj = (DerivedClass)obj;
</code>```

Here obj is of type Object and this is reasonable since Object is the base type of every Class in C#.

Here, since the type of derObj is defined at compile time, what is the need to explicitly use type conversion here. Can't the compiler predict on it's own that it will be of DerivedClass. I understand that, the Conversion type doesn't have to match the Derived type, but for practical purpose, it will only be as useful as the Derived type.

Could someone explain with a small, hypothetical example, as to why the Explicit Type Conversion is necessary when a reference of type Object is being assigned to a derived class.

From what I know, in C, there is no  need to do perform Explicit type conversion from void* to any pointer and the compiler can handle it, based on the type of the pointer to which the converted value is being assigned.

Body:
The reason why you have to do this is pretty simple:

Because that's the way the language was designed.

While yes, the C# designers could have decided to infer that your intent was to cast obj based solely on your declaration, they chose not to do so, probably because such an inference would cause more problems than it solved.

I can think of two reasons why they might have chosen not to infer the cast to DerivedObj:

1) Because it's inconsistent.  Though for assignment (as in your example) it may seem logical to perform the inference, there are a ton of situations you would need to perform the cast explicitly, and making the casting behavior consistent makes the language conceptually simpler.  For example, let's say you were writing a piece of code that needed to set the obj's ID to 5, knowing ahead of time that it was a DerivedObj.  You'd still have to do the cast:

((DerivedObj)obj).ID = 5;

2) Because it's dangerous.  Performing the cast at assignment is an "are you sure?" kind of check which makes you think twice about what the object really is before assigning.  I would say that's a feature of the language, and definitely not worth a special-case casting behavior just for assignment.  In fact, if you really created obj by saying obj = new object() somewhere, the cast will fail anyway.


答: Garbage collection works well for memory. If you have a ton of memory, why run around cleaning up every byte as it is done with? GC typically responds to "memory pressure" and cleans up when needed. This is a good thing for memory. However, if you have an object that holds a non-memory resource (file handle, database connection, lock) waiting until memory pressure triggers GC will generally meaning holding that resource way too long. You need another approach for those resources. That might mean a reference counting shared resource, with deterministic release when the reference count reaches zero, or the using/Dispose approach of .NET.</p>

Title: What can and can't the Garbage Collector do?

Body:
Will the GC take care of all memory management issues (memory leaks) ?

Is there any case where you don't want the GC to take control of some part of your code ?


答:
Speaking from experience:  It's not easy.  It's almost impossible.  Management doesn't care that the code sucks and more than likely are completely ignorant and/or clueless of the issues being faced, or they would have fixed it long ago and you wouldn't be stuck with it today.  The best thing you can do is to make a list of the reasons the code sucks, and then the reasoning behind why it sucks to demonstrate actual business value in refactoring/rewriting it.

An example might be for "Code is not maintainable":

The current code is not maintainable because of X, Y and Z (list reasons why it's unmaintainable).  This makes change requests and new features very difficult to do, because X, Y, Z (reasons why making changes is difficult).  Because changes are hard, the development team can't easily respond to bug fixes and improvements.

Your only hope is that your boss and senior management aren't too stupid to understand what ramifications that has for the code, and are willing to stop coming out with new feature requests to address the issues, otherwise your efforts are going to be in vain.  Speaking from past experience, it's very likely that they won't see anything wrong with the code, and/or your co-workers are too spineless to bring their concerns to management.

Good luck.  You'll need it.


问:
Can someone find a job as a programmer without an education?
Interested in knowing from the more experienced ones if someone can find a job as a programmer without even a highschool degree. Consider the said person to be an average programmer. Would someone even consider giving him/her a chance on an interview ? The languages of interest would be python/php/java/c#

Please answer for your region/city/country only. No "go back to school" answers please.

答:
It used to be possible, but it has become increasingly difficult (if not near impossible) in the last 15 years. I'm always of the school of thought that software engineering is MUCH, MUCH MORE a mindset and innate mental capabilities towards analysis and problem solving that the completion of a formal curriculum.

That is, people either get (or have the capability of getting) things like recursion and pointers or not (independently of whether people go to CS schools or not.) I've known people with degrees in Literature or Accounting being able to code really low level crap on embedded systems, whereas I've met people well into the CS masters who still cannot grasp the idea of a pointer to a function.

But nowadays, it will be really hard for someone without a formal education to break through into the software industry. Barring an opportunity to work at a small company where they might give you a chance, I don't know how to best suggest going about it.

Good luck.

--- edit ---

I would really hesitate to hire someone without a HS degree (unless he already has a demonstratively long work record in the software field), though. I could consider someone with partial college education or with a degree not related to math, sciences or engineering if  they can prove they have the analytical skills (or the math that tends to be a good indicator of analytical skills.)

It is just too much the risk. And in hiring, there is always a risk analysis trade off involved.


问:
What are the disadvantages of automated testing?
There are a number of questions on this site that give plenty of information about the benefits that can be gained from automated testing.  But I didn't see anything that represented the other side of the coin: what are the disadvantages?  Everything in life is a tradeoff and there are no silver bullets, so surely there must be some valid reasons not to do automated testing.  What are they?

Here's a few that I've come up with:

Requires more initial developer time for a given feature

Requires a higher skill level of team members

Increase tooling needs (test runners, frameworks, etc.)

Complex analysis required when a failed test in encountered - is this test obsolete due to my change or is it telling me I made a mistake?

Edit

I should say that I am a huge proponent of automated testing, and I'm not looking to be convinced to do it.  I'm looking to understand what the disadvantages are so when I go to my company to make a case for it I don't look like I'm throwing around the next imaginary silver bullet.

Also, I'm explicity not looking for someone to dispute my examples above.  I am taking as true that there must be some disadvantages (everything has trade-offs) and I want to understand what those are.

答:
I wouldn't say these are entirely applicable disadvantages, but the few I hit most are:

Time taken to set up the test in a complex enterprise application.

Handling old tests that fail incorrectly, in other words, the system has evolved and now the tests are wrong.

False confidence from patchy or unknown test coverage.

Test coverage that is patchy can lead to a false sense of security.  If you do a refactor and use the tests to prove it's validity, what has proven your tests are able to prove this?

The time it takes to create the test is sometimes a problem for us.  Our automated testing doesn't just include unit tests, but also use case tests.  These tend to be broader and require context.

Of course, my perspective is from an application that is older than it's unit tests.


问:
What should I expect from a technical evaluation for C++?
I have been asked to go for a technical test/evaluation for a job as a junior developer, mainly using C++. This is my first test/evaluation, and it is 2 hours long.

My C++ is a bit rusty as I have been doing projects recently on PHP.

This is a UK company, however im guessing technical testing of candidates will be pretty much the same everywhere.

What should I expect in one of these tests?

答:
I got in my last interview:

Difference between passing an object to a function by value/reference/pointer and where and why you would do that.

Swap the 2 last 8 bits of an integer eg RGBA to RGAB.

What's RIAA?

Define template meta programming: you might get a question in terms of "solve this problem with TMP.."

What's mutable, volatile, const etc etc etc mean? know all keywords.

multiple inheritance.... again again and again.

Multi threading: Producer consumer and buffered shared memory objects.

A few more periphery questions:

UML aggregation and composistion

Design patterns : implement a singleton... What are the common components of MVC?


答:
You pretty much nailed the most important ones. I have a few minor additions, plus the disadvantage of tests actually succeeding - when you don't really want them to (see below).

Development time: With test-driven development this is already calculated in for unit tests, but you still need integration and system tests, which may need automation code as well. Code written once is usually tested on several later stages.

Skill level: of course, the tools have to be supported. But it's not only your own team. In larger project you may have a separate testing team that writes tests for checking the interfaces between your team's product and other's. So many more people have to have more knowledge.

Tooling needs: you're spot on there. Not much to add to this.

Failed tests: This is the real bugger (for me anyways). There's a bunch of different reasons, each of which can be seen as a disadvantage. And the biggest disadvantage is the time required to decide which of these reasons actually applies to your failed test.

failed, because of an actual bug. (just for completeness, as this is of course advantageous)

failed, because your test code has been written with a traditional bug.

failed, because your test code has been written for an older version of your product and is no longer compatible

failed, because the requirements have changed and the tested behavior is now deemed 'correct'

Non-failed tests: These are a disadvantage too and can be quite bad. It happens mostly, when you change things and comes close to what Adam answered. If you change something in your product's code, but the test doesn't account for it at all, then it gives you this "false sense of security".

An important aspect of non-failed tests is that a change of requirements can lead earlier behavior to become invalid. If you have decent traceability, the requirement change should be able to be matched to your testcode and you know you can no longer trust that test. Of course, maintaining this traceability is yet another disadvantages. And if you don't, you end up with a test that does not fail, but actually verifies that your product works wrongly. Somewhere down the road this will hit you.. usually when/where you least expect it.

Additional deployment costs: You do not just run unit-tests as a developer on your own machine. With automated tests, you want to execute them on commits from others at some central place to find out when someone broke your work. This is nice, but also needs to be set up and maintained.

Title: What are the disadvantages of automated testing?

Body:
There are a number of questions on this site that give plenty of information about the benefits that can be gained from automated testing.  But I didn't see anything that represented the other side of the coin: what are the disadvantages?  Everything in life is a tradeoff and there are no silver bullets, so surely there must be some valid reasons not to do automated testing.  What are they?

Here's a few that I've come up with:

Requires more initial developer time for a given feature

Requires a higher skill level of team members

Increase tooling needs (test runners, frameworks, etc.)

Complex analysis required when a failed test in encountered - is this test obsolete due to my change or is it telling me I made a mistake?

Edit

I should say that I am a huge proponent of automated testing, and I'm not looking to be convinced to do it.  I'm looking to understand what the disadvantages are so when I go to my company to make a case for it I don't look like I'm throwing around the next imaginary silver bullet.

Also, I'm explicity not looking for someone to dispute my examples above.  I am taking as true that there must be some disadvantages (everything has trade-offs) and I want to understand what those are.


问:
How to keep .Net assemblies relevant through high-flux period
How much do you, as .Net developers, consider the changes between Windows XP, 7, & 8  when choosing your development environment and libraries?

We are nearing the end of Windows XP; Windows 7 is noticeably and aggressively making it's mark; Windows 8 (Win R/T) is on the horizon. Granted, flexibility is completely expected from the customer's perspective. But we are faced with developing to the current OS, Windows 7 (understandably, some may argue the current OS is still XP) ...and maintain legacy code for the outgoing OS, WinXP.

So, Windows 8 and all the Win R/T goodness flares the imagination and you can't help but ask yourself, "what will still be relevant in 5 years?"  Well, at least I can't help but ask the question.

During periods of rapid evolution of an OS, what considerations do you plan for in application design, libraries, frameworks, and choosing development environments; and, in doing so, how do you determine the length of relevance a particular design will have?

答:
But we are faced with developing to the current OS, Windows 7
  (understandably, some may argue the current OS is still XP) ...and
  maintain legacy code for the outgoing OS, WinXP.

The only people who say this are just asking to fail so their argument is flawed, in other words, they are unlikely to change and are stuck in their ways.  This means you can ignore them without a great deal of risk, I mean look at what Apple has done to the "the market previously known as the tablet market", all the companies that ignored what we wanted are throwing the entire pot of noodles at the wall.  I would argue the iPad is not a Tablet, I only say this because, you would be hard pressed to replace a standard computer with it.  I would call it a multi-purpose computing touch device, I think thats fair, I have yet to see a tablet from anyone that can replace the standard personal computer.

So, Windows 8 and all the Win R/T goodness flares the imagination and
  you can't help but ask yourself, "what will still be relevant in 5
  years?" Well, at least I can't help but ask the question.

This question cannot be answered.  Who would have thought that 5 years ago we would have mobile phones that could access your desktop just like you would as a desktop at home, I know I didn't think the iPhone was going to come out, let alone the iPad or the Kindle Fire.

During periods of rapid evolution of an OS, what considerations do you
  plan for in application design, libraries, frameworks, and choosing
  development environments; and, in doing so, how do you determine the
  length of relevance a particular design will have?

You continue to look at ways to improve your user interface, you design everything else so it can accept different forms of input, because voice, touch, and inputs like Kinect are not going away.

I think we are at least a decade away from the science fiction inputs described in so many movies over the last 3 decades.

Adobe is example they after how many years just released a mobile version of Photoshop.  This might be a horrible example because its a complete translation of their full suite, who knows if the programs we have come to use every single day will ever get full translations so touch/voice inputs can be used.


答: Do the same thing you always should be doing -- keep your core logic separated from UI and other platform specific concerns. They might change how the input comes in, but they aren't changing the if statement or for loops anytime soon.

Title: How to keep .Net assemblies relevant through high-flux period

Body:
How much do you, as .Net developers, consider the changes between Windows XP, 7, & 8  when choosing your development environment and libraries?

We are nearing the end of Windows XP; Windows 7 is noticeably and aggressively making it's mark; Windows 8 (Win R/T) is on the horizon. Granted, flexibility is completely expected from the customer's perspective. But we are faced with developing to the current OS, Windows 7 (understandably, some may argue the current OS is still XP) ...and maintain legacy code for the outgoing OS, WinXP.

So, Windows 8 and all the Win R/T goodness flares the imagination and you can't help but ask yourself, "what will still be relevant in 5 years?"  Well, at least I can't help but ask the question.

During periods of rapid evolution of an OS, what considerations do you plan for in application design, libraries, frameworks, and choosing development environments; and, in doing so, how do you determine the length of relevance a particular design will have?


答:
You should carefully evaluate what kind of information does the client need to send to the server.
In my opinion you should provide the full set of information needed to operate only to a stateless service, on the other side I prefer to send the minimum set of data needed if the service is state-full.

In an order filling web service (as you describe) there are a set of relevant information which should be kept in a session by the server and not provided by the client.
Think of the price. What if a malicious client changes the price from 100$ to 1$?

Requesting redundant information to the client is a general security threat. That said you should not ask a client to send that kind of data.
The other good side effects of this practice are that a client is easier to implement and that the payload you transfer is smaller but I consider them side effects as a good security policy on the transferred data trumps them all.


问:
Maximum project duration for Feature Driven Development Project
Is there a duration limit for FDD Project when those projects are likely to fail due external and internal factors?

For example XP projects should kept short due the openess of the concept and dependents on the individuals in the team and lack of documentation which is vulnerable to disturbances like losing team members and so forth.

答:
Any project where there's a high risk of failure should aim to deliver something as soon as possible.

This is of benefit for several reasons:

You can gauge whether there is going to be the necessary demand for your product and fail early.

You can get rapid feedback on features already developed.

You can get rapid feedback on which outstanding features are still considered important. The  relative priority of features will change over time and new requirements will come in while old ones fall by the wayside.

You can have something "out there" to show investors so they keep giving you money.

This is true regardless of the approach you use to development.

Obviously the exact duration of each phase/stage/sprint will depend on the development effort you can put in and the minimum set of requirements that need to be fulfilled at each iteration.


答: Having just started trying automated tests in our team, the biggest disadvantage I've seen is that it's very difficult to apply to legacy code that wasn't designed with automated testing in mind.  It would undoubtedly improve our code in the long term, but the level of refactoring needed for automated testing while retaining our sanity is a very high barrier for entry in the short term, meaning we're going to have to be very selective about introducing automated unit testing in order to meet our short term commitments.  In other words, it's a lot harder to pay off the credit cards when you're already deep in technical debt.</p>


答:
The business case is almost impossible to make because your deliverable is working software (what they already have) not elegant code.

Add in the fact that in software there is a big opportunity cost from getting to market with features first. If you really think about it, the long term payback on the time investment isn't guaranteed.

That said, it is still a good plan to refactor and fix the small things (like getting a good VSS) along the way in manageable bites. Ultimately this is a technical issue not a management one. Just do what needs to be done while still delivering on what you promise and you will be fine. Management probably isn't going to be interested in the nitty gritty details of code quality even if you make a strong case.


问:
Does objective-c's method overhead make a 'many small methods' design approach inadvisable?
I generally favour using small methods, as recommended by, amongst others, Bob Martin in Clean Code. I've also read enough about Objective-C's internals to have at least some idea about how its message dispatch works (bbums series is particularly informative on this).

Premature optimisation concerns notwithstanding, I'd like to know if all that work that Objective-c does with objc_msgSend is, in practical terms, significant enough for the 'many small methods' approach to be inadvisable for Objective-C projects.

Empirical findings are particularly welcome (maybe I'll set up a test myself sometime). Experience from anyone who has written large objective-c projects would also be great.

Clarification

The general tone of the question is intentional. I'm not asking about performance tuning of specific apps (which is why I ask here rather than on SO), but more about whether Objective-C's language characteristics discourage a certain design approach. I have observed that much of the code I've seen from Apple, and other parties (on github etc) tends towards large methods (and classes), and I'm wondering if this is a bias that has crept in because of the language itself. Of course I may have been reading the wrong code, or it may be cultural rather than technical factors that have led to the tendency if it exists.

(For what it's worth, I am currently writing Objective-C, and I'm using small methods)

Further request

I agree with both the answers that have been given. One further thing I'd like is for someone to point me to a (hopefully substantial) open-source (or otherwise visible) Objective-C codebase that uses nice short methods (and small classes). I haven't seen anything in Objective-C yet to compare with (for example) the fitnesse source.

答:
I don't really know whether the overhead is negligible or not. But, I would prefer to design a system to be easily understandable and maintainable first, and that normally means small, focused methods and classes. This will even help with subsequent code tuning too (just because the code is more maintainable). Also, it's important to profile the code to find real bottlenecks, which might not even be related to method call overhead. If you do any off-process operations (e.g. calls to database, network, file system), these tend to dominate the runtime of the program anyway.

But, as usual, your mileage may vary...


问:
How to use Blend sample data as real data?
I am trying to do some design in Blend 4. The sample data function of Blend is nice to have during design time, but it could be much more better to see the design in browser.

Can anyone help me to use sample data created by Blend as real data (see same data in browser) also ?

Thanks in advance.

答:
Design time data and run time data are different.

You can certainly use the same class structure you created for your sample data when setting up your Create Object Data Source backing which could provide you with your need of leveraging the structure you defined for the sample data.


答:
Management do not care about the code. They care about having a product to sell.

If the legacy system is really, really bad and it is adding a ridiculous amount of overhead on for the majority of the team (I say majority because there's always a guy who either coded large chunks or all of it and knows it like the back of his hand) then approach them and say it's costing the business money in development time, and it'll have a knock on effect with customer satisfaction.

But once again, they still don't care about code, they care about a product, so whilst that answer might make them go "Yeah lets do it", you might as well tidy the code up without seeking the permission of a manager. Don't go overboard, make sure you talk to the team first, no one likes to come and try use that function that took you 3 months to write and now appears to not work because it's been hacked out.


答:
Easy access to refreshments, for example a coffee pot in the room (if that's your preference).

There's nothing worse than grabbing a quick coffee before embarking on the next section of code, and being ambushed by users with support issues or managers who want "a quick chat" (or worse, vica versa).


问:
XML or HTML for User Manual/Help and Why?
I want to make User Manual/Help to my program. I found two good ways - XML or HTML - which should I use and why?

I know how to do it in html (I know how to use js, css and such) but in XML it's harder (or I imagine?)

anyway which way should I choose and why?...

Edit:

There's one important thing I forgot to mention: I need it for the army, I can make it only on army's computer and I cannot install anything you said. I can use notepad and that's it.

答:
XML will let you define custom elements that you can use transform into HTML using XSLT (XSLT is used to transform XML data from one format to another). This is more flexible, but also more work.

For example: If you go the XML route, you could define new elements in an XSD (XSD is where you can define new elements) and your document could be written like this:

```<code><HelpHeader>Ron's Help manual</HelpHeader>
<Warning level="5">Not to be taken internally!!</Warning>
<HelpBody>Welcome to the Help Manual!
        <HelpSidebar>I hope this documen is very helpful to you<HelpSidebar/>
</HelpBody>
</code>```

This might make it easier to write the document as the elements are closer to the document you're writing. You must then use XSLT to transform the document into HTML (and I think you can include CSS and maybe JavaScript here as well?), which might be a lot of work.

One advantage of going the XML route is that if you ever decide to change the layout/look-and-feel, you don't change the content of your XML file, you change the XML-to-HTML translations in the XSL file. This way the content is preserved and huge and sweeping style changes can be made quite easily. This is a big bonus when the style changes are relatively small, but there are hundreds of HTML files. You can make one change in the XSL, and regenerate the HTML with a single button-click! No one wants to manually reapply HTML changes to all those files.

Body:
XML will let you define custom elements that you can use transform into HTML using XSLT (XSLT is used to transform XML data from one format to another). This is more flexible, but also more work.

For example: If you go the XML route, you could define new elements in an XSD (XSD is where you can define new elements) and your document could be written like this:

<HelpHeader>Ron's Help manual</HelpHeader>
<Warning level="5">Not to be taken internally!!</Warning>
<HelpBody>Welcome to the Help Manual!
        <HelpSidebar>I hope this documen is very helpful to you<HelpSidebar/>
</HelpBody>

This might make it easier to write the document as the elements are closer to the document you're writing. You must then use XSLT to transform the document into HTML (and I think you can include CSS and maybe JavaScript here as well?), which might be a lot of work.

One advantage of going the XML route is that if you ever decide to change the layout/look-and-feel, you don't change the content of your XML file, you change the XML-to-HTML translations in the XSL file. This way the content is preserved and huge and sweeping style changes can be made quite easily. This is a big bonus when the style changes are relatively small, but there are hundreds of HTML files. You can make one change in the XSL, and regenerate the HTML with a single button-click! No one wants to manually reapply HTML changes to all those files.


答:
Actually, I would go for both.

We are writing big manuals for a military system and DocBook with it's transformations possibilities is great. Don't create your own schema, use the comprehensive one that DocBook has and export to HTML, PDF, Latex, etc.

Storing things in DocBook also has the tremendous advantage that it's just plain text, meaning that you can sensible store it in CVS, associated bugtracker tickets to it, etc. In the long run, for big manuals, this is just the way to go.

It works great.

Title: XML or HTML for User Manual/Help and Why?

Body:
I want to make User Manual/Help to my program. I found two good ways - XML or HTML - which should I use and why?

I know how to do it in html (I know how to use js, css and such) but in XML it's harder (or I imagine?)

anyway which way should I choose and why?...

Edit:

There's one important thing I forgot to mention: I need it for the army, I can make it only on army's computer and I cannot install anything you said. I can use notepad and that's it.