答:
I developed ASP .Net WebForms applications for 3 years, and after one day of doing an MVC tutorial I was sold. MVC is almost ALWAYS the better solution. Why?

The page lifecylce is simpler and more efficient

There is no such thing as controls besides html controls. You don't need to debug your output to see what ASP .Net is generating.

ViewModels give you immense power and obviate the need to do manual control binding and it eliminates many errors relating to binding.

You can have multiple forms on a page. This was a serious limitation of WebForms.

The web is stateless and MVC matches the architecture of the web more closely. Webforms introduces state and the bugs you have with it by introducing the ViewState. The ViewState is automatic and works in the background, so it doesn't always behave the way you want it to.

Web applications need to work with ajax these days. It's not acceptable to have full page loads any more. MVC makes ajax so so much better, easier and more efficient with JQuery.

Because you can have multiple forms on a page, and because the architecture is driven by calls to urls, you can do funky things like ajax load a different form, like an edit form into your current page using JQuery. Once you realise what this lets you do you can do amazing things easily.

ASP .Net WebForms is not only an abstraction over html, it is an extremely complex one. Sometimes you would get a weird bug and struggle with it for much longer than need be. In many cases you could actually see what it was doing wrong but you are unable to do anything about it. You end up doing weird workarounds.

WebForms does not make a good technology for designers. Designers often like working with html directly. In MVC it's a view, in WebForms it's half a day of work.

As the web platform is evolving fast WebForms wont keep up. It's not aware of new tags or features of HTML5, it will still render the same stuff unless you get (often) expensive 3rd party controls or wait for Microsoft to issue an update.

Controls in WebForms limit you in so many ways. In MVC you can just grab a JQuery library and integrate it into your templates.

I know some of the issues above have been addressed to some extent as WebForms evolves, but that was my original experience. All in all I would find it extremely hard to find a business case for WebForms unless a project is already using it.

Title: When to favor ASP.NET WebForms over MVC

Body:
I know that Microsoft has said

ASP.NET MVC is not a replacement for WebForms.

And some developers say WebForms is faster to develop on than MVC.  But I believe speed of coding comes down to comfort level with the technology so I don't want any answers in that vein.

Given that ASP.NET MVC gives a developer more control over their application, why isn't WebForms considered obsolete?  Alternatively, when should I favor WebForms over MVC for new development?


问:
Logging in JSON Effect on Performance
I see more and more articles about logging in JSON. You can also find one on NodeJS blog. Why does everyone like it so much? I can only see more operations getting involved:

A couple new objects being created.

Stringifying objects, which either involves calculating string length or multiple string allocations.

GCing all the crap that was created.

Is there any test on performance when using JSON logging and regular string logging? Do people use JSON (for logging) in enterprise projects?

答:
If your machine runs so close to its limits that such issues really would matter, you most likely have more serious problems. While there may be exceptional situations where this makes some difference, many applications (maybe most) run on machines for which the difference if you log JSON, simple text or records to a database doesn't matter at all. Objects, strings and other conversions have to be done in most cases anyway (unless you log raw binary?), maybe you wont see it, because you use default classes that handle it in the background (like if you write to a database).

If you need performance evaluations for this, you would need to make them yourself on the machine you want to run your code and with the programming environment you use everyday. If there is a big overhead or any at all depends on many things. If you write a website in Ruby on Rails for example, your data in most cases is a hash, converting that to JSON costs you near to nothing, since the internal representation isn't that far from what you want to write (and it's typical for Rails code to throw around such objects and data structures all the time).

The advantages depend again on your tools. If you have JSON built in your libraries, you can easily read it and display this in some form. Again as an example: Assuming you had an admin interface for your web site and want to show some logging information stored in JSON, you could do this read and display as HTML in Ruby in a single line of code in some cases.

ContentLicense: CC BY-SA 3.0

Title: Logging in JSON Effect on Performance


答:
JSON logging gives you the ability to parse the log file programmatically even if the format has changed in time.

A good example is Apache logs. By default Apache uses common format for access.log:

```<code>"%h %l %u %t \"%r\" %>s %b"
</code>```

Say that you have built an offline parser that takes one of those log files and calculates some statistics from it.

At some moment you introduce subdomains to your application and include virtual_host to your logs (just so you can debug if problems appear with one of the subdomains):

```<code>"%v %h %l %u %t \"%r\" %>s %b"
</code>```

Your parser doesn't make use of the virtual_hosts, but you still need to adapt your parser to:

accept the new log format (notice the %v at the head of log format)

still support the old log format (for older log files)

But if you log in JSON, your parser won't even notice the added field and can happily parse the new logs as well as old logs. And some other parser can make use of the added fields  if they exist.

And of course for you, parsing JSON is easier than writing regexps to parse string logs.

Title: Logging in JSON Effect on Performance

Body:
I see more and more articles about logging in JSON. You can also find one on NodeJS blog. Why does everyone like it so much? I can only see more operations getting involved:

A couple new objects being created.

Stringifying objects, which either involves calculating string length or multiple string allocations.

GCing all the crap that was created.

Is there any test on performance when using JSON logging and regular string logging? Do people use JSON (for logging) in enterprise projects?

Body:
JSON logging gives you the ability to parse the log file programmatically even if the format has changed in time.

A good example is Apache logs. By default Apache uses common format for access.log:

"%h %l %u %t \"%r\" %>s %b"

Say that you have built an offline parser that takes one of those log files and calculates some statistics from it.

At some moment you introduce subdomains to your application and include virtual_host to your logs (just so you can debug if problems appear with one of the subdomains):

"%v %h %l %u %t \"%r\" %>s %b"

Your parser doesn't make use of the virtual_hosts, but you still need to adapt your parser to:

accept the new log format (notice the %v at the head of log format)

still support the old log format (for older log files)

But if you log in JSON, your parser won't even notice the added field and can happily parse the new logs as well as old logs. And some other parser can make use of the added fields  if they exist.

And of course for you, parsing JSON is easier than writing regexps to parse string logs.


问:
What are best practices for testing programs with stochastic behavior?
Doing R&D work, I often find myself writing programs that have some large degree of randomness in their behavior. For example, when I work in Genetic Programming, I often write programs that generate and execute arbitrary random source code.

A problem with testing such code is that bugs are often intermittent and can be very hard to reproduce. This goes beyond just setting a random seed to the same value and starting execution over.

For instance, code might read a message from the kernal ring buffer, and then make conditional jumps on the message contents. Naturally, the ring buffer's state will have changed when one later attempts to reproduce the issue.

Even though this behavior is a feature it can trigger other code in unexpected ways, and thus often reveals bugs that unit tests (or human testers) don't find.

Are there established best practices for testing systems of this sort? If so, some references would be very helpful. If not, any other suggestions are welcome!

答:
I'm not a specialist in this domain, but there is a scientific litterature relative to stochastic program testing.

If you cannot easily create test classes, a statistical test can be used, as #Euphoric said. Borning et al. compare a traditional approach and a statistical one. A generalisation of the statistical tests suggested by @Euphoric could be the one discussed by Whittaker. He suggested to create a stochastic model of the desired (stochastic, in your case) behavior and then generate specific test cases from this model (see his dedicated paper).

ContentLicense: CC BY-SA 4.0


问:
Tool to identify (and remove) unnecessary website files?
Inevitably I'll stop using an antiquated css, script, or image file.  Especially when a separate designer is tinkering with things and testing out a few versions of images.  Before I build one myself, are there any tools out there that will drill through a website and list unlinked files?  Specifically, I'm interested in ASP.NET MVC sites, so detecting calls to (and among many other things) @Url.Content(...) is important.</p>

答:
Aside strictly static website, the task would be rather random:

You can't scan the source code in order to find the links, since links can be generated. Imagine the following case:

On a page, when a user effectuates an action, an image is added to the DOM (so you actually don't have any  element in HTML originally). The link to a image is assigned by JavaScript. In order to find a part of this link, JavaScript does an AJAX request; the other part is hardcoded in JavaScript code. The final URI is http://example.com/photos/nature/polar-bear.jpg?width=800

The server receives the request for the image and rewrites the URL to http://example.com/generate-photo.aspx?category=nature&name=polar-bear.jpg&width=800. It appears that the new URI points to a dynamic resource which generates the image by taking an existent one (/photos/catalog/133d6566-3c98-4690-be4a-caad41c0e21d.jpg) and adding a copyright.

Could you possibly track this situation automatically?

You can't rely on logs, since the fact that the resource was not requested for a while doesn't mean that it will never be requested.

The only viable alternative is to:

List every resource on the website,

Collect the statistics from the logs in order to filter the resources which were used for the past N months. Don't forget about a huge amount of small issues which can arise: remember that there is URL rewriting, that you need to canonize the requests, that there are default pages (http://example.com/index.html will mostly be called http://example.com/), etc.

Based on those statistics, forget about the resources which are in use: you don't need to remove them.

For the remaining resources, try to guess for each one the context in which it could be used, and check if it is. This last step is extremely complex for a program and requires human brain (or years and years of R&D).

As a side note, do you know that instead of Url.Content, ASP.NET MVC 4 allows to use ~ directly, like this:

```<code><a href="~/Products/Edit/458">Edit</a>
</code>```

Body:
Aside strictly static website, the task would be rather random:

You can't scan the source code in order to find the links, since links can be generated. Imagine the following case:

On a page, when a user effectuates an action, an image is added to the DOM (so you actually don't have any <img/> element in HTML originally). The link to a image is assigned by JavaScript. In order to find a part of this link, JavaScript does an AJAX request; the other part is hardcoded in JavaScript code. The final URI is http://example.com/photos/nature/polar-bear.jpg?width=800

The server receives the request for the image and rewrites the URL to http://example.com/generate-photo.aspx?category=nature&name=polar-bear.jpg&width=800. It appears that the new URI points to a dynamic resource which generates the image by taking an existent one (/photos/catalog/133d6566-3c98-4690-be4a-caad41c0e21d.jpg) and adding a copyright.

Could you possibly track this situation automatically?

You can't rely on logs, since the fact that the resource was not requested for a while doesn't mean that it will never be requested.

The only viable alternative is to:

List every resource on the website,

Collect the statistics from the logs in order to filter the resources which were used for the past N months. Don't forget about a huge amount of small issues which can arise: remember that there is URL rewriting, that you need to canonize the requests, that there are default pages (http://example.com/index.html will mostly be called http://example.com/), etc.

Based on those statistics, forget about the resources which are in use: you don't need to remove them.

For the remaining resources, try to guess for each one the context in which it could be used, and check if it is. This last step is extremely complex for a program and requires human brain (or years and years of R&D).

As a side note, do you know that instead of Url.Content, ASP.NET MVC 4 allows to use ~ directly, like this:

<a href="~/Products/Edit/458">Edit</a>


问:
One dimensional cutting algorithm with minimum waste
Can anybody point me to some resources about "cutting algorithm"?

The problem:

have rods with length of L meters, e.g. 6 m

need cut smaller pieces of different lengths, e.g. need:

4 x 1.2m

8 x 0,9m

etc... (many other lengths and counts)

How to determine the optimal cutting, what will produce the minimum wasted material? I'm capable write an perl program, but haven't any idea about the algorithm. (if here is already some CPAN module what can help, would be nice).

In addition, I need to take care about the "cutting line width" too, which means that from the 6m long rod it is impossible to cut 6 x 1m, because the cutting itself takes "3mm" width, so it is possible cut only 5 x 1m and the last piece will be only 98.5 cm (1m minus 5 x 3mm cut-width).

答:
This sounds like the Bin Packing Problem where the bins are the size of your rods and the object sizes are the lengths of material required. See also stackoverflow.com/questions/tagged/bin-packing

Following comments, it's known as the Cutting Stock Problem


问:
Refactoring and Open / Closed principle
I have recently being reading a web site about clean code development (I do not put a link here because it is not in English).

One of the principles advertised by this site is the Open Closed Principle: each software component should be open for extension and closed for modification. E.g., when we have implemented and tested a class, we should only modify it to fix bugs or to add new functionality (e.g. new methods that do not influence the existing ones). The existing functionality and implementation should not be changed.

I normally apply this principle by defining an interface I and a corresponding implementation class A. When class A has become stable (implemented and tested), I normally do not modify it too much (possibly, not at all), i.e.

If new requirements arrive (e.g. performance, or a totally new implementation of the interface) that require big changes to the code, I write a new implementation B, and keep using A as long as B is not mature. When B is mature, all that is needed is to change how I is instantiated.

If the new requirements suggest a change to the interface as well, I define a new interface I' and a new implementation A'. So I, A are frozen and remain the implementation for the production system as long as I' and A' are not stable enough to replace them.

So, in view of these observation, I was a bit surprised that the web page then suggested the use of complex refactorings, "... because it is not possible to write code directly in its final form."

Isn't there a contradiction / conflict between enforcing the Open / Closed Principle and suggesting the use of complex refactorings as a best practice? Or the idea here is that one can use complex refactorings during the development of a class A, but when that class has been tested successfully it should be frozen?

答:
Refactoring, by definition, is changing code structure without changing behavior. So when you refactor, you don't add new features.

What you did as an example for the Open Close principle sounds OK. This principle is about extending existing code with new features.

However, don't get this answer wrong. I do not imply that you should only do features or only do refactoring for big chunks of data. The most common way of programming is doing a little bit of a feature than immediately doing a little bit of refactoring (combined with tests of course to make sure you did not change any behavior). Complex refactoring does not mean "big" refactoring, it means applying complicated and well thought refactoring techniques.

About the SOLID principles. They are really good guidelines for software development but they are no religious rules to be blindly followed. Sometimes, many times, after you add a second and third and n-th feature, you realize that your initial design, even if it respects Open-Close, it does not respect other principles or software requirements. There are points in the evolution of a design and of a software when more complex changes has to be done. The whole point is to find and realise these problems as soon as possible and apply refactoring techniques as well as possible.

There is no such thing as perfect design. There is no such design that can and should respect all existing principles or patterns. That is coding utopia.

I hope this answer helped you in your dilemma. Feel free to ask for clarifications if needed.

Title: Refactoring and Open / Closed principle


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

答:
I know companies where the QA team is responsible for releases. This means that they have the power to block a release due to lack of quality. If an issue is reported in the field, they are the first in the line of fire (well right after the field engineer).

Typically they have higher domain knowledge. They tend to know the overall functionality of the product better while developers concentrate on their module/features.

Also I know of QA orgs where they have to write their own test tools. Not to mention automating the whole stuff. I am a developer, and have always valued QA guys who test my features.

At least in my organization, QA are treated equally with developers. I think it is because of the domain (telecom) where protocol and network architecture knowledge is equally valued with programming skills.

Title: Are testers considered low profile?

ContentLicense: CC BY-SA 2.5


答:
I think of the Open-Closed principle as a design goal.  If you end up having to violate it, then that means your initial design failed, which is certainly possible, and even likely.

Refactoring means you're changing the design without changing the functionality.  Likely you're changing your design because there's a problem with it.  Perhaps the problem is that it's difficult to follow the open-closed principle when making modifications to the existing code, and you're trying to fix that.

You might be doing a refactoring to make it possible to implement your next feature without violating the OCP when you do it.

Title: Refactoring and Open / Closed principle

Body:
I have recently being reading a web site about clean code development (I do not put a link here because it is not in English).

One of the principles advertised by this site is the Open Closed Principle: each software component should be open for extension and closed for modification. E.g., when we have implemented and tested a class, we should only modify it to fix bugs or to add new functionality (e.g. new methods that do not influence the existing ones). The existing functionality and implementation should not be changed.

I normally apply this principle by defining an interface I and a corresponding implementation class A. When class A has become stable (implemented and tested), I normally do not modify it too much (possibly, not at all), i.e.

If new requirements arrive (e.g. performance, or a totally new implementation of the interface) that require big changes to the code, I write a new implementation B, and keep using A as long as B is not mature. When B is mature, all that is needed is to change how I is instantiated.

If the new requirements suggest a change to the interface as well, I define a new interface I' and a new implementation A'. So I, A are frozen and remain the implementation for the production system as long as I' and A' are not stable enough to replace them.

So, in view of these observation, I was a bit surprised that the web page then suggested the use of complex refactorings, "... because it is not possible to write code directly in its final form."

Isn't there a contradiction / conflict between enforcing the Open / Closed Principle and suggesting the use of complex refactorings as a best practice? Or the idea here is that one can use complex refactorings during the development of a class A, but when that class has been tested successfully it should be frozen?


问:
Why use other number bases when programming
My coworkers and I have been bending our minds to figuring out why anyone would go out of their way to program numbers in a base other than base 10.

I suggested that perhaps you could optimize longer equations by putting the variables in the correct base you are working with (for instance, if you have only sets of 5 of something with no remainders you could use base 5), but I'm not sure if that's true.

Any thoughts?

答:
The computer (or more accurately the compiler) doesn't really care at all what number base you use in your source code. Most commonly used programming languages support bases 8 (octal), 10 (decimal) and 16 (hexadecimal) directly. Some also sport direct support for base 2 (binary) numbers. Specialized languages may support other number bases as well. (By "directly support", I mean that they allow entry of numerals in that base without resorting to mathematical tricks such as bitshifting, multiplication, division etc. in the source code itself. For example, C directly supports base-16 with its 0x number prefix and the regular hexadecimal digit set of 0123456789ABCDEF. Now, such tricks may be useful to make the number easier to understand in context, but as long as you can express the same number without them, doing so - or not - is only a convenience.)

In the end, however, that is inconsequential. Let's say you have a statement like this following:

```<code>int n = 10;
</code>```

The intent is to create an integer variable and initialize it with the decimal number 10. What does the computer see?

```<code>i  n  t     n     =     1  0  ;
69 6e 74 20 6e 20 3d 20 31 30 3b (ASCII, hex)
</code>```

The compiler will tokenize this, and realize that you are declaring a variable of type int with the name n, and assign it some initial value. But what is that value?

To the computer, and ignoring byte ordering and alignment issues, the input for the variable's initial value is 0x31 0x30. Does this mean that the initial value is 0x3130 (12592 in base 10)? Of course not. The language parser must keep reading the file in the character encoding used, so it reads 1 0 followed by a statement terminator. Since in this language base 10 is assumed, this reads (backwards) as "0 ones, 1 tens, end". That is, a value of 10 decimal.

If we specified a value in hexadecimal, and our language uses 0x to specify that the following value is in hexadecimal, then we get the following:

```<code>i  n  t     n     =     0  x  1  0  ;
69 6e 74 20 6e 20 3d 20 30 78 31 30 3b (ASCII, hex)
</code>```

The compiler sees 0x (0x30 0x78) and recognizes that as the base-16 prefix, so looks for a valid base-16 number following it. Up until the statement terminator, it reads 10. This translates to 0 "ones", 1 "sixteens", which works out to 16 in base 10. Or 00010000 in base 2. Or however else you like to represent it.

In either case, and ignoring optimizations for simplicity's sake, the compiler allots enough storage to hold the value of an int type variable, and places there the value it read from the source code into some sort of temporary holding variable. It then (likely much later) writes the resulting binary values to the object code file.

As you see, the way you write numerical values in the source code is completely inconsequential. It may have a very slight effect on compile times, but I would imagine that (again, ignoring such optimizations such as disk caching by the operating system) things like random turbulence around the rotating platters of the disk, disk access times, data bus collisions, etc., have a much greater effect.

Bottom line: don't worry about it. Write numbers in a base that your programming language of choice supports and which makes sense for how the number will be used and/or read. You spent far more time reading this answer than you will ever recover in compilation times by being clever about which number base to use in source code. ;)

Body:
The computer (or more accurately the compiler) doesn't really care at all what number base you use in your source code. Most commonly used programming languages support bases 8 (octal), 10 (decimal) and 16 (hexadecimal) directly. Some also sport direct support for base 2 (binary) numbers. Specialized languages may support other number bases as well. (By "directly support", I mean that they allow entry of numerals in that base without resorting to mathematical tricks such as bitshifting, multiplication, division etc. in the source code itself. For example, C directly supports base-16 with its 0x number prefix and the regular hexadecimal digit set of 0123456789ABCDEF. Now, such tricks may be useful to make the number easier to understand in context, but as long as you can express the same number without them, doing so - or not - is only a convenience.)

In the end, however, that is inconsequential. Let's say you have a statement like this following:

int n = 10;

The intent is to create an integer variable and initialize it with the decimal number 10. What does the computer see?

i  n  t     n     =     1  0  ;
69 6e 74 20 6e 20 3d 20 31 30 3b (ASCII, hex)

The compiler will tokenize this, and realize that you are declaring a variable of type int with the name n, and assign it some initial value. But what is that value?

To the computer, and ignoring byte ordering and alignment issues, the input for the variable's initial value is 0x31 0x30. Does this mean that the initial value is 0x3130 (12592 in base 10)? Of course not. The language parser must keep reading the file in the character encoding used, so it reads 1 0 followed by a statement terminator. Since in this language base 10 is assumed, this reads (backwards) as "0 ones, 1 tens, end". That is, a value of 10 decimal.

If we specified a value in hexadecimal, and our language uses 0x to specify that the following value is in hexadecimal, then we get the following:

i  n  t     n     =     0  x  1  0  ;
69 6e 74 20 6e 20 3d 20 30 78 31 30 3b (ASCII, hex)

The compiler sees 0x (0x30 0x78) and recognizes that as the base-16 prefix, so looks for a valid base-16 number following it. Up until the statement terminator, it reads 10. This translates to 0 "ones", 1 "sixteens", which works out to 16 in base 10. Or 00010000 in base 2. Or however else you like to represent it.

In either case, and ignoring optimizations for simplicity's sake, the compiler allots enough storage to hold the value of an int type variable, and places there the value it read from the source code into some sort of temporary holding variable. It then (likely much later) writes the resulting binary values to the object code file.

As you see, the way you write numerical values in the source code is completely inconsequential. It may have a very slight effect on compile times, but I would imagine that (again, ignoring such optimizations such as disk caching by the operating system) things like random turbulence around the rotating platters of the disk, disk access times, data bus collisions, etc., have a much greater effect.

Bottom line: don't worry about it. Write numbers in a base that your programming language of choice supports and which makes sense for how the number will be used and/or read. You spent far more time reading this answer than you will ever recover in compilation times by being clever about which number base to use in source code. ;)


问:
How to check if my open source idea already exists?
I've got a great idea for an open source project. What should I do before starting, to make sure that I'm not duplicating anyone's efforts?

Of course I've googled, but which keywords to use isn't obvious. Is there a site to discuss such ideas?

To address a common answer: My goal is not to be the author of a successful project. It is to make sure that this product exists, and can be improved. (There's already a similar commercial venture, which is of low quality and not being developed.) Thus, it won't help me to have the only project that can be found in this niche. If there's a start out there, I'd like to find it and help.

答:
Of course I've googled, but which keywords to use isn't obvious. Is there a site to discuss such ideas?

If it not easily find-able it may as well not exist, so you aren't duplicating efforts.


答:
First off it is often good to have more than one project in a certain space.  I am glad that there is more than one open source database for instance.  If you plan on implementing it in a specific language try that language's favorite source code hang outs, Perl's CPAN, Python's Pypi, Haskell's Cabal, Ruby's gems, etc...

Give it a try, if it is a duplicate of someone else's work you get the question how is this different than project X.  That way you can outsource the search to the community.

Title: How to check if my open source idea already exists?

Body:
I've got a great idea for an open source project. What should I do before starting, to make sure that I'm not duplicating anyone's efforts?

Of course I've googled, but which keywords to use isn't obvious. Is there a site to discuss such ideas?

To address a common answer: My goal is not to be the author of a successful project. It is to make sure that this product exists, and can be improved. (There's already a similar commercial venture, which is of low quality and not being developed.) Thus, it won't help me to have the only project that can be found in this niche. If there's a start out there, I'd like to find it and help.


答:
Put yourself in the shoes of the person that's going to come looking for your product. What problem have they just hit? What are they going to search for?

If you can't figure that out, it doesn't matter if you're the only product in the marketplace, you're going to have a terrible time getting people to use it.

If you can figure it out, it doesn't matter if there are 20 identical products, if they can't be found and yours can.


答:
To me, the Open-Closed Principle is a guideline, not a hard and fast rule.

With regard to the open part of the principle, final classes in Java and classes in C++ with all constructors declared as private violate the open part of the open-closed principle. There are good solid use cases (note: solid, not SOLID) for final classes. Designing for extensibility is important. However, this takes a good deal of foresight and effort, and you are always skirting the line of violating YAGNI (you ain't gonna need it) and injecting the code smell of speculative generality. Should key software components be open for extension? Yes. All? No. That in itself is speculative generality.

With regard to the closed part, when going from version 2.0 to 2.1 to 2.2 to 2.3 of some product, not modifying behavior is a good very idea. Users really don't like it when every minor release breaks their own code bade. However, along the way one often finds that the initial implementation in version 2.0 was fundamentally broken, or that external constraints that limited the initial design no longer apply. Do you grin and bear it and maintain that design in release 3.0, or do you make 3.0 non-backward compatible in some regard? Backward compatibility can be a huge constraint. Major release boundaries are the place where breaking backward compatibility is acceptable. You do need to beware that doing this might get your users upset. There has to be a good case for why this break with the past is needed.

Title: Refactoring and Open / Closed principle


答:
In the financial industry, there is an identifier scheme that is effectively base 36.  It uses the numbers 0-9 and letters B-Z to represent digits valued 0-35.  It skips the vowels to prevent any obnoxious names from being generated.

It's not perfect, however.  There was a time when one unfortunate company had the id B000BZ.

Title: Why use other number bases when programming

Body:
My coworkers and I have been bending our minds to figuring out why anyone would go out of their way to program numbers in a base other than base 10.

I suggested that perhaps you could optimize longer equations by putting the variables in the correct base you are working with (for instance, if you have only sets of 5 of something with no remainders you could use base 5), but I'm not sure if that's true.

Any thoughts?


问:
What is the difference between functional relational programming and functional programming?
After reading both this thread and the linked paper, I don't understand how FRP (functional relational programming) is different from (FP) functional programming.

Does FRP augment or replace FP?  Can FRP be implemented as a library in an FP language?

答:
Functional relational programming seems to be, just as the name suggests, a blend of both functional programming and the relational model. I think this sentence pretty much sums it up (p. 42):

In FRP all essential state takes the form of relations, and the essential
  logic is expressed using relational algebra extended with (pure) user defined
  functions.

Functional programming removes state from the equation and deals only with pure functions (no side effects). This is supposed to make things easier on everyone by preventing data manipulation from being hidden therefore making it easier to reason about the program.  FP is a beautiful ideal but in real life applications state is necessary and often useful. It is of course possible to have state in FP it's just a little more involved.

Based on a quick glance at the paper it seems they're trying to simplify FP by allowing state in a tightly controlled manner. Relational data is well structured and easy to reason about and functional programs are easy to reason about (maybe not in the human sense mind you) so let's augment FP with R and make everyone's state-loving live easier.


答:
In layman's words:

A. O/C principle means that specialization must be done by extending, not by modifying a class to accommodate for specialized needs.

B. Adding missing ( not specialized ) functionality means the design was not complete and you have to add it to the base class, obviously without violating the contract. I think this is not violating the principle.

C. Refactoring doesn't violate the principle.

When a design matures, say, after some time in production:

There should be very little reasons to do so ( point B ), tending to zero over time.

( Point C ) will always be possible although more infrequent.

All new functionality is supposed to be a specialization, meaning the classes must be extended (inherited from) ( point A ).

Title: Refactoring and Open / Closed principle


问:
Where should "display functions" live in an MVC web app?
I'm using the Yii Framework which is an MVC php framework that is pretty similar to your standard web-based MVC framework.  I want to display the related data from a many-to-many table as a list of strings in my view.

Assuming a table schema like:

```<code>tag { id, name }
post { id, title, content, date }
post_tag { post_id, tag_id }
</code>```

A post will display like:

```<code>Date: 9/27/2012
Title: Some Title
Content: blah blah blah...
Tags: Smart Funny Cool Informative
</code>```

I can achieve this by doing something like this in my Post view:

```<code><?php
  echo join(' ',
           array_map(function($tag) { return $tag->name; }, $model->tags));
?>
</code>```

(where $model->tags is an array of Tag objects associated with my model)

My questions are:

Is this amount of code/logic okay in the view? (Personally I think I'd rather just reference a property or call a single function.)

If not, where should this code live? In the model? the controller? a helper?

Potentially I may want to use in in other views as well.  Ultimately I think its purely a display issue which would make me think it should be in the view, but then I have to repeat the code in any view I want to use it in.

答:
If it is a function specifically oriented at structuring output, I would put it into a view helper.

However if the code touches some logic, it should move to a controller or model or way down to your business logic classes, depending on what is your code doing or what is you structure.

I personally would put your code in a view helper.


答: I think would be a fine thing to put into a view or view-helper. My rationale is that you're passed all the data and printing out the array with a space in-between is part of the view. If you were to implement another set of views for mobile or something, it could possibly be implemented differently, and if you used a web-service you'd definitely do it differently. </p>

Title: Where should "display functions" live in an MVC web app?

Body:
I'm using the Yii Framework which is an MVC php framework that is pretty similar to your standard web-based MVC framework.  I want to display the related data from a many-to-many table as a list of strings in my view.

Assuming a table schema like:

```<code>tag { id, name }
post { id, title, content, date }
post_tag { post_id, tag_id }
</code>```

A post will display like:

```<code>Date: 9/27/2012
Title: Some Title
Content: blah blah blah...
Tags: Smart Funny Cool Informative
</code>```

I can achieve this by doing something like this in my Post view:

```<code><?php
  echo join(' ',
           array_map(function($tag) { return $tag->name; }, $model->tags));
?>
</code>```

(where $model->tags is an array of Tag objects associated with my model)

My questions are:

Is this amount of code/logic okay in the view? (Personally I think I'd rather just reference a property or call a single function.)

If not, where should this code live? In the model? the controller? a helper?

Potentially I may want to use in in other views as well.  Ultimately I think its purely a display issue which would make me think it should be in the view, but then I have to repeat the code in any view I want to use it in.


问:
Dynamic Forms: Pattern or AntiPattern?
I'm sure you've seen it.  The database has a bunch of tables called Forms, Controls,FormsControls, ControlSets, Actions and the program that queries these tables has a dynamically generated user interface.  It will read all the forms, load a home page that has links to them all, or embed them in some tabbed or paged home page, and for each of those forms it will read the various text boxes, check boxes, radio buttons, submit buttons, combo boxes, labels and whatnot from the controls and form-to-control join tables, lay those elements out according to the database and link all the controls to logic according to other rules in the database.

To me, this is an anti-pattern.  It actually make the application more difficult to maintain because the design of it is now spread out into multiple different systems.  Also, the database is not source controlled.  Sure, it may make one or two changes go more quickly, after you've analyzed the program anyway to understand how to change the data and as long as you don't stray from the sort of changes that were anticipated and accounted for, but that's often just not sustainable.

What say you?

答:
It's not an anti-pattern in general. It's no different from how programming languages, browsers and report generators work.

Can a particular implementation of this method be or become an anti-pattern? Yes, just like any other program. As always, the devil is in the details. Also, as others have noted, complexity is perhaps the biggest challenge when creating this kind of program.

I've written several programs like this, mostly report generators and content presentation systems, and I've tried to keep them as simple as possible. I try to use kind of a "fast food" method to provide mass customization. The idea is to limit user choices to a set number of base items and the way to put them together while allowing the user to have limited control over certain elements.

Where the over-complexity comes in, it's usually a result of programmer "gold plating" and/or excessive user demands. In some cases, it's better to use an off-the-shelf power user oriented product (like SSRS, Access or Hyperion Reporting suite) than trying to reinvent the wheel.

Title: Dynamic Forms: Pattern or AntiPattern?


问:
Can Win32 message loops survive being ported to native linux?
I would like to port a large Win32 DLL to native linux in C++.  I don't think I can use Wine for a DLL like mine, because users of the DLL would then also have to be in Wine, and then they would all whine...  As a Windows C++ programmer, I don't (yet) have any familiarity with the GUI front-end services in linux, but if it logically runs on anything like win32 message loops, fonts, bitmaps, invalidation regions, getmessage( ) calls and so forth, it should be a fairly straight forward remapping of my existing code.

So what am I looking at here, a remap or a rewrite? The path for such things must be well worn by now.

答:
Why not consider using Qt or some cross-platform library to solve this question?

Does your solution have GUI related core or just processing functions? Pure C/C++ cross-platform coding would be enough in this case.


问:
Long lines of text in source code

Possible Duplicate:

  Is the 80 character limit still relevant in times of widescreen monitors?

I used to set a vertical line set at 80 characters in my text editor and then I added carriage returns if the lines got too long.  I later increased the value to 135 characters.  I started using word wrap and not giving myself a limit but tried to keep lines short if I could because it took a lot of time shortening my lines.

People at work use word wrap and don't give themselves a limit.. is this the correct way?

What are you meant to do ?  Many thanks.

答: Opinions differ wildly on this matter. The best thing to do is to follow the same style as the rest of your team. It helps if the style is codified in a style guide so you can all argue about what's best in a productive way.</p>

Title: Long lines of text in source code


答:
It depends on your team norms. Some people want the 80 character limit, some could care less.

The focus though is on readability. If code goes off the screen it tends to be unreadable. If it wraps around, that tends to be unreadable too. It's often better to refactor the code to simply not be too long.

What's "too long"? Most places I've been have had the same monitors, and the same IDEs with the same fonts. Baring some team norm, I would work off of "if your code goes off your standard screen using a full screen IDE with the standard font and configuration... then it's too long."

Title: Long lines of text in source code

Body:
Possible Duplicate:

  Is the 80 character limit still relevant in times of widescreen monitors?

I used to set a vertical line set at 80 characters in my text editor and then I added carriage returns if the lines got too long.  I later increased the value to 135 characters.  I started using word wrap and not giving myself a limit but tried to keep lines short if I could because it took a lot of time shortening my lines.

People at work use word wrap and don't give themselves a limit.. is this the correct way?

What are you meant to do ?  Many thanks.


答:
From my experience and from some random statistical data you can find on the Internet, the best is to keep lines at a maximum of 120 characters. That is about how much is comfortable for a human to read in a single line and also it does not require horizontal scrolling on most displays today.

I am strongly recommending to anyone to put and respect a limit because not all editors have a word-wrap feature and not all programmers enable word-wrap in their IDEs. In fact I do not personally know anyone who uses word-wrap in source code.

Word wrap can also be confusing when the code suddenly breaks the line in places that would lead to errors if there would be real new line at that point.

Title: Long lines of text in source code


问:
Should HTTP Verbs Be Used Semantically?
If I'm making a web application which integrates with a server-side backend, would it be considered best practice to use HTTP methods semantically? That is, for example, if I'm fetching data (e.g., to populate a menu, etc.), I would use GET, but to update data (e.g., save a record), I would use POST. (I realise there are other methods that may be even more appropriate, but we need to consider browser support.)

I can see the benefits of this in the sense that it's effectively a RESTful API, but at a slightly increased development cost. In my previous projects, I've POST'd everything: Is it worth switching to a RESTful mindset simply for the sake of best practice?

答:
My answer is simply: yes.

There are cool advantages also, like you can get stuff directly by accessing URLs from different parts of you application. Than when you post things you are covered and you don't expose stuff.

If you respect the verbs in you classes in whatever programming language you use, it will also help to better structure your code. Classes that are sending data will more naturally separate from those which are receiving or searching for information.

Title: Should HTTP Verbs Be Used Semantically?


问:
Why do Git users say that Subversion does not have all the source code locally?
I'm only going on what I've read on SO, so forgive me, but all I read says that one major advantage of Git over Subversion is that Git gives all the source code to the developer locally, not having to do anything on the server.

With my limited using of SVN and TortoiseSVN, I had all the source code, or at least I thought I did.  For example, I have a website.  I upload it to SVN.  I am still running my website locally, aren't I?  If someone submits a change and I'm not connected, it wouldn't matter if I had Git or not, until I reconnect to the server.

I do not understand.  I'm not asking for a rehash of one vs. the other except this one point.

答:
The premise you are questioning really is wrong:

that one major advantage of Git over Subversion is that Git gives all the source code to the developer locally

With both Subversion and Git you have your source code locally. With Git you have both your source code and a repository on your local machine.

It goes something like this.

Subversion:

Your code <-> The Repository

Git:

Your code <-> Your local repository <-> A remote repository (... <-> another remote repo, and so on)

One benefit you get from this structure is that you can still use source control and commit your local changes to your local repository without disturbing the work of other team members (with whom you share the remote repository).

With Subversion you'd have to either risk breaking the build for other people or suffer prolonged local development without any source control which ends with a huge commit (or more likely a revert).

With Git, on the other hand, you'd feel free to commit these changes to your local repository, view logs and diffs or your changes, and only when you feel it is ready to be shared with the team push the changes from the local repository to the remote one.


答:
It depends on how your source code will be used/by whom.

If it will be printed with monospace font or shown through terminal use 80 characters.

If others with smaller monitors will look at it, use some limit to acomodate them (eg 80, but it can be more, but 80 is safe).

Another point of view, try to not use so long lines (sometimes it is unavoidable, often it is avoidable (and sometimes avoiding it is not worth it)).
Long lines are from:
1) too deep indentation (introduce functions)
2) too much done on one line
3) method chaining
4) too much parameters for one function
5) too long indentifiers

all of them are code smells (at least for someone).

if method declaration gets too long (without having enormous ammount of parameters), puting one parameter per line can be much more readable than wrapped line or scrolling to read it.

Title: Long lines of text in source code


答: Git or Mercurial store your whole repository locally with all revisions and named branches. Subversion only stores one - usually the Head Revision. So with Git and Mercurial you can access the full repository (i.e. your current source code and its history) even when your network breaks down with SVN you are restricted to the last revision you updated to.

Title: Why do Git users say that Subversion does not have all the source code locally?

Body:
I'm only going on what I've read on SO, so forgive me, but all I read says that one major advantage of Git over Subversion is that Git gives all the source code to the developer locally, not having to do anything on the server.

With my limited using of SVN and TortoiseSVN, I had all the source code, or at least I thought I did.  For example, I have a website.  I upload it to SVN.  I am still running my website locally, aren't I?  If someone submits a change and I'm not connected, it wouldn't matter if I had Git or not, until I reconnect to the server.

I do not understand.  I'm not asking for a rehash of one vs. the other except this one point.


答:
I think what you may be getting at is that with SVN, all your actions require communication with the server, where as GIT does not.  With SVN, if you want to branch, you branch on the server and pull down that branch.  With GIT, you could create a local branch without ever having the "server" know about it.

You're correct in saying that you have the source code with both SVN and GIT, but with GIT, there doesn't have to be a centralized server that contains the source code as well.  With GIT, you may be the ONLY person with the source code, yet still be able to do all the functions that you would with a typical VCS.

I've heard arguments against GIT, and I think this may help with your question, saying that since you're not required to commit to a central repo, you own your source code until you have committed and pushed it to your server, if you have one.  With SVN, the only way to have the version control is by committing to the server, but with GIT, you could potentially keep everything on your local machine and if any goes wrong, you "could lose everything" even though you could just as easily lose all your changes with SVN if you didn't commit and your HDD crashed as well.


答:
The Open-Closed principle is more of an indicator of how well your software is designed; not a principle to follow literally. It is also a principle that helps to keep us from accidentally changing existing interfaces (classes & methods you call and how you expect them to work).

The goal is to write quality software. One of these qualities is extendability. This means it's easy to add, remove, change code with those changes tending to be limited to as few existing classes as practical. Adding new code is less risky than changing existing code so in this regard Open-Closed is a good thing to do. But what code are we talking about exactly? The crime of violating O-C is much less when you can add new methods to a class instead of needing to alter existing ones.

O-C is fractal. It apples at all depths of your design. Everyone assumes it is only applied at the class level. But it is equally applicable at the method level or at the assembly level.

Too frequent violation of O-C at the appropriate level is suggesting that maybe it's time to refactor. "Appropriate level" is a judgement call that has everything to do with your overall design.

Following Open-Closed literally means the number of classes will explode. You'll create (capital "I") Interfaces unnecessarily. You'll end up with bits of functionality spread across classes and you then have to write lots more code to wire it all together. At some point it will dawn on you that changing the original class would have been better.

Title: Refactoring and Open / Closed principle


答:
The Open-Closed principle seems to be a principle that appeared before TDD was more prevalent. The idea being that it's risky to refactor code because you might break something so it's safer to leave existing code as is and simply add to it. In the absence of tests this makes sense. The downside to this approach is code atrophy. Each time you extend a class rather than refactoring it you end up with an extra layer. You're simply bolting code on top. Every time you bolt more code on you're increasing the chance of duplication. Imagine; there's a service in my codebase that I want to use, I find it doesn't have what I want so I create a new class to extend it and include my new functionality. Another developer comes along later and also wants to use the same service. Unfortunately, they don't realise that my extended version exists. They code against the original implementation but they also need one of the features that I coded. Instead of using my version they now also extend the implementation and add the new feature. Now we've got 3 classes, the original one and two new versions that have some duplicated functionality. Follow the open/closed principle and this duplication will continue to build up over the life time of the project leading to a needlessly complex code base.

With a well tested system there is no need to suffer this code atrophy, you can safely refactor code allowing your design to assimilate new requirements rather than having to continually bolt on new code. This style of development is called emergent design and leads to code bases that are able to stay in good shape over their entire lifetime rather than gradually collecting cruft.

Title: Refactoring and Open / Closed principle


问:
Github Workflow: Pushing small fix branches to remote, or keep them local?
In Scott Chacon's workflow (explained eg in this SO answer), with essentially two silos (development, and master), if, say I have a small bug to fix (e.g. can be fixed with a few characters) is the optimal way of doing that:

a) branch off of development a branch called e.g. fix_123. Push this branch to origin as I work on it. When it's done, code-reviewed, whatever, merge into development and push development to origin.

b) Same as above, but without pushing fix_123 to origin.

答:
Ideally push it to origin as that means everybody else will see that someone else is working on a fix. Also even though something is a small fix when measured by number of charecters it can make a huge difference in execution so the size of the fix shouldn't make any difference to the way you fix it.

However practically when I used git it took so long to sync that I'd bundle a group of small fixes together and just let other devs know by email that I was working on them.


答:
Reason #1: because all numbers at the circuit level are represented in base-2 (electrical switch is on or off).
Reason #2: because at one level higher than the actual circuits, bits are grouped into bytes, and bytes can be easily represented as two hexadecimal digits, when it would take 3 decimal digits (and some validation) to represent all possible values of the byte.

So, if you are working at these levels (or approximating them, in some managed environment), it is easier to work in binary or hexadecimal than decimal. The situations in which you would do this are varied, but are typically never situations where you just need basic arithmetic.


问:
What is the difference between "good" designers and "great" designers?
While reading this wikipedia article, Brookes has told that there is a difference between "good" designers and "great" designers.  What is the difference between them? How can I decide if a designer is good or great?</p>

答:
A great designer catches the intent of what I want to accomplish and improves on it to my delight. A good designer follows a specification to the letter, but creativity shows in how they did that.

A bad designer is, well, none of the above.

I think 'exceptional' is always in the eye of the client, and the people they hope to reach.

Other things come into play in the 'great' category, such as someone who can articulate why my 'vision' of something might be skewed. I guess it boils down, mostly to how much ownership someone takes in any given project, given a group of people with similar skills.

Great, is also, entirely subjective.


答:
It really depends on this. I commit frantically locally but only commit (presumably working) milestones to the remote repository. Historically, the 1000's of local commits don't add as much value to the greater code base as the feature level stuff does (IMO). It creates clutter (IMO).

If your fix_123 is a complete and functional commit, perhaps a bug fix or some other isolated task, it makes more sense to commit each of these to development. If bug number 10402030 is reported and your commit and push from local only encompasses the complete fix state that isn't such a bad thing.

One way to limit clutter on the remote repository is to squash some commits by rebasing like mentioned HERE. I only use git in personal projects outside of my paid work so if I am flawed in my methods I don't mind corrective comments.

On all this, version control practices can almost be like discussing religion. You will get wildly different opinions and practices but it really depends on what fits the project and organization.

Title: Github Workflow: Pushing small fix branches to remote, or keep them local?

Body:
In Scott Chacon's workflow (explained eg in this SO answer), with essentially two silos (development, and master), if, say I have a small bug to fix (e.g. can be fixed with a few characters) is the optimal way of doing that:

a) branch off of development a branch called e.g. fix_123. Push this branch to origin as I work on it. When it's done, code-reviewed, whatever, merge into development and push development to origin.

b) Same as above, but without pushing fix_123 to origin.


问:
Ruby on rails not popular in big international IT companies?
Is the ROR used only in startups or also in bigger companies as well?

What should be the reasons of their preference of Java over ROR?

答:
Ruby is often seen as a solution for when you need something fast (and quick and dirty).  It also is seen as lacking scalability for large systems.

Large companies typically are not after "quick and dirty" or after the time to market that a quicker solution would provide.  The large company is not going for a cycle from design to release in a matter of weeks and is more often on the time from design to release on the order of months (sometimes years).

One advantage of ruby is the smaller technology stack necessary to go out.  It is quite similar in that respect to php+mysql for a web app.  The large companies are more likely dealing with an already existing (for example) java+weblogic+oracle stack that has been in place for a decade.  There is no advantage for the large company to switch to something smaller when they already have the larger stack in place.


答:
That's my impression as well: ROR is used more by startups, Java in big companies.

First of all, different languages have strengths/weaknesses for different applications.  Ruby is a language; Ruby on Rails is a framework for creating web apps.  C++ isn't very suited to web apps, the only one I know of in C++ is ok cupid.  C and C++ are for high performance apps, e.g. databases, operating systems, what's generally referred to as "systems programming."

People often feel that dynamic languages like Ruby are harder to scale to lots of programmers or complicated programs, because of the lack of compile time checks.

Similarly, large companies are very conservative, so they're happy to slow down developers by having them write lots of boilerplate, as long as things mostly work in the end.

Title: Ruby on rails not popular in big international IT companies?

Body:
Is the ROR used only in startups or also in bigger companies as well?

What should be the reasons of their preference of Java over ROR?


答:
I would suggest you to visit this page on Quora. There are many answers which would give you an explanation.

The most appropriate answer on Quora is:

Many companies have systems that have to maintained for a long time, yet they do not have dedicated staff to maintain them. Rather, the system is written by some contractors, then just sits there until something new is needed, when a different set of contractors comes in, etc. With that approach, it is important that you use something standardized that is popular for this general type of system, so you can always find somebody to maintain it for you. Java and C# are very popular for writing big business automation systems, so there are many contractors who can write big business automation systems in them, so they remain popular for writing big business automation systems. This becomes a self-fulfulling prophecy, but that makes it no less convincing of an argument.

For similar reasons, it is important that you use something stable. With many dynamic/scripting languages like the ones you mentioned, 3 years is considered more than adequate notice to deprecate a language or library feature. With Java, on the other hand, you can still run a 10-year old program without modification. This is often very important to people doing business automation.

The presence of a big corporation backing a language and the associated set of libraries and tools reassures decision-makers in large corporations that support is good and won't go away soon. (Whether this is actually true is a whole 'nother question.) Python, PHP, and Ruby are all originally hobby/academic projects, and have grown some amount of corporate support, but mostly from rather small firms that do not impress your typical Fortune 500 CIO. C# is backed by Microsoft, and Java comes out of Sun, which may have gone under, but is still backed heavily by Oracle, IBM, and others.

Big business automation projects require different libraries and frameworks than typical dynamic web sites do. You want to be able to talk to Oracle and SAP, for instance. These sorts of frameworks and libraries tend to be for Java or C#, and this too is self-perpetuating.

Sometimes, Java or C# may actually be a technically better alternative. I mention this argument last, but it's not just to point out the logical possibility. For instance, Java has a decent threading model and there exist high-performance concurrent data structure libraries. The standard Python implementation has poorly implemented threading, and the standard PHP implementation has for all practical purposes no threading at all. Also, strong typing and compile-time name resolution, while slowing down exploratory programming, do increase the number of bugs that can be statically caught.

And now an admittedly slightly off topic remark: The question mentions languages with a lot of compile-time checking that are tedious to use, like Java and C#, and languages with very little compile-time checking that are not tedious to use, like Python and Ruby. For completeness, it must be said that the amount of compile time checking a language does need not necessarily correlate directly with the amount of boilerplate that you have to type to help it do so. Among the languages that have very tight compile-time checking but that are considerably cleverer than Java about inferring what it is they are supposed to check, ML (OCaml, Standard ML, F#), Haskell, and Scala are especially worth knowing about. Among these, Scala has the best chances to become truly mainstream, because it integrates so well with the mature and open source Java runtime and libraries.


答:
There are a lot of reasons why large multinationals prefer Java, C++ or .NET developers. For one thing, their systems were set with a platform using one of those languages before Ruby came along (same will hold true for Python in many respects). They also know that computer science departments train Java and C++ programmers, so there is a larger pool of potential applicants to hire from. These are basically the forces of inertia at work in large multinational firms.

There is also the issue of support. Java, especially Java EE, is supported by huge firms with mega budgets and a whole industry of training schemes. As is .NET. What about Ruby? People are still asking around on this forum for books about Ruby or how steep the learning curve is.

You and I probably agree that when it comes to developing web apps from scratch, ROR is the right tool for the job. However, if I were a CIO at a large multinational, I would see no benefit in switching my army of developers to a whole new language and framework. Nor could I sell that to my boss.


问:
Can you use Pi as a crude random number generator?
I recently saw this question over at math.SE. It got me thinking. Could Pi be used as a crude random number generator? I mean the results are well known(how long has pi been computed to now?) but, Pi does seem to be quite random when taken 1 digit at a time. </p>

<p>Does this make any sense at all? </p>

答:
Such generator would be a pseudo number generator, i.e. given the same seed, the result would always be the same. This being said, in most frameworks, when you use the standard random number generator, there is the same issue of being pseudo-random.

The distribution of the digits seems to be quite similar to the standard random number generators¹, so the digits of π can be used for ordinary random number generation scenarios.

The issue is that the algorithm will probably be very slow, compared to the ordinary random number generators, so it's not very useful in practice.

¹ I believe it's true, but don't have any proof. It would be interesting (and not to complicate) to do a comparison based on a large quantity of numbers.


答: Well, among other properties of a random number generator, you probably want it to be a normal number.  And several answers in the math.SE question that inspired your question point out that currently pi is believed to be normal, but it has not been proven.</p>

Title: Can you use Pi as a crude random number generator?

Body:
I recently saw this question over at math.SE. It got me thinking. Could Pi be used as a crude random number generator? I mean the results are well known(how long has pi been computed to now?) but, Pi does seem to be quite random when taken 1 digit at a time. </p>

<p>Does this make any sense at all? </p>


答:
Digging from http://www.befria.nu/elias/pi/binpi.html to get the binary value of pi (so that it was easier to convert into bytes rather than trying to use decimal digits) and then running it through ent I get the following for an analysis of the random distribution of the bytes:

Entropy = 7.954093 bits per byte.

Optimum compression would reduce the size of this 4096 byte file by 0
  percent.

Chi square distribution for 4096 samples is 253.00, and randomly would
  exceed this value 52.36 percent of the times.

Arithmetic mean value of data bytes is 126.6736 (127.5 = random).

Monte Carlo value for Pi is 3.120234604 (error 0.68 percent).

Serial
  correlation coefficient is 0.028195 (totally uncorrelated = 0.0).

So yes, using pi for random data would give you fairly random data... realizing that it is well known random data.

From a comment above...

Depending on what you are doing, but I think you can use the decimals
  of the square root of any prime number as a random number generator.
  These should at least have evenly distributed digits. – Paxinum

So, I computed the square root of 2 in binary to undetake the same set of problems.  Using Wolfram's Iteration I wrote a simple perl script

```<code>#!/usr/bin/perl
use strict;
use Math::BigInt;

my $u = Math::BigInt->new("2");
my $v = Math::BigInt->new("0");
my $i = 0;

while(1) {
    my $unew;
    my $vnew;

    if($u->bcmp($v) != 1) { # $u <= $v
        $unew = $u->bmul(4);
        $vnew = $v->bmul(2);
    } else {
        $unew = ($u->bsub($v)->bsub(1))->bmul(4);
        $vnew = ($v->badd(2))->bmul(2);
    }

    $v = $vnew;
    $u = $unew;

    #print $i,"  ",$v,"\n";
    if($i++ > 10000) { last; }
}

open (BITS,"> bits.txt");
print BITS $v->as_bin();
close(BITS);
</code>```

Running this for the first 10 matched A095804 so I was confident I had the sequence.  The value vn as when written in binary with the binary point placed after the first digit gives an approximation of the square root of 2.

Using ent against this binary data produces:

```<code>Entropy = 7.840501 bits per byte.

Optimum compression would reduce the size
of this 1251 byte file by 1 percent.

Chi square distribution for 1251 samples is 277.84, and randomly
would exceed this value 15.58 percent of the times.

Arithmetic mean value of data bytes is 130.0616 (127.5 = random).
Monte Carlo value for Pi is 3.153846154 (error 0.39 percent).
Serial correlation coefficient is -0.045767 (totally uncorrelated = 0.0).
</code>```

Body:
Digging from http://www.befria.nu/elias/pi/binpi.html to get the binary value of pi (so that it was easier to convert into bytes rather than trying to use decimal digits) and then running it through ent I get the following for an analysis of the random distribution of the bytes:

Entropy = 7.954093 bits per byte.

Optimum compression would reduce the size of this 4096 byte file by 0
  percent.

Chi square distribution for 4096 samples is 253.00, and randomly would
  exceed this value 52.36 percent of the times.

Arithmetic mean value of data bytes is 126.6736 (127.5 = random).

Monte Carlo value for Pi is 3.120234604 (error 0.68 percent).

Serial
  correlation coefficient is 0.028195 (totally uncorrelated = 0.0).

So yes, using pi for random data would give you fairly random data... realizing that it is well known random data.

From a comment above...

Depending on what you are doing, but I think you can use the decimals
  of the square root of any prime number as a random number generator.
  These should at least have evenly distributed digits. – Paxinum

So, I computed the square root of 2 in binary to undetake the same set of problems.  Using Wolfram's Iteration I wrote a simple perl script

#!/usr/bin/perl
use strict;
use Math::BigInt;

my $u = Math::BigInt->new("2");
my $v = Math::BigInt->new("0");
my $i = 0;

while(1) {
    my $unew;
    my $vnew;

    if($u->bcmp($v) != 1) { # $u <= $v
        $unew = $u->bmul(4);
        $vnew = $v->bmul(2);
    } else {
        $unew = ($u->bsub($v)->bsub(1))->bmul(4);
        $vnew = ($v->badd(2))->bmul(2);
    }

    $v = $vnew;
    $u = $unew;

    #print $i,"  ",$v,"\n";
    if($i++ > 10000) { last; }
}

open (BITS,"> bits.txt");
print BITS $v->as_bin();
close(BITS);

Running this for the first 10 matched A095804 so I was confident I had the sequence.  The value vn as when written in binary with the binary point placed after the first digit gives an approximation of the square root of 2.

Using ent against this binary data produces:

Entropy = 7.840501 bits per byte.

Optimum compression would reduce the size
of this 1251 byte file by 1 percent.

Chi square distribution for 1251 samples is 277.84, and randomly
would exceed this value 15.58 percent of the times.

Arithmetic mean value of data bytes is 130.0616 (127.5 = random).
Monte Carlo value for Pi is 3.153846154 (error 0.39 percent).
Serial correlation coefficient is -0.045767 (totally uncorrelated = 0.0).


问:
Creating a layer of abstraction over the ORM layer
I believe that if you have your repositories use an ORM that it's already enough abstracted from the database.

However, where I am working now, someone believe that we should have a layer that abstract the ORM in case that we would like to change the ORM later.

Is it really necessary or it's simply a lot of over head to create a layer that will work on many ORM?

Edit

Just to give more detail:

We have POCO class and Entity Class that are mapped with AutoMapper.
Entity class are used by the Repository layer. The repository layer
then use the additional layer of abstraction to communicate with
Entity Framework.

The business layer has in no way a direct access to Entity Framework. Even without the additional layer of abstraction over the ORM, this one need to use the service layer that user the repository layer. In both case, the business layer is totally separated from the ORM.

The main argument is to be able to change ORM in the future. Since it's really localized inside the Repository layer, to me, it's already well separated and I do not see why an additional layer of abstraction is required to have a "quality" code.

答:
The UnitOfWork usually provides this abstraction. It's one place that needs to change, your repositories depend on it via an Interface. If you ever need to change O/RM, just implement a new UoW over it. One and done.

BTW it goes beyond just switching O/RM, think of unit testing. I have three UnitOfWork implementations, one for EF, one for NH (because I actually DID have to switch O/RMs mid-project for a client who wanted Oracle support), and one for InMemory persistence. The InMemory persistence was perfect for unit testing or even for rapid prototyping before I was ready to put a database behind it.

The framework is simple to implement. First you have your generic IRepository interface

```<code>public interface IRepository<T>
  where T:class
{
  IQueryable<T> FindBy(Expression<Func<T,Bool>>filter);
  IQueryable<T> GetAll();
  T FindSingle(Expression<Func<T,Bool>> filter);
  void Add(T item);
  void Remove(T item);

}
</code>```

And the IUnitOfWork interface

```<code>public interface IUnitOfWork
{
   IQueryable<T> GetSet<T>();
   void Save();
   void Add<T>(T item) where T:class;
   void Remove<T>(T item) where T:class;
}
</code>```

Next is the base repository (your choice on whether or not it should be abstract

```<code>public abstract class RepositoryBase<T>:IRepository<T>
  where T:class
{
   protected readonly IUnitOfWork _uow;

   protected RepositoryBase(IUnitOfWork uow)
   {
      _uow=uow;
   }

   public IQueryable<T> FindBy(Expression<Func<T,Bool>>filter)
   {
      return _uow.GetSet<T>().Where(filter);
   }

   public IQueryable<T> GetAll()
   {
      return _uow.GetSet<T>();
   }

   public T FindSingle(Expression<Func<T,Bool>> filter)
   {
      return _uow.GetSet<T>().SingleOrDefault(filter);
   }

   public void Add(T item)
   {
      return _uow.Add(item);
   }

   public void Remove(T item)
   {
      return _uow.Remove(item);
   }
}
</code>```

Implementing IUnitOfWork is child's play for EF, NH, and In Memory. The reason I return IQueryable, is for the same reason, Ayende mentioned in his post, the client can further filter, sort, group, and even project the result using LINQ and you still get the benefit of it all being done server side.

Body:
The UnitOfWork usually provides this abstraction. It's one place that needs to change, your repositories depend on it via an Interface. If you ever need to change O/RM, just implement a new UoW over it. One and done.

BTW it goes beyond just switching O/RM, think of unit testing. I have three UnitOfWork implementations, one for EF, one for NH (because I actually DID have to switch O/RMs mid-project for a client who wanted Oracle support), and one for InMemory persistence. The InMemory persistence was perfect for unit testing or even for rapid prototyping before I was ready to put a database behind it.

The framework is simple to implement. First you have your generic IRepository interface

public interface IRepository<T>
  where T:class
{
  IQueryable<T> FindBy(Expression<Func<T,Bool>>filter);
  IQueryable<T> GetAll();
  T FindSingle(Expression<Func<T,Bool>> filter);
  void Add(T item);
  void Remove(T item);

}

And the IUnitOfWork interface

public interface IUnitOfWork
{
   IQueryable<T> GetSet<T>();
   void Save();
   void Add<T>(T item) where T:class;
   void Remove<T>(T item) where T:class;
}

Next is the base repository (your choice on whether or not it should be abstract

public abstract class RepositoryBase<T>:IRepository<T>
  where T:class
{
   protected readonly IUnitOfWork _uow;

   protected RepositoryBase(IUnitOfWork uow)
   {
      _uow=uow;
   }

   public IQueryable<T> FindBy(Expression<Func<T,Bool>>filter)
   {
      return _uow.GetSet<T>().Where(filter);
   }

   public IQueryable<T> GetAll()
   {
      return _uow.GetSet<T>();
   }

   public T FindSingle(Expression<Func<T,Bool>> filter)
   {
      return _uow.GetSet<T>().SingleOrDefault(filter);
   }

   public void Add(T item)
   {
      return _uow.Add(item);
   }

   public void Remove(T item)
   {
      return _uow.Remove(item);
   }
}

Implementing IUnitOfWork is child's play for EF, NH, and In Memory. The reason I return IQueryable, is for the same reason, Ayende mentioned in his post, the client can further filter, sort, group, and even project the result using LINQ and you still get the benefit of it all being done server side.


答:
The ORM provides an abstraction for your data layer to be independent of its RDBMS, but it may not be enough to "untie" your business layer from your data layer. Specifically, you should not let objects that map to RDBMS tables to "leak" directly into the business layer.

At the very least, your business layer needs to program to interfaces that your ORM-managed, table-mapped objects from the data layer could potentially implement. Additionally, you may need to create an interface-based layer of abstract query building to hide the native querying capabilities of your ORM. The main goal is to avoid "baking in" any particular ORM into your solution beyond its data layer. For example, it might be tempting to create HQL (Hibernate Query Language) strings in the business layer. However, this seemingly innocent decision would tie your business layer to Hibernate, thus nailing the business and the data access layers together; you should try to avoid this situation as much as possible.

EDIT : In your case, the additional layer inside the repository is a waste of time: based on your point number two, your business layer is sufficiently insulated from your repository. Providing additional insulation would introduce unnecessary complexity, with no additional benefits.

The problem with building an extra abstraction layer inside your repository is that the particular "brand" of ORM dictates the way you interact with it. If you build a thin wrapper that looks like your ORM, but is under your control, replacing the underlying ORM will be roughly as hard as it would be without that additional layer. If, on the other hand, you build a layer that does not look anything like your ORM, then you should question your choice of the object-relational mapping technology.

Title: Creating a layer of abstraction over the ORM layer

Body:
I believe that if you have your repositories use an ORM that it's already enough abstracted from the database.

However, where I am working now, someone believe that we should have a layer that abstract the ORM in case that we would like to change the ORM later.

Is it really necessary or it's simply a lot of over head to create a layer that will work on many ORM?

Edit

Just to give more detail:

We have POCO class and Entity Class that are mapped with AutoMapper.
Entity class are used by the Repository layer. The repository layer
then use the additional layer of abstraction to communicate with
Entity Framework.

The business layer has in no way a direct access to Entity Framework. Even without the additional layer of abstraction over the ORM, this one need to use the service layer that user the repository layer. In both case, the business layer is totally separated from the ORM.

The main argument is to be able to change ORM in the future. Since it's really localized inside the Repository layer, to me, it's already well separated and I do not see why an additional layer of abstraction is required to have a "quality" code.


答:
A good designer creates something that does the job well. A great designer also makes the user say "wow!!!".

A good designer knows the established standards, and applies them well. A great designer goes beyond that and creates new solutions that become new standards.

Title: What is the difference between "good" designers and "great" designers?

Body: While reading this wikipedia article, Brookes has told that there is a difference between "good" designers and "great" designers.  What is the difference between them? How can I decide if a designer is good or great?</p>


问:
Enforcing Constraints Upon Data Documents of Various Formats
This seems like the sort of problem that must have been solved elegantly long ago, but I haven't the foggiest how to google it and find it.

Suppose you're maintaining a large legacy system, which has a large collection of data (tens of GB) of various formats, including XML and two different internal configuration formats. Suppose further that there are abstract rules governing the values these files may or may not contain.

EXAMPLE: File A defines the raw, mathematical data pertaining to the aerodynamics of a car for consumption of the physics component of the system. File B contains certain values from File A in an easily accessible, XML hierarchy for consumption of a different component of the system. There exists, therefore, an abstract rule (or constraint) such that the values from File B must match the values from File A.

This is probably the simplest constraint that can be specified, but in practice, the constraints between files can become very complicated indeed.

What is the best method for managing these constraints between files of arbitrary formats, short of migrating it over to an RDBMS (which simply isn't feasible for the foreseeable future)? Has this problem been solved already?

To be more specific, I would expect the solution to at least produce notifications of violated constraints; the solution need not resolve the constraints.

==============================

Sample file structures

File A (JeepWrangler2011.emv):

```<code>MODEL JeepWrangler2011
{
    EsotericMathValueX 11.1
    EsotericMathValueY 22.2
    EsotericMathValueZ 33.3
}
</code>```

File B (JeepWrangler2011.xml):

```<code><model name="JeepWrangler2011">
  <!--These values must correspond File A's EsotericMathValues-->
  <modelExtent x="11.1" y="22.2" z="33.3"/>
  [...]
</model>
</code>```

EDIT: Reflecting on this issue, it seems to me that a software solution would require something like the following:

Develop an abstract language to describe the structure of arbitrary formats.

Develop an abstract language to describe constraints between files.

Develop a tool that consumes format-structure-descriptions (item 1), constraint-declarations (item 2), and a file that maps various files (pointed to by file paths) to a format-structure-declaration and produces a list of violated constraints.

It's a fascinating, non-trivial problem.

答: A database is the proper solution to this problem, anything else is just a hacky reinvention of existing database tools. You should reevaluate why you think this isn't a feasible solution, its not going to be more effort than a custom system to ensure you constraints are met. Databases are designed to create one version of the truth and serve it up any way you need it.</p>


答:
That way lies madness.  It is highly unlikely that you would ever need to change ORMs.  And if you ever decide to change the ORM, the cost of rewriting the mappings will be a tiny fraction of the cost to develop and maintain your own meta-ORM.  I would expect that you could write a few scripts to do 95% of the work needed to switch ORMs.

In-house frameworks are almost always a disaster.  Building one in anticipation of future needs is almost a guaranteed disaster.  Successful frameworks are extracted from successful projects, not built ahead of time to meet imaginary needs.


问:
Avoiding duplicate bug reports
I use Linux and other open source software in my home. As I'm not a professional coder, I usually report bugs to developers as my skills are not enough to solve problems on my own.

What kind of things you want me to check before I send a bug report? I mean, once I thought I found a bug in Gedit and I couldn't find similar bug in Bugzilla. But after I sent the report, some developer said that the bug is already in Bugzilla as the bug was in GTK+, not in Gedit. Sometimes it might be hard for an amateur to guess whether some previously known bug would solve the issue I found.

答:
There is nothing wrong with submitting duplicate bug reports. If your search for similar bugs did not turn up a duplicate, sending a bug report is the best thing you can do. The worst thing that could happen is that the developers working on the product closes your report as a duplicate. This is much better than letting a genuine problem go unnoticed.

You are also right about not trying to investigate problems outside your area of expertise in too much depth: in my experience, user's assessments of what's going on and how to fix it are mostly wrong and rarely helpful (see #4 in Jeff's post).

Title: Avoiding duplicate bug reports


问:
The 10 minutes technical interview
I must do a quick assessment of dozens of fresh students very quickly. I have 30 minutes meeting with each of them (in two or three days). I want to use most of the time to discuss non technical aspects. So I plan to use 10 minutes for technical questions. The same questions for all of them.

They are all hired already (they are students), what I need to know is the average level in order to prepare a training.

Ideally, the difficulty must be progressive in order to set a level for each. Level I will average, and I'll do an average on each question too.

If you had only 10 minutes and 10 questions to ask to a candidate, what would be your top 10 ?

答:
Three questions, elaborating on the end of Eric Lippert's answer here:

Question 1:

On a scale of 1 - 10, where do you
  rate yourself in (name the skill
  here)? They answer [n], a number
  between 1 and 10.

Question 2:

What could you learn from someone at
  level [n+1] ?

Question 3:

What could someone at level [n-1]
  learn from you?

The most important factor in your decision is to determine where a student (realistically) places themselves, and those three questions will help you to determine that quickly. It also helps identify people that might be compromised by the Dunning-Kruger effect (on either end), but that is another topic.

If anyone can find the reference to this method on SO and edit this post to include a link, I would really appreciate it.

Anyway, that should fall well under ten minutes.

Title: The 10 minutes technical interview


问:
Is it okay to define a [] method in ruby's NilClass?
Ruby by default does not include the method [] for NilClass

For example, to check if foo["bar"] exists when foo may be nil, I have to do:

```<code>foo = something_that_may_or_may_not_return_nil
if foo && foo["bar"]
  # do something with foo["bar"] here
end
</code>```

If I define this method:

```<code>class NilClass
  def [](arg)
    nil
  end
end
</code>```

Something like that would make this possible, even if foo is nil:

```<code>if foo["bar"]
  # do something with foo["bar"]
end
</code>```

Or even:

```<code>if foo["bar"]["baz"]
  # do something with foo["bar"]["baz"] here
end
</code>```

Question:
Is this a good idea or is there some reason ruby doesn't include this functionality by default?

EDIT July 2017: My core complaint was the unwieldy foo && foo["bar"] && foo ["bar"]["baz"] idiom required to access nested values when at any point the value may be nil. As of Ruby 2.3, Array#dig and Hash#dig exist, which addresses my concern. Now I can use the following idiom!

```<code>if foo && foo.dig("bar", "baz")
  # do something
end

# Note that errors will still occur if a value isn't what you expect. e.g.
foo = { "a" => { "b" => "c" } }
foo && foo.dig("a", "b", "c") # raises TypeError: String does not have #dig method
</code>```

答:
In some ruby code that I've had to tweak, I have added isFalse or something of that nature to the nil object to make some parts be not unhappy with each other.

Open classes are not my favorite thing and making such a change to the nil class is not a small change.  It is a significant change because it can change the entire functioning of the entire system.

You can do it.  Make sure you regression test everything and document up front all changes to core objects so that other people don't become surprised when suddenly nil behaves in an unexpected way.

As to why that isn't default functionality - that is the realm of speculation into the mind of Matz.


答:
Nullable values must be addressed carefully, it's not the same a variable that always has a certain type than other which sometimes has this type, sometimes is null. Functional languages are usually the most careful on this regard and they have custom types to manage it (Maybe in Haskell, Option in Ocaml/F#/Scala, ...).

In Ruby I wouldn't extend the NilClass as you propose, it may lead to buggy code (note that you're modifying a basic object used by every library, it's a disaster waiting to happen). However, it's understandable that you want some pattern to succinctly interact with values that may be nil to avoid littering the code with conditionals.

One option is the maybe proxy pattern proposed in Ick:

```<code>hash.maybe[key1].maybe[key2].maybe[key3]
</code>```

Or the block syntax:

```<code>hash.maybe { |h| h[key1][key2][key3] }
</code>```

Title: Is it okay to define a [] method in ruby's NilClass?

Body:
Ruby by default does not include the method [] for NilClass

For example, to check if foo["bar"] exists when foo may be nil, I have to do:

```<code>foo = something_that_may_or_may_not_return_nil
if foo && foo["bar"]
  # do something with foo["bar"] here
end
</code>```

If I define this method:

```<code>class NilClass
  def [](arg)
    nil
  end
end
</code>```

Something like that would make this possible, even if foo is nil:

```<code>if foo["bar"]
  # do something with foo["bar"]
end
</code>```

Or even:

```<code>if foo["bar"]["baz"]
  # do something with foo["bar"]["baz"] here
end
</code>```

Question:
Is this a good idea or is there some reason ruby doesn't include this functionality by default?

EDIT July 2017: My core complaint was the unwieldy foo && foo["bar"] && foo ["bar"]["baz"] idiom required to access nested values when at any point the value may be nil. As of Ruby 2.3, Array#dig and Hash#dig exist, which addresses my concern. Now I can use the following idiom!

```<code>if foo && foo.dig("bar", "baz")
  # do something
end

# Note that errors will still occur if a value isn't what you expect. e.g.
foo = { "a" => { "b" => "c" } }
foo && foo.dig("a", "b", "c") # raises TypeError: String does not have #dig method
</code>```

Body:
Nullable values must be addressed carefully, it's not the same a variable that always has a certain type than other which sometimes has this type, sometimes is null. Functional languages are usually the most careful on this regard and they have custom types to manage it (Maybe in Haskell, Option in Ocaml/F#/Scala, ...).

In Ruby I wouldn't extend the NilClass as you propose, it may lead to buggy code (note that you're modifying a basic object used by every library, it's a disaster waiting to happen). However, it's understandable that you want some pattern to succinctly interact with values that may be nil to avoid littering the code with conditionals.

One option is the maybe proxy pattern proposed in Ick:

hash.maybe[key1].maybe[key2].maybe[key3]

Or the block syntax:

hash.maybe { |h| h[key1][key2][key3] }


问:
What makes C so popular in the age of OOP?
I code a lot in both C and C++, but did not expect C to be the second most popular language, slightly behind Java.

TIOBE Programming Community Index

I'm curious as to why, in this age of OOP, C is still so popular? Note that 4 out of the top 5 popular programming languages are "modern", object-oriented capable languages.

Now, I agree that you can use OOP in C to some extent, but it's sort of painful and inelegant (well at least compared to C++ I guess). So, what makes C so popular?  Is it efficiency; being low-level; the vast majority of libraries that already exist or something else?

答:
I see some of the answerers give as to why C is the most popular, it's been around for a long time, it available in most platforms, free, etc.

But the same can be said about other languages, free Pascal for example - it's free, and supported for just about all platforms.

Pascal was invented around 1970, C was invented around 1972, so I think Pascal has been around just as long as C.

Personally I think C is the most popular language because there is just more open source code available out there to be reused by anyone. And yes it lower level than Pascal, so it's getting close to assembly but its a lot more readable than assembly.

I think there are just way too many programming languages out there. As programmers we have to know most of the important ones, but at the end there should be no need for that. One programming language can be implemented to do it all from building websites to iOS computer games.

C seem to be that global language, but I wish it would be something like Object Pascal. Why Object Pascal, it's a more readable programing language, OOP code does tend to be more reusable and less bug prone (in my opinion) than C.

Very large applications are easier to manage with Object Pascal than C/C++.

As to having a programming language that has been the some since the '70, and not liking languages that change every 5 or 10 years. As time goes technology advances and programming methods are improved. If a languages changes drastically every few years then it was probably not well thought out by its designer. But 1970 to 2012 is almost half a century, it's ok to make changes to a language in that time to incorporate advances used in Software development.

C itself has been revised several times. So, it's not better than other languages form that point of view.