namespace FunkySoftware {

#include "FunkySoftwareNet.h"

};

namespace OtherSoft {

#include "OtherSoftNet.h"

};



FunkySoftware::net::Socket m_socket;

OtherSoft::net::Socket m_othersocket;



I realize that this is a very old article, and maybe the version of VC++ used at that time didn't support nested namespaces.

However, anyone using a recent compiler should ignore this article. Nested namespaces can solve the problem.





modify the symbol name which means wrapper namespaces will result in big fat linker errors during the build if the code in question is not entirely inline in the header. This applies to GCC, and should also apply to MSVC++ 7 as well.







The original intention of namespaces (as Dejan notes) was to allow developers from different organizations to contribute parts of a single codebase without their identifiers conflicting. If everyone in an organization puts their code in a single namespace, and its name is sufficiently unique, then I enjoy this benefit of namespaces (i.e. each piece of code doesn't conflict with anyone else's code).



But it's difficult for me to see the benefit of extending this to a hierarchy. The original distinction that led to namespaces - the distinction between code coming from different organizations - isn't hierarchical. (You're either outside my organization or you're not; even if you're in a different department we ought to be able to cooperate on naming.)



Beyond that, I think dangerous things happen when a single development shop starts using hierarchical namespaces internally. For example, suppose you put your "SocketHelper" class in namespace "OurOrg_12357::Helpers::IO" and I put my own "SocketHelper" class in "OurOrg_12357::Helpers::IO::Net". We're much less likely to find out that we've both coded classes called SocketHelper than if we'd both simply used "OurOrg_12357." And since we're really in the same organization, we don't want that name collision hidden. We probably want to know about the fact that we've both written a "SocketHelper."



Unfortunately, just about everyone I've ever worked with who knew about namespaces tended to try to use them as an organizational tool. Something just feels wrong to them about putting everything in "OurOrg_12357," as if that we're somehow comparable to putting all of their files in C:\. The difference is that the file system was constructed with a different purpose than namespaces. MS-DOS 2.0 did not introduce folders so that people from other companies could put stuff on your C-drive.



Of course (and as Dejan pointed out) another big problem with namespaces like "OurOrg_12357::Helpers::IO" is that they clutter up some already very cluttered error messages. I agree wholeheartedly with that sentiment, although (again) I don't find my colleagues to be universal on this point. I think I know quite a few developers who would argue that if you find template-related error messages (or generic-related error messages in C#) to be complex, then you just don't understand templates (or generics). I don't agree with that; my feeling is that the human factor (misunderstanding or plain stupidity) needs to be ruled out as much possible in the design of a computer language just like it is in the design of other man-machine interfaces.



I think these misconceptions (or at least disagreements) fall into a category that might reasonably be called the "common sense" anti-pattern. By that I mean that too many design decisions are made because they resemble other (seemingly similar) design decisions. That is, they have the look-and-feel of good software engineering practice without actually _being_ good software engineering practice. Namespaces were made hierarchical simply because so many other things in CS legitimately are, or need to be, hierarchies (classes, file systems, etc.)



It must have felt like simple common sense to the C++ committee that namespaces should be hierarchies... unfortunately, common sense frequently does not apply to CS. After all, the ability to program is by no means "common" among the general populace. A related rule of mine is that I treat absolute statements about CS or even programming with extreme skepticism.



I think these disagreements are also examples of another anti-pattern (which might be called the "kitchen sink" anti-pattern) that legitimizes the addition of features to a language based on the argument that they can be ignored by those who don't like them. I don't like hierarchical namespaces, but there's no way I can ignore them. Any time a potential collision is squelched by a colleague's decision to use some goofy, deeply-nested namespace, then an opportunity for collaboration with that colleage is lost - regardless of my decision to simply use the top-level organizational namespace.



C++ exemplifies this "kitchen sink" anti-pattern fairly well (having been designed by a committee) but .NET is the absolute champ. Anything that even remotely resembles a good idea (e.g. functional programming) ends up being embraced by the ever-expanding .NET moniker. C++ had a bad tendency to introduce keywords with each revision... C# has a nasty tendency to introduce whole new paradigms.



That was a great article, straight to the point and ideas on unique naming of namespaces to boot.



This random number thing is an admirable sentiment; shame people aren't very good at remembering numbers like that. If you use a random number, I suppose you could guarantee its uniqueness for a thousand years or so by using a GUID ala COM, MFC, Class Wizard etc. But that's an even LONGER and less humanly meaningful namespace name!



My idea for extension to this article would be to explain a bit about how to properly use namespaces when you are inheriting from classes and templates from one namespace (say PDE, net_394324, or whatever) to another global namespace or one of your own. This would be useful to go through, because as I found out it has it's own pitfalls, and have seen nothing on that particular aspect of it on the net.



In case you can't think of a motivation to do that, think of say, specialising a std::list to something that is very specific to you - thus doesn't belong in the std namespace.



What do you think?



Cheers,



Paul







/**********************************

Paul Evans, Dorset, UK.

Personal Homepage "EnjoySoftware" @

http://www.enjoysoftware.co.uk/

**********************************/





(This is best done on a machine that has an ethernet card)



Instead of your arbitarily chooseing random things use guidgen.exe click on the registry format. Copy it and then do a



#ifndef net

#define net GUID

#endif



.

.

.



namespace net{....}



I'm not sure how long namespaces are allowed to be but I bet its some where in your compiler's documentation. Another thing to KEEP IN MIND is to remove the "{" "}" braces on the GUID AND make sure that the GUID starts out with a letter and the you remove the dashes "-" in the GUID. I havent tested this out but I bet it will work.



Jake







- Dejan







Due: 9 May 2001







Objective: Comparing both divide and conquer sorting method using traditional way, by counting the elapsed time, and mathematical way, by counting number of comparisons and movements.

Write a C program of bottom-up non-recursive MergeSort , called function NRMergeSort. You are required to modify the recursive MergeSort program discussed on the class, by removing its recursion of MergeSort, and start do (or call) Merge function from the bottom to the top, as illustrated bellow:







Inside this function or program, count the number of comparisons between entries in the input list. Whenever it is found a comparison between entries increment the comparison counter by one. Also, inside this function or program, Count the number of movements of entries in the input list. Whenever there is movement or assignment from original list to temp array, increment movement counter by one, and whenever there is movement or assignment from temp array to the original list, increment the movement counter by one.



Write a C program of MeanSort, called function MeanSort. This is a modified version of QuickSort program discussed on the class. The modified part is ONLY in choosing the pivot. The pivot of this MeanSort is an average or a mean of an input list or sub-list. Inside this function or program, count the number of comparisons between entry in the input list and the pivot. Whenever it is found a comparison between entry and pivot, increment the comparison counter by one. Also, inside this function or program, Count the number of movements of entries in the input list. Whenever there is swapping between two entries, increment the movement counter by three.



Write a main program, The main program should contain the following:



Interact with user to enter the size of the input list.



Give a user a choice (menu) either to enter the entries of the input list manually (entered by user) or let computer generating entries of random numbers.



Call both NRMergeSort and MeanSort program or function. Record the elapsed time (in seconds) of each function. Start record the time from calling the function until the function is returned.



Print all the statistics or measurement, includes elapsed time, number of comparisons, and number of movements of each NRMergeSort funtion and MeanSort function.



Print the Original (unsorted) list and the sorted list.



Implementation Guidelines:



The type of input list for the above functions is your choice. You may use General list contiguous implementation, or simple array. When you declare it, declare the size of the list or array at least 100.



The comparison and movement counter are recommended to be global variables.



To record the elapsed time, you may use the following function time() in TIME.H library. To get more accurate in measuring the elapsed time (recommended) use the function clock() in TIME.H library.



To generate integer random number use the following functions: randomize(), random(), and rand() in STDLIB.H library.



Bonus 25 Points



Bonus of 25 points is given for those students who extend this program by enabling the program to read the input from a text stream file that consist of lots of (more than 500) integer numbers. And give the flexibility to user to choose the size and the starting record of the file to be retrieved and passed as an input to the above both functions.







Deliverable and Important Note

Hand-in both hardcopy and softcopy (diskette) of program in an envelope at the beginning of class on 9 May 2001.



Make sure you follow the principle of good programming in lecture 2 note.



N0 LATE submission.



Copying other student's work may result 'F' grade on this course.





I NEED HELP PLEASE FROM ANY ONE WELCOMMMMMMMMMMMMMMMMMMMMMMMMME





Due: 9 May 2001







Objective: Comparing both divide and conquer sorting method using traditional way, by counting the elapsed time, and mathematical way, by counting number of comparisons and movements.

Write a C program of bottom-up non-recursive MergeSort , called function NRMergeSort. You are required to modify the recursive MergeSort program discussed on the class, by removing its recursion of MergeSort, and start do (or call) Merge function from the bottom to the top, as illustrated bellow:







Inside this function or program, count the number of comparisons between entries in the input list. Whenever it is found a comparison between entries increment the comparison counter by one. Also, inside this function or program, Count the number of movements of entries in the input list. Whenever there is movement or assignment from original list to temp array, increment movement counter by one, and whenever there is movement or assignment from temp array to the original list, increment the movement counter by one.



Write a C program of MeanSort, called function MeanSort. This is a modified version of QuickSort program discussed on the class. The modified part is ONLY in choosing the pivot. The pivot of this MeanSort is an average or a mean of an input list or sub-list. Inside this function or program, count the number of comparisons between entry in the input list and the pivot. Whenever it is found a comparison between entry and pivot, increment the comparison counter by one. Also, inside this function or program, Count the number of movements of entries in the input list. Whenever there is swapping between two entries, increment the movement counter by three.



Write a main program, The main program should contain the following:



Interact with user to enter the size of the input list.



Give a user a choice (menu) either to enter the entries of the input list manually (entered by user) or let computer generating entries of random numbers.



Call both NRMergeSort and MeanSort program or function. Record the elapsed time (in seconds) of each function. Start record the time from calling the function until the function is returned.



Print all the statistics or measurement, includes elapsed time, number of comparisons, and number of movements of each NRMergeSort funtion and MeanSort function.



Print the Original (unsorted) list and the sorted list.



Implementation Guidelines:



The type of input list for the above functions is your choice. You may use General list contiguous implementation, or simple array. When you declare it, declare the size of the list or array at least 100.



The comparison and movement counter are recommended to be global variables.



To record the elapsed time, you may use the following function time() in TIME.H library. To get more accurate in measuring the elapsed time (recommended) use the function clock() in TIME.H library.



To generate integer random number use the following functions: randomize(), random(), and rand() in STDLIB.H library.



Bonus 25 Points



Bonus of 25 points is given for those students who extend this program by enabling the program to read the input from a text stream file that consist of lots of (more than 500) integer numbers. And give the flexibility to user to choose the size and the starting record of the file to be retrieved and passed as an input to the above both functions.







Deliverable and Important Note

Hand-in both hardcopy and softcopy (diskette) of program in an envelope at the beginning of class on 9 May 2001.



Make sure you follow the principle of good programming in lecture 2 note.



N0 LATE submission.



Copying other student's work may result 'F' grade on this course.





I NEED HELP PLEASE FROM ANY ONE WELCOMMMMMMMMMMMMMMMMMMMMMMMMME





Use your company name, or an abbreviated version that's easy to remember and hard to mistype.

namespace AICNet; // for, say "Acme Internet Consulting"



would be a bit "cleaner" than..

namespace net_33843894; // which is subject to typos



Just a suggestion to aid readability







1. Company names can change (did somebody say "Inprise"?) and are subject to legal disputes.



2. Two people inside the same company can independently create a class with the same name.



3. Putting all the classes in the same company inside the same namespace is too large a granularity; it prevents useful software engineering practices like using the older version of a library together with the new one because they are in separate namespaces.



Dejan



namespace Www_MyCompany_Com__Networking_Ipv6WorkingGroup_SocketsReferenceImplementation_Net {... . As you point out, this can be aliased to a shorter name for humans and if it becomes the standard way of doing things, compilers, linkers, and debuggers can probably evolve use hashed representations in their internal symbol tables to save space (there's been some nice work in gcc on shortening mangled names of template classes that could probably also be adapted here).



It also suggests that at some point in the future, the C++ standards group may want to create an extension to allow true URNs to be used as namespace identifiers. I would imagine something like adding a keyword _urn to be used like namespace _urn(http://www.mycompany.com/networking/ipv6-working-group/sockets-reference-implementation/net) {... .



As far as URNs not being truly persistent, this is a problem the whole world faces. Since URNs are quickly becoming the standard for namespaces, if C++ authors adopt URN-like namespace names, then they will benefit from being able to adapt the same kinds of solutions that the XML and Java communities do.



He was allying himself to science, for what was science but the absence of prejudice backed by the presence of money? --- Henry James, The Golden Bowl

