Passing an object into a method which changes the object, is it a common
(anti-)pattern?
I am reading about common code smells in Martin Fowler's Refactoring book.
In that context, I was wondering about a pattern I am seeing in a code
base, and wether one could objectively consider it an anti-pattern.
The pattern is one where a object is passed as an argument to one or more
methods, all of which change the object's state, but none of which return
the object. So it is relying on the pass by reference nature of (in this
case) C#/.NET.
var something = new Thing();
// ...
Foo(something);
int result = Bar(something, 42);
Baz(something);
I find that (especially when methods are not named appropriately) I need
to look into such methods to understand if the object's state has changed.
It makes code comprehension more complex, since I need to track multiple
levels of the call-stack.
I'd like to propose to improve such code to return another (cloned) object
with the new state, or anything that is needed to change the object at the
call-site.
var something1 = new Thing();
// ...
// Let's return a new instance of Thing
var something2 = Foo(something1);
// Let's use out param to 'return' other info about the operation
int result;
var something3 = Bar(something2, out result);
// If necessary, let's capture and make explicit complex changes
var changes = Baz(something3)
something3.Apply(changes);
To me it seems the first pattern is chosen on the assumption that it is
less work, or requires less lines of code, or allows us to both change the
object, and return some other piece of information, or is more efficient
since we have less instances.
I illustrate an alternative, but to propose it, one needs to have
arguments against the original solution. What, if any, arguments can be
made to make the case that the original solution is an anti-pattern?
And what is wrong with my alternative solution?
Monday, 19 August 2013
How do we cluster papers by analyzing title and abstract into various subject?
How do we cluster papers by analyzing title and abstract into various
subject?
How do we cluster papers/articles by analyzing title and abstract into
various subject categories like Mathematics, Business, Economics,
Psychology and more detailed like Industrial Behavior Psychology etc?
subject?
How do we cluster papers/articles by analyzing title and abstract into
various subject categories like Mathematics, Business, Economics,
Psychology and more detailed like Industrial Behavior Psychology etc?
Sunday, 18 August 2013
Update Manager issues
Update Manager issues
I am still getting used to dual running Ubuntu on my Windows 7 machine
using Wubi. I currently have Ubuntu 12.01 and want to upgrade to 13.04.
According to the instructions here
:http://www.ubuntu.com/download/desktop/upgrade
I first need to launch the dash and search for an "Upgrade Manager". I do
that but the only option I get is a software updater.
Any help?
PS, I am still getting used to using a terminal so I would really
appreciate not using the terminal quite yet till I am more familiar with
it (if at all possible).
I am still getting used to dual running Ubuntu on my Windows 7 machine
using Wubi. I currently have Ubuntu 12.01 and want to upgrade to 13.04.
According to the instructions here
:http://www.ubuntu.com/download/desktop/upgrade
I first need to launch the dash and search for an "Upgrade Manager". I do
that but the only option I get is a software updater.
Any help?
PS, I am still getting used to using a terminal so I would really
appreciate not using the terminal quite yet till I am more familiar with
it (if at all possible).
Specialize template is_string
Specialize template is_string
I have a class that overloads a lot of members for different types as
follows:
template<typename T, typename Allocator>
Stream& operator << (Stream &Destination, const std::list<T, Allocator>
&Value)
template<typename T, typename Allocator>
Stream& operator << (Stream &Destination, const std::vector<T, Allocator>
&Value)
And now I'm trying to specialize it for strings.. I created an is string
using:
...
...
template<>
struct is_string<std::string> : std::true_type {};
...
...
and then I want to make it specialized as follows:
template<typename T = typename is_literal<T>::value_type> //How?
Stream& operator << (Stream &Destination, const typename
is_literal<T>::value_type &Value)
{
std::cout<<"HERE";
return Destination;
}
//I can do:
template<typename T = std::string> //works fine.
Stream& operator << (Stream &Destination, const typename
is_literal<T>::value_type &Value)
{
std::cout<<"HERE";
return Destination;
}
How can I fix the string one so that it works for all string types so that
T is whatever string type passed?
I have a class that overloads a lot of members for different types as
follows:
template<typename T, typename Allocator>
Stream& operator << (Stream &Destination, const std::list<T, Allocator>
&Value)
template<typename T, typename Allocator>
Stream& operator << (Stream &Destination, const std::vector<T, Allocator>
&Value)
And now I'm trying to specialize it for strings.. I created an is string
using:
...
...
template<>
struct is_string<std::string> : std::true_type {};
...
...
and then I want to make it specialized as follows:
template<typename T = typename is_literal<T>::value_type> //How?
Stream& operator << (Stream &Destination, const typename
is_literal<T>::value_type &Value)
{
std::cout<<"HERE";
return Destination;
}
//I can do:
template<typename T = std::string> //works fine.
Stream& operator << (Stream &Destination, const typename
is_literal<T>::value_type &Value)
{
std::cout<<"HERE";
return Destination;
}
How can I fix the string one so that it works for all string types so that
T is whatever string type passed?
Calculate the determinant of a matrix multiplied by itself confirmation
Calculate the determinant of a matrix multiplied by itself confirmation
If $ det(B) = 4 $ is the value of $ det(B^{10}) = 4^{10} $
Does that also mean that $ det(B^{-2}) = \frac{1}{(det(B))^2} $
Or do I have this completely wrong?
If $ det(B) = 4 $ is the value of $ det(B^{10}) = 4^{10} $
Does that also mean that $ det(B^{-2}) = \frac{1}{(det(B))^2} $
Or do I have this completely wrong?
File Transfer over Internet
File Transfer over Internet
I am developing a Personal Assistance Program which lets me help my Family
Members and maybe Friends over the internet when they have trouble with
their Computer as they are non-tech.
I will be running the Server and Clients (Family Computers) will connect
to me. I have tried to make it as simple as possible by only allowing the
Client to Show a Chat window and nothing else. This is because they always
fail in doing anything I tell them so I have to do everything remotely.
Now I want to Implement File Transfer.I thought of using TCP/UDP but the
time and effort to code and test it are just too much for me.
Is there any other way which I can use to Transfer files over Internet?
Minimum Requirements:
1) It should be reliable
2) Resume Capability
3) Able to Transfer very large files > 1 gb
PS. It would also be nice If a Client could Transfer files to Other
client's directly as well such as Pictures/Movies etc.
Don't suggest me to use TeamViewer/LogMeIn/Join.me etc etc. It has it's
own problems as well and I want to code to do this myself so I can
implement extra features.
I am developing a Personal Assistance Program which lets me help my Family
Members and maybe Friends over the internet when they have trouble with
their Computer as they are non-tech.
I will be running the Server and Clients (Family Computers) will connect
to me. I have tried to make it as simple as possible by only allowing the
Client to Show a Chat window and nothing else. This is because they always
fail in doing anything I tell them so I have to do everything remotely.
Now I want to Implement File Transfer.I thought of using TCP/UDP but the
time and effort to code and test it are just too much for me.
Is there any other way which I can use to Transfer files over Internet?
Minimum Requirements:
1) It should be reliable
2) Resume Capability
3) Able to Transfer very large files > 1 gb
PS. It would also be nice If a Client could Transfer files to Other
client's directly as well such as Pictures/Movies etc.
Don't suggest me to use TeamViewer/LogMeIn/Join.me etc etc. It has it's
own problems as well and I want to code to do this myself so I can
implement extra features.
Google Apps Email - how to add several domain names?
Google Apps Email - how to add several domain names?
I signed up for Google Apps for Businesses, paid (I guess) $5 a month for
this service. My primary goal is to use Google Apps for email accounts for
my projects (with custom domains).
I added one custom domain, everything is working well. Now I have a
problem, because I would need to add another 2 custom domains, but I don't
see nowhere an option to do that.
How to tackle this situation?
Thanks
I signed up for Google Apps for Businesses, paid (I guess) $5 a month for
this service. My primary goal is to use Google Apps for email accounts for
my projects (with custom domains).
I added one custom domain, everything is working well. Now I have a
problem, because I would need to add another 2 custom domains, but I don't
see nowhere an option to do that.
How to tackle this situation?
Thanks
Subscribe to:
Posts (Atom)