|
You can never tell - some I thought would be gone in five minutes didn't get solved at all, and some I figured were a real challenge were answered immediately.
We have a lot of different brains here, and they all think differently...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
A meeting is scheduled at 0900 hrs UTC. Will post by 0930 hrs.
|
|
|
|
|
Haemoglobin
Anag. of "A goblin home"
|
|
|
|
|
Ah, so close!
|
|
|
|
|
Ah, so late!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
we have a lot of class where all properties are readonly and have constructor with 40+ parameters to initialize those said properties.
And, in the unit test code with have code like
public static T EmptyConstructor<T>()
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>("{}");
}
This is the kind of typical web developer code that make me sick to just look at it.
Where do web developers learn to code?
That seems to be fairly typical practice for web developer to do that, but it makes me want to vomit!
|
|
|
|
|
SO, for the not so web developer amongst us, what is wrong with that ?
|
|
|
|
|
- constructor with lots (I mean, 40+ mandatory parameters) is kind of a bad idea (i.e. an endless source of pain)
- having all property setter, and the using reflection to call the private setter anyway, or having zillion of mandatory parameters and using reflection tricks to automatically fill them for you is what I would call bad practice and generally cause endless source of perfectly avoidable pain, while providing little concrete benefit (more like, what if benefits)
not too mention such code has bad performance and is hard to understand and modify, quite often.
|
|
|
|
|
OK, what would be the correct way to handle the parameters then ? (Genuine question, trying to learn here).
|
|
|
|
|
If your method requires more than 3 or 4 parameters then refactor your method. Break it down into several smaller, more manageable methods. Also, look at passing an object into the method instead of multiple parameters.
If I see a method requiring more than 3 or 4 parameters I will take immediate action. This is something I have addressed in the development team's coding standards document.
"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
|
|
|
|
|
We have Sonar set up to flag > 7 parameters as a defect. Even 7 would require a very good reason to get passed at code review.
|
|
|
|
|
We use Resharper, but not sure if it flags this up or not. I'm going to have a look though.
"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
|
|
|
|
|
This Sonar tool sounded interesting, but all links that google found were "IP address not found". Does this tool still exist?
A human being should be able to change a diaper, plan an invasion, butcher a hog, navigate a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects! - Lazarus Long
|
|
|
|
|
|
Years ago, I was working in a company making a Fortran compiler that had to be extended for one single customer: The old version had a limit of 99 paramters to a function; this customer's code broke that limit!
The new compiler (it was in fact an all new compiler, not an update of the old one) could handle 127 parameters, but this could easily be extended to 255. The customer's needs were satisfied with 127 parameters.
Other strange cases I have been in touch with: I worked with the company makin the linker for ITT System 12 telephone exchange software. This linker had to be extended when one of the modules exported more than 32767 symbols! All it took was to replace a signed 16-bit index with an unsigned index, for 65535 symbols, but I can to some degree excuse the developers for thinking that 32K exported symbols should be enough for everybody . (There was no similar limit on total number of imported symbols.)
The same software also won a first prize for the largest struct definition: approx 8300 lines. If you print it out, 72 lines to the page, that one type defintion would fill a book of 120 pages. True enough: This wasn't one flat set of 8300 fields, but a variant structure defining a protocol element, with a few common header fields followed by all the different variants depending on the function code in the header. Nevertheless, in my eyes this is crazy. ... But then, almost every time I see code relating to telephone switches, I say "This is crazy". I suppose it is just a completely different approach to programming.
|
|
|
|
|
Member 7989122 wrote: The same software also won a first prize for the largest struct definition: approx 8300 lines. If you print it out, 72 lines to the page, that one type defintion would fill a book of 120 pages. True enough: This wasn't one flat set of 8300 fields, but a variant structure defining a protocol element, with a few common header fields followed by all the different variants depending on the function code in the header. Nevertheless, in my eyes this is crazy. ... But then, almost every time I see code relating to telephone switches, I say "This is crazy". I suppose it is just a completely different approach to programming.
I suppose that in a language such as C++, you would have a set of classes, all derived from the same base class, with appropriate serializers for I/O. Given that many of these protocols were implemented in C, I don't see how else they could have done.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
System 12 is coded in CHILL, which is actually a well designed language. Both designed, not just "well, it just turned out that way", and well - it is not over-designed. It is complete with exception handling and threading mechanisms, with synchronization and data protection, designed into the language from the very beginning. It is a pity that it was never marketed outside the telecom business. Compared to Ada, which appeared at the same time, CHILL is elegant and lightweight, Ada is an elephant in a mudhole. Oh well; CHILL is dead now. There is nothing to do about that.
The disadvantage of having a couple hundred classes is that you have all the red tape repeated a couple hundred times. You probably have a couple hundred files. If you need to search for some member name (or whatever), you have to do a couple hundred searches (of course that can be automated, but still!) I know programmers who make a separate source file for each function, no matter how small the function. Fifty to hundred lines of comments, twenty lines of red tape (defining of environment etc.) followed by a five to ten code lines function. "Grasping the big picture" is almost impossible!
I prefer something in the middle between. That 8300 lines struct is way over my limits, but I like to have closely related things gathered together in one unit (such as in one source file).
Re. serializers: I didn't see this struct myself, but I guess that it was designed something like the classic Sun XDR "External Data Representation": Essentially, serialization is done by reading out RAM octet by octed according to how Sun stored the C struct in a Sparc based computer. Serializing was practically a no-op - which Sun used for all it was worth in comparisons with other standard encodings, such as BER. Doing nothing is a lot faster than doing something, no matter how fast that "something" is ...
Probably, the CHILL struct representation in System 12 memory was an exact image of the octet sequence to be transmitted. You probably couldn't do that in C++; you would require active serializer code. In C you could - but I wouldn't trust it for more than one C compiler at a time; there are so many vaguely "defined" elements in the language, or explicitly not defined but "implmenentation defined". CHILL, as a (telecom exchange) system programming language, had the facilities for defining exact memory layout.
|
|
|
|
|
I sit corrected.
In the early 2000s, I worked in the cellular phone world. The GSM stack that we used was written in C.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Super Lloyd wrote: typical web developer code
I'm a web developer - too - for decades and never seen code like that...
"The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018
|
|
|
|
|
I had a cow worker like that, not web developement and self taught. Every attribute was const, no setters and overly long constructor.
He also used (in C++) templates following a "guru" book, the best he did was using templates and then specializing every single possible instance of that template. Every single one.
GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
They close the roads...
First (and maybe last) snow...[^]
"The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018
modified 16-Jan-19 13:20pm.
|
|
|
|
|
Salt and sand should be enough to keep the roads open.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Please!! Do not encourage them! That porridge of salt and snow, which turns into a thick over-salted snow soup, is just terrible to drive or walk in. And it eats up your car by corrosion within a few years.
I'd much rather have white, snowy roads. Get yourself studded winter tires, or if you go for the soft-rubber non-studded winter tires, get chains for use under extreme conditions.
I had to showel away about 30 cm of snow to get my car out this morning. Temperatures have stayed at -12 C to -8 C since the snow fell, so it was dry and lightweight. Took me less than fifteen minutes to showel my driveway, all by hand. Would have been more work to get the snowblower out and to make it start
|
|
|
|
|
Member 7989122 wrote: Get yourself studded winter tires, or if you go for the soft-rubber non-studded winter tires, get chains for use under extreme conditions. I don't have a drivers-license. Should I put chains under my shoes?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|