|
|
NickPace wrote: IMHO anything that does not follow the SOLID principles is probably overly
complex Hence, "most of the code in existence today".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: Hence, "most of the code in existence today".
I would say that within the bounds of error and statistical variation that "most" is actually "all" in any meaningful sense of the word.
|
|
|
|
|
Member 4411225 wrote: I would like to think that architectures need to be complex, or rather even if it is "complex", if it was designed properly, it should still be straightforward and easily understandable.
I would like to think that unicorns were real but reality keeps getting the way.
Humans are limited. Humans are fallible, even the ones that are really good.
Complex systems and some point do not become amenable to being easily broken down.
And finally of course businesses are not willing to wait much less spend infinite sums of money waiting for perfect solutions. Even presuming they knew what the wanted in the first place.
Consequently systems are messes. And more complexity means more mess.
The only goal can be to insure that is not any more messy than it needs to be. Within limits.
|
|
|
|
|
Architecture is similar to design but at a larger scale. And like design, is about managing the complexity of a software system (or multiple software systems that are interacting with one another).
There isn't anything inherently complex about architecture, except that few people have practical experience of it. Designing and architecting large enterprise applications requires a deep understanding of architecture patterns. For this I would recommend Martin Fowler's book on Architecture Patterns.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
I remember once having an argument with a "Systems Architect" who said I and my team were just bricklayers who built a system from his plans. I replied that we were more like structural engineers who could point out to him that the house he had designed using expensive straw would collapse at the merest visit from a little naughty wolf, never mind a big bad one. He did not like being told this.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
I prefer simpler. It has the potential for less security holes, maintentance, and performance problems. But this all has to do with what the application is and the objective.
Blah blah blah... say your prays...
|
|
|
|
|
"Keep Code Left" (KCL) is the name I've given to a coding style I believe improves code readability and maintainability in almost any procedural language. I've been coding for many (many) years, and reviewing code as a dev manager for much of that time.
Over the years I've come to the conclusion that programmers are abusing if statements by using the then clause to contain the meat of a method, rather than to contain the exception cases. This is most egregiously demonstrated by short examples found in many internet articles which are written like this:
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
someControl.val = 1;
}
}
The fundamental premise of KCL is that the "meat" of the method should be as un-indented as possible, and indented code is for cases which are errors or uninteresting due to starting data conditions. Most often, these exception cases end in a return statement as there is no more work to be done for that case. This leads to a simple rewrite whose implications are far-reaching (really!).
private void Page_Load(object sender, System.EventArgs e)
{
if (IsPostBack)
return;
someControl.val = 1;
}
Almost by definition this reduces the complexity of the code and increases the maintainability. If your job is to manage any significant body of code, then surely these two goals are front and center for you, each and every working day?
So what about those cockroaches else statements? By following these two points, I've found it is possible to remove over 50% of the else statements from much of the code I read; this reduces or eliminates the indentation, and even in some cases exposes bugs just by this simple refactoring (don't believe me? Try it!).
Code like this:
public IIdentity Identity {
get
{
if (this._identities.Count > 0)
return this._identities[0];
else
return null;
}
}
becomes this:
public IIdentity Identity {
get
{
if (this._identities.Count <= 0)
return null;
return this._identities[0];
}
}
The more lines of code there are in a method, the clearer the code becomes.
I've created a presentation on this topic which builds and expands on these ideas. I've delivered it at a couple of user groups over the past several months, and it's remarkable how many people have approached me at other technical gatherings since then to let me know how much they think the ideas presented have helped improve their code. This has encouraged me to share with the wider community.
Although the presentation is more fun given "live", with interactive Q&A featuring many code samples and discussion, I'd like to share it here, and solicit feedback and perhaps start a lively online discussion.
http://www.slideshare.net/MichaelMickAndrew/keep-code-left-10-1114
|
|
|
|
|
This is hardly new (although it is in direct contradiction to Steve McConnell's advice about only having one exit point from a method). You do know that tools like Resharper actually provide this ability as standard and utilities like NDepends provide this analysis and recommendation for free.
|
|
|
|
|
Pete O'Hanlon wrote: although it is in direct contradiction to Steve McConnell's advice about only
having one exit point from a method Worst advice ever if you work in a OO-language.
How can a "goto endOfMethod" be more readble than a "return"? That is only true if you need multiple statements as a return-block (say, cleanup code), where it indeed would be more difficult to maintain since it means having duplicate code inside your method.
No, limiting the exitpoints of a method to "1" does not improve readability. Yes, I've also heard the argument that it makes it easier to locate where something is returned without having to read the entire function. Well, without reading the entire function you won't know what happened either, and if it is that much reading work then you have a method that is too large.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Some KCL prescriptive anti-pattern constructs, such as “else return” or “else throw” are great candidates for automated tools such as Resharper, and I would think NDepend too. I agree that the points I am making may well be “not new”; I wrote the discussion article because I’ve not seen these simple concepts discussed plainly anywhere else, and it’s the fact that they are so simple yet have such a radical effect on code structure (in what I think is a good way), which encouraged me to write it down.
The “only one exit point from a method” rule is one which has been argued about for many years; my view is that for languages with try-finally syntax, this allows for having your cake and eating it. Simply code a try-finally around the entire content in any method which has one or more return or throw statements (or calls methods which might throw exceptions), and you have the one exit point which McConnell is a strong proponent of.
|
|
|
|
|
So what's your question?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The question to the community, in a superficial sense, is simply “What do you think?”.
To be more specific:
Do you program this way? Have you seen other articles that cover this ground? I haven’t, and would like to join that conversation. I think KCL has a lot to contribute.
Does the reader think this a “good” programming style or a “bad” programming style, or somewhere in between. Why? I think we all agree that we should use “good” style/technique, but it is often hard to come to agreement about what constitutes “good” versus “bad”. There is a still a lot of “art” in programming, and one person’s art is another person’s trash.
The thing I like about applying KCL is that it is highly prescriptive and not subjective; this is a good thing for automation and both coders and reviewers don’t need to be coding super heroes to apply it.
And finally a question for a few weeks after reading this: Did you try it and what do you think now?
|
|
|
|
|
mickan wrote: The question to the community, in a superficial sense, is simply “What do you think?”. I think the programming forums are not the place for this type of discussion; it belongs in the Lounge or Soapbox.
|
|
|
|
|
mickan wrote: Over the years I've come to the conclusion that programmers are abusing if statements by using the then clause to contain the meat of a method
Over the years I have come to the conclusion that simple syntax idioms have nothing to do with the real problems that developers face.
Myself I haven't worked anywhere for years where the higher ups have not always been over promising features and even while making the actual promise not even understanding what they are promising. Even worse those they are making the promise to don't know what they want either.
Solving that problem would have a vast impact on software development.
Might note that I have worked at places with explicit requirements as part of the contract and even then they can't get it right.
|
|
|
|
|
I'd love to hear any feed back regarding design, style and architecture.
You can find the source at http://github.com/corvusoft/restbed.
Asynchronous RESTful framework
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void get_method_handler( const shared_ptr< Session >& session )
{
const auto request = session->get_request( );
size_t content_length = 0;
request->get_header( "Content-Length", content_length );
session->fetch( content_length, [ ]( const shared_ptr< Session >& session,
const Bytes& body )
{
fprintf( stdout, "%.*s\n", ( int ) body.size( ), body.data( ) );
session->close( OK, "Hello, World!", { { "Content-Length", "13" } } );
} );
}
int main( const int, const char** )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Was told to remove this from the C++ threads. Please let me know if this is still not the right place for this?
|
|
|
|
|
|
What most people here would be interested in, and what would generate the most feedback, is an article/set of articles, going into depth about your code. Show the type of challenges you faced, the decisions you took, why you took them, what you rejected and so on. The forums really aren't the place to try and get the type of feedback you're after.
|
|
|
|
|
Thanks. This sounds like a great idea, will look into it this week.
|
|
|
|
|
|
Hello
Is it possible to get real time data feeds of futures and options from NSE Web site or any other source and i need to create a web application with few logic built to it.
|
|
|
|
|
Yes. Go to the website and find out what information they provide and in what format.
|
|
|
|
|
I'm not sure if this is the correct forum to post this in but here it goes.
I'm working on designing a more robust ETL process for our Enterprise Data Warehouse. The idea is, there would be two servers set up as primary and secondary dispatchers along with (n) number of client listeners.
I would like to be able to have each listener perform some SQL Query and/or a stored procedure using the resources on that specific machine in an effort to maximize both ETL process speed and resource utilization.
My question is:
Is this a situation where I could/should use a Parallel Data Warehouse architecture?
I wouldn't really want, let's say, 20+ computers all performing rather large queries against the same SQL Server instance... that would negate any performance gains I may get from a Distributed architecture.
Thank you for reading this and I appreciate any information you could provide.
I hate users. Not all of them, just the ones who talk.CP member: Al Einstien
|
|
|
|
|
After adding Code Snippets, I am having trouble with Syntax Error in WordPress. Can anyone tell me the solution to solve this issue?
The Error looks like:
Parse error - syntax error, unexpected $end in /public_html/site1/wp-content/themes/my-theme/functions.php on line xxx
|
|
|
|