Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am considering releasing one of my class libraries written in C# as open source. Before doing that, I am trying to do some refactoring so that it meets the demands of the general public :)
I wonder what would be the best namespace schema to use? Basically, I see the following options:
namespace MyTool: This just doesn't really look like organized for me. I mean, (almost) all the namespaces in the .NET Framework are prefixed with System so I guess it is not really a standard way to do it.
namespace MyOrganization.MyTool: The problem with that there is just simply no "MyOrganization". It is written in my spare time.
namespace MyName.MyTool: I would prefer something more humble. I mean really, I don't want to have my name in the namespace.
Now there are a couple of related questions on Stackoverflow already, like this and this, but none of them really answer my question.
Any suggestions?
I'd go with something like:
namespace OpenSourceProjectCodeName.MajorFunctionalArea
For example:
namespace VideoWizardMagicThing.Audio
namespace VideoWizardMagicThing.Audio.Codecs
namespace VideoWizardMagicThing.Video
namespace VideoWizardMagicThing.Video.Codecs
You don't have to go completely mad with namespaces and all you may need is one or two MajorFunctionalArea's. However without knowing how the project is structured or what it does it's hard to say.
If it's open source and there will be contributors I would pick MyTool.
If you can afford to change it later, I'd go with MyName.MyTool. If you are the only person writing the tool, you need full credit, and having your name in the namespace doesn't hurt anyone.
If you take on new contributors, you can remove your name from the namespace but only if other people actually made a big contribution. If the majority of work is yours, I'd leave it in.
MyTool has the problem that names aren't unique; you’re heading for name conflicts. MyCompany.MyTool doesn’t apply in your case if you don’t want to give yourself some label.
I actually rather like the Java convention of reversing the URI associated with the product. For companies, this is the company website. For you – do you have a blog / personal homepage whose address isn’t likely to change soon? Then use the name, with TLD and second-level domain reversed. In my case: net.madrat.MyTool.
I know a few people who use TheirName.MyTool which is fine. Howver, this becomes a problem as soon as there is a second contributor.
I would suggest getting a MyOrganization and using it. If you ever take money for the work, you are going to need an entity, and it could protect you from liability. It is fairly easy to set something up.
Or just use a MyOrganization name and create the entity later, but you run the risk of legal name conflicts, etc if you don't set it up first.
You could do MyToolProject.MyTool. Or, you could just come up with some creative name for your "organization" and just have that as what all your future open source projects will be, even if it is just one right now. Then you could have MyCreativeOrgName.MyTool.
MyTool sounds pretty much like the project code/brand name?
In that case if you wish to categorise it further without using your organisation or personal name, hook on the industry or problem domain it is meant to address.
VideoEditing.MyTool
Accounting.MyTool
HomeAutomation.MyTool
MyOrganization.Technology is still the recommended way to start the namespace with.
I used to have similar problem of namespacing my hobby the projects before. So I've just made up the name for the development group of one (you want to have a short and readable one) and started using it.
However, keep in mind that the usability is still the key. For example, here's is one exception from the rule. Our open source Lokad Shared Libraries are following namespace of the .NET itself (i.e.: System or System.Threading). That's because there are numerous everyday helpers and extensions that should be available for our developers without even noticing that they are leveraging non-BCL code.
It also makes the using declarations look nicer.
I ended up with Idunno.* for a couple of projects (my web site), and SharpSTS.* for the main one (as that's the project name)
Related
I am pretty new to C# but I have worked a little bit for my classes. When I worked in C#for classes, our teacher used to tell us the namespaces that we needed for completing the assignment.
I wanted to know where do I find all the collection of the namespace for C#.
One of my friends directed me to this site
https://learn.microsoft.com/en-us/dotnet/api/index?view=netframework-4.0
but some of the namespaces did not work for example,
enter image description here
I am working on a small project with ASP.NET MVC and wanted to try different namespaces
I think you may be a little confused, or are possibly not asking the question correctly. The link you provided does contain a list of the different libraries (namespaces) available in the C# API.
If you try to use a namespace in your own code, and it does not resolve, you may need to add an assembly reference to bring that namespace into your project. VS usually does a pretty decent job of guessing what assembly, or missing using statement is required if you either press alt+enter, or click the context drop down under the missing library (denoted by the red squiggly).
Either way, you should just start coding your MVC project, and then google the issues you come up with directly. Asking for all the namespaces is very very vague.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Our team of software developers consists of a bunch of experienced programmers with a variety of programming styles and preferences. We do not have standards for everything, just the bare necessities to prevent total chaos.
Recently, I bumped into some refactoring done by a colleague. My code looked somewhat like this:
public Person CreateNewPerson(string firstName, string lastName) {
var person = new Person() {
FirstName = firstName,
LastName = lastName
};
return person;
}
Which was refactored to this:
public Person CreateNewPerson (string firstName, string lastName) {
Person person = new Person ();
person.FirstName = firstName;
person.LastName = lastName;
return person;
}
Just because my colleague needed to update some other method in one of the classes I wrote, he also "refactored" the method above. For the record, he's one of those developers that despises syntactic sugar and uses a different bracket placement/identation scheme than the rest of us.
My question is: What is the (C#) programmer's etiquette for refactoring other people's sourcecode (both semantic and syntactic)?
I would worry less about politeness and more about the economics. Every code change induces a huge number of costs:
code changes must be tested by QA
code changes must have test suites written for them by development
code changes that affect user experience may need to be documented
code changes can introduce bugs; those are obviously enormous costs
and so on.
I would not dream of making a minor "aesthetics-only" change to any production-quality code, whether it was "mine" or not. The benefits of the change do not come anywhere even close to justifying the cost.
You might consider reminding your colleague that you're in the coding business not to produce beautiful code that you all find aesthetically pleasing, but rather to produce profit for your company in a weak economy. You're not artists, you're engineers, so act like engineers; all changes should be justified by a business purpose.
I believe in collective code ownership i.e. that code belongs to the project, not to an individual engineer. So I have no problem with someone refactoring something I wrote as long as it complies with the project standards. If the project doesn't have coding standards, then the team should define some.
An etiquette should always be done on the level of the team. So talk with your colleague about this and then talk with the complete team to define a rule.
Common rules may contain not to change the code, if it is only for beatifying and disputed coding styles. If someone has to maintain your class in the future, then it is usual, that he can change anything.
Define some base-rules, some anti-patterns (that always can be refactored by your coworkers) and so on.
Such rules don't have to be very strict, so the placement of braces or similar things don't need to be defined. But in that case, nobody should beatify code, someone else maintains. If you get into conflict about one thing, talk about it in the complete team, to create a new rule for this case.
Without coding-style guidelines/rules, he might not even be aware that the change is causing annoyance.
That said, the style is fairly non-standard and on a personal level, I'd be annoyed with a "refactor" that does not change the meaning of the code but rather serves only to stamp his coding style in your face. I'm not sure it even qualifies as a refactor. Pretty selfish.
IMHO this doesn't make the code any cleaner, just imposes the other guy's coding style on it. You should discuss it with your colleague(s) whether this type of "refactoring" is really necessary (and whether there are really no better ways for your colleague to spend his/her time :-)
The most important aspect of this is consistency. Your team should decide on whether to use type inference and object initializers and write down some coding guidelines.
I believe the most important thing is to be able to disagree and commit. We all have our preferences, but changing non-important things back and forth waste everybody's time.
Ruthlessly adhere to the standard. If there is no standard then that is your problem, not that other people can and do change your code.
Also, before getting upset about code changes, you need to determine intent. Was it malicious, or an innocent change?
If I'm modifying a file that is owned by a colleague, I try to keep the changes consistent with their style. This way, even though half of our files prefix "m_" for fields and half prefix "_" (among other minor things), at least a single file/class is self-consistent.
Did he produce a majority of the code for the project in question? If that were the case, I could understand what he did. When entering into a project that's already well underway, I try to match the formatting that's already in use throughout the code.
That may not apply to your situation, of course. If whatever project has received generally equal contributions from all of you, maybe take Mnementh's advice and bring the issue to a head.
I would simply talk with your fellow developer about what you want to refactor and why. Only refactor the code if you agreed on something.
This will result in discussions where most probably both of you will learn something from each other.
I think in this specific example (C# that is), you should simply follow the guidelines provided by Microsoft. Consistency with the code standards of the .NET Framework makes for easy to read class and code structure.
The other thing is Visual Studio auto-corrects to various formatting rules as you type which would help. For example, when closing a bracket or ending a statement.
I personally think that cosmetic refactor looks ugly and decreases readability, whereas your code adhered to the .NET conventions.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm developing a price calculation engine. I've looked all over and there's nothing that really fits what we need. However, I'm now looking how to implement specific prices and/or discounts. I don't want to introduce a rule based engine to my end-users, because they won't get it.
For example, when you order an ItemX the price is $30. But in combination with ItemY the price of ItemX is $20. Or when ordering five of ItemX, each after it will be only $15.
Any ideas on where to start? How to take this on? Perhaps some (open source) example applications that contain practices like these? Any (technical) patterns I could use? Preferably in C#.
Thanks in advance!
There are many ways you can achieve this, but I think the one which might be most useful for you would be to define a DSL that you can use to express your discounts in such a way where they can be easily explained and rationalised with business users. An example from one of ayende's articles on DSLs in boo is:
apply_discount_of 5.percent:
when order.Total > 1000 and customer.IsPreferred
when order.Total > 10000
suggest_registered_to_preferred:
when order.Total > 100 and not customer.IsPreferred
As you can see you can see, this is the kind of thing you can print out and show to a client and they will immediately understand what's going on.
Of course developing something like this is time consuming, expensive and fraught with funky edge cases. However it has the benefit of being code which can be unit tested, executed and debugged.
If boo isn't your thing, then maybe you could look at defining something similar in ironruby, ironpython or F#. I would however suggest staying away from XML for defining these rules unless you really enjoy a world of pain.
This is however the kind of thing that products like Biztalk were designed to handle. Which rules engines have you evaluated and found lacking?
We use a Rule Engine for this type of complex calculation. Our platform is Java and we use Drools (which we're happy with). Drools is also available for .Net. Here's a list of open source Rules Engines for .NET.
I am sorry to have to say this, but this would seem like you would have to apply some Pricing Rule Engine to achive what you are after.
Would seem like you have to
Store the available items, and their
discounts on per pruchase.
Store which items in combination
would discount each other.
Also maybe thinking of per
unit/quantity purchased per unit, or
maybe per package/special.
Might want to look at keeping a
archive/storage of these
specials/packages, just incase the
customer wants a reprint of the
original invoice.
In general there is a lot of possible rules/combinations that can be thought of, and you as developer can implement these and hide them from the user, or allow the user to create them, but somebody has to do so.
And then, when you dont feel like implementing your own, GOOGLE shold provide some:
Open Source Rule Engines
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
We're hiring a .NET developer soon, and I was assigned to create a test, which would take aprox: 1h to solve. A test which would test the programmers knowledge in (mainly) C# and ASP.NET.
This is what i've come up with so far:
Use project #1 to read data(HTML) from the specified URL and output all links(anchors) containing anchor name “xxxxxxxxx”. You are free to use 3rd party libraries. My main thought here was to test how the developer would go about solving the problem. For example:
Create a regex which would parse all the data needed.
Create a DOM-tree and use XPATH to find all anchor nodes.
Iterate the whole string and perform manual string compares.
Create a new solution where you demonstrate the usage of .NET masterpages.
Connect the solution to the ******** database. And output all customers from the “********_customers” table.
Create a new button which refreshes all users using AJAX.
Pretty basic stuff. Though, I also added the one below. Mainly to test the developers OO knowledge. Do you think this is too "overkill", or what kind of test would you suggest? If you were to hire a ASP.NET developer, what would your main focus be? ADO.NET? IO? string handling?
Create an interface/abstract class implementation demonstrating the functionallity of either the Factory, Factory Method, Command or Decorator pattern. You wont need to implement any functionallity, just use comments in your abstract class.
Thanks in advance!
The task you gave is essentially a day or two worth of coding if you want to have reasonably readable code. Within an hour I guess I would do it, but you'd have to read code that has cryptically named methods, unreadable regexes, weird callbacks, no error handling and overall is pretty darn ugly. Looking at it you would not hire me.
Before you give your question to candidates, first make sure that your peers/programmers can do it first. And that you can code it in less than 60 minutes in a way that would satisfy you.
That said, I do not know if test is the best choice for hiring anyone. A few interviewing bloggers wrote about their experience coming from conducting tons of interviews:
Guerilla Guide to Interviewing by Joel Spolksy
Truth about interviewing, Get that job at Google (and many others) by Steve Yegge
I totally agree with them. Having conducted about a gazillion of interviews myself, I find that asking basic technology related questions is not nearly as good as asking to implement a bit of recursion or pointers (if someone claims to know C/C++).
By hiring someone who understands recursion/algorithms you get a smart guy who can learn new technology. When you hire someone who knows how to connect to a database, who knows how to connect to a database but not necessarily qualified to do much more than that.
There are a few sources of good programming questions that are somewhere between coding and algorithms that may inspire you. They do not test .NET at all, but are very good indicator of smart programmers.
Top Coder
Google Code jam
Within 1 hour you can only test his programming skills, but it's not enough to write the code sample.
Take a look at this C# / ASP.NET MVC test:
http://tests4geeks.com/test/asp-net-mvc-c-sharp
After the applicant will pass the test and result will be good, then invite him to the interview and talk about his experience. Ask about most difficult features, that he implemented in his projects. In other words, you must understand, if he know and can do enough to take part in your project.
If you still want to ask him to write some code. That is some idea:
There are the students and subjects. Please ask to write 3 pages (asp .net mvc or web-forms). First and second - for editing the dictionary of students and subjects. Third form must contain be the table. The students are in left column. The subjects are in the top row. The marks are at the intersection. Each mark can be edited (text box) and saved. Saving could be implemented by clicking the common button "Save". Or it could save each cell automatically using the Ajax.
This is very simple example, but it would show you how user writes the code, what techniques does he use.
I would have thought that it would be better to simply create a test that would make it easy for you to put developers into different 'skill buckets'.
Why not have three or four sections or features that the developer must 'layer' features on top one another to show their programming and design skills.
Part 1: Implement x easy difficulty
features.
Part 2: Implement x medium difficulty
features.
Part 3: Implement x difficult
features.
Part 4: Implement x very difficult features.
And give the developer 1 hour to write the application. Make it realistic that they can implement the features in the given time frame.
As Joel and Jeff say on the Stackoverflow podcast, there is a direct correlation between developer skill and speed.
Think about the way exams are structured? We can all get 100% of the questions correct in any exam we sit if we had infinite time, but in 1 hour?
This way, If a developer takes your test and only implements features up to Section 2 in the time period, then you should have a safe indication that they are not suitable for the job. Section 3 features all done then they are good enough and section 4 complete would indicate that they are very experienced and a slight cut above the rest.
However I would also look at the overall polish that the developer has given to the code. If they implemented all features up to section 4, but poorly, then they are also not going to be someone you want. IF a developer only did up to section 3 but implemented everything very elegantly, then I would want to hire them.
I also think that 1 hour is perhaps a little too long. I would aim for 10-40 minutes obviously you may need to cut out section 4 that I proposed.
You should check
GeekInterview -- a good source for interview questions
There are hundreds of questions.
I think you would be much better off coming up with a single question that will allow you to see more than just development skills using your target technologies. Strong problem solving skills are as important as expertise in a specific technology stack.
I would even recommend that you explore the two aspects of a candidate in different parts of the process. I usually ask a bunch of questions about the technology stack we are using on our project to gauge the candidates level of knowledge as it relates to that stack.
Then I ask them a pure problem solving question and I allow them to use whichever technology they are most comfortable with to solve the problem (their choice of technology can be an important indicator).
I particularly like Graph Theory related problems. The candidates solutions will tell you a ton about how they approach, solve problems as well as how they validate their solutions.
As part of the problem solving portion of the interview you should be looking for:
Proper data structure design
Implementation of OO best practices
Proper solution (can they debug problems effectively... one great way to see this is do not allow them to use a computer, make them code on a whiteboard and debug in their heads)
Proper solution validation (do they come up with test cases)
My 2 cents:
We have a programming test in my company that is easy. Basically, you have to implement the listener pattern extending the ArrayList class, create unit tests for it (based on at least what we require), document the corner cases, document the program itself if you want to, and then send the test back to us.
A developer has 48 hours to complete that test. We ask for production quality in the test. We want to test the following items:
Was the developer smart enough to cover the corner cases?
Is the developer implementation of multi-threading satisfactory?
Are the unit tests good enough? Do they cover enough cases?
Is the code well written and documented? Will someone be able to maintain that code in the future?
Does he care about his code? Did he explain why he did "A" and not "B"?
I don't think short tests are capable of evaluating a developer. You may ask for a tool or technology that someone have not been using in the past months, and whoever is being tested for that technology will need sometime to get up to speed - but if a developer was working with that the day before, he will know by memory how to use it, and he/ she will seem smarter than the other developer, what may not be true.
But if you ask for something that is tricky and you are interviewing the developer, you can check how he is going to solve the problem - I don't think it really matters if he/ she cannot get the 100% right answer, as long as he/ she can talk about the problems that you found on the code and show that they actually understand whatever you explained to them.
In the past we have used problems from Google code jam. the problems in the early rounds are easier and they get gradually harder. They are kind of algorithmic in nature, you can solve them in whatever language you like. As they get harder there is often an obvious 'brute force' kind of answer that won't work because of the size of the data. So you have to think of something more optimal.
The first test you suggested should take 10min-40min for a basic dev - I would use a web-crawler I have in my library that converts HTML to XML then easily use Linq to XML.
I would test for lambda expressions, performance patterns maintain files, or writing an object to several files dynamically.
Maybe you would like to test unmanged code, pointers etc.
I donno, im just writing-jabbering while things are comin up to my mind, i wrote things that was hard for me to implement.
few days ago I was invited to pass C# programming test at skillbox website there was 30 questions quiz and 45 time to pass it. Below is some of them:
1) What will be printed by running the program?
#if DEBUG
Console.WriteLine("DEBUG");
#else
Console.WriteLine("RELEASE");
#endif
2) What will be the result of calling SomeMethod():
public static void SomeMethod()
{
string s1 = "a";
string s2 = "b";
Swap(ref s1, ref s2);
Console.WriteLine(s1);
Console.WriteLine(s2);
}
public static void Swap(ref Object a, ref Object b)
{
Object t = b;
b = a;
a = t;
}
Here is a link for reference, I think you can find more C# quezzes there http://skillbox.io
I am developing a framework, and some of the objects have reaaally long names. I don't really like this, but I don't like acronyms either. I am trying to come up with a shorter name for "EventModelSocket", basically a wrapper around the .Net socket class that implements various events, and methods to send files, objects, etc. Some of the objects have really long names due to this, such as "EventModelSocketObjectReceivedEventArgs" for example.
I've tried everything from a thesaurus, to a dictionary to sitting here for hours thinking.
When you come upon situations like this, what is the best way to name something?
Push some of it into the namespace.
For example:
EventModelSocketObjectReceivedEventArgs
becomes
EventModel.Sockets.ReceivedEventArgs
Well, are the long names hurting something?
(edit) two other thoughts:
use var in C# 3.0 - that'll save half the width
if you are using the type multiple times in a file, consider a type alias if it is annoying you:
using Fred = Namespace.VeryLongNameThatIsBeingAnnoying;
I would just suggest using the most concise naming that describes the object.
If EventModelSocketObjectReceivedEventArgs does that, move on.
My 2 cents.
Years ago when I was in a programming class, the prof quoted the statistic that a piece of code is typically read 600 times for each single time it got modified. Nowadays, I would assume that this is no longer true, particulary in TDD environments where there's lots of refactoring going on. Nevertheless, I think a given piece of code is still read many more times than it gets written. Therefore, I think the maxim that we should write for readability is still valid. The full form of a word in a name is more readable, since the brain doesn't have to do the conversion. Comprehension is faster and more accurate.
The tools we have today make this so easy with autocompletion and the like. Because of this, I use full words in variable names now, and I think it's a good way to go.
If you need to go through that much effort to find an alternative name, you already have the correct name. Object/method/property names should be self documenting. If they do not describe their exact purpose they are misnamed. There is nothing wrong with long names if they give the most clear understanding of the purpose of that object.
In this age of intellisense and large monitors there really is no excuse to not be as descriptive as possible in naming.
Don't remove the vowels or something crazy like that.
I'm with the "stick with the long name" people.
One thought is that if the names are that awkward, maybe some deeper rethinking of the system is needed.
I for one use the long name. With intellisense typing out the name isn't that important, unless you are using a 15 inch monitor.
If I had to reduce the name I might go with EvtMdlSck just make the work shorter but still understood. Even though that is not my preference.
Some criticisms on your naming...
Why DOES your component have the word "model" in its name - isnt that a bit redundant.
Since your component seems to be a messaging hub of some sort why not include
Message in its name. What about MessageSender.
To solve your problem I would create an interface and given it a generic name like
MessageSender and an implementation which is where you include the technology within the name like RandomFailingSocketMessageSender.
If one wishes to get a good example of this take a look at the Java or .Net libraries..
from Java.
interface - class/implementations...
Map - HashMap, LinkedHashMap.
List - LinkedList
Details regarding the technology or framework used eg words like "Socket" or perhaps to use a contrived example "MQSeries" shouldnt be part of the interface name at all.
MessageSender seems to IMHO sum up the purpose of your component. It seems strange that your thing which sends "files" and "events" doesnt include the those two descriptive words. The stuff your using in your naming is superfluous and IMHO doesnt match your description of the component.
In general I believe in classnames that accurately describe their function, and that's it's OK to have long names. If you think the names are really getting long, what I would suggest is finding a concept that is well-known to your programming team and abbreviating that. So if "Event Model Sockets" are a concept that everybody knows about, then abbreviate them to EMS. If you've got a package that is entirely about Event Model Sockets then abbreviate them to EMS in all the classes internal to that package. They key here is to make sure the name is in full for anyone who might not be familiar with the concept and abbreviated for anyone who is.