Managing locking for access












1














I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock, I wanted something with a lot of syntactic sugar so that once the lock is acquired the resource (object) is used via a reference without a need for special getters and setters.



namespace Lockable {
public delegate void ActionRef<REF>(ref REF r1);
public delegate void ActionIn<REF>(in REF r1);
public delegate RES FuncRef<REF, RES>(ref REF r1);
public delegate RES FuncIn<REF, RES>(in REF r1);
public delegate void ActionRef<REF1, REF2>(ref REF1 r1, ref REF2 r2);
public delegate void ActionIn<REF1, REF2>(in REF1 r1, in REF2 r2);
public delegate RES FuncRef<REF1, REF2, RES>(ref REF1 r1, ref REF2 r2);
public delegate RES FuncIn<REF1, REF2, RES>(in REF1 r1, in REF2 r2);
public delegate void ActionRef<REF1, REF2, REF3>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate void ActionIn<REF1, REF2, REF3>(in REF1 r1, in REF2 r2, in REF3 r3);
public delegate RES FuncRef<REF1, REF2, REF3, RES>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate RES FuncIn<REF1, REF2, REF3, RES>(in REF1 r1, in REF2 r2, in REF3 r3);

public class Lockable<T> {
public Lockable() { }
public Lockable(T val) => this.val = val;
readonly object theLock = new object();
T val;

public void Lock(ActionRef<T> f) { lock (theLock) f(ref val); }
public void Lock(ActionIn<T> f) { lock (theLock) f(in val); }
public TRES Lock<TRES>(FuncRef<T, TRES> f) { lock (theLock) return f(ref val); }
public TRES Lock<TRES>(FuncIn<T, TRES> f) { lock (theLock) return f(in val); }

public class TwoLockable<T2> {
public TwoLockable(Lockable<T> val1, Lockable<T2> val2) { this.l1 = val1; this.l2 = val2; }
readonly Lockable<T> l1;
readonly Lockable<T2> l2;

public void Lock(ActionRef<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(ref l1.val, ref l2.val); }
public void Lock(ActionIn<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(in l1.val, in l2.val); }
public TRES Lock<TRES>(FuncRef<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(ref l1.val, ref l2.val); }
public TRES Lock<TRES>(FuncIn<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(in l1.val, in l2.val); }

public class ThreeLockable<T3> {
public ThreeLockable(Lockable<T> val1, Lockable<T2> val2, Lockable<T3> val3) { this.l1 = val1; this.l2 = val2; this.l3 = val3; }
readonly Lockable<T> l1;
readonly Lockable<T2> l2;
readonly Lockable<T3> l3;

public void Lock(ActionRef<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(ref l1.val, ref l2.val, ref l3.val); }
public void Lock(ActionIn<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(in l1.val, in l2.val, in l3.val); }
public TRES Lock<TRES>(FuncRef<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(ref l1.val, ref l2.val, ref l3.val); }
public TRES Lock<TRES>(FuncIn<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(in l1.val, in l2.val, in l3.val); }
}
public ThreeLockable<T3> Combine<T3>(Lockable<T3> l3) => new ThreeLockable<T3>(this.l1, this.l2, l3);
}
public TwoLockable<T2> Combine<T2>(Lockable<T2> l2) => new TwoLockable<T2>(this, l2);
}
}


With that code, I can now do this:



class State {
public readonly Lockable<Customers> Customers = new Lockable<Customers>(new Customers());
public readonly Lockable<Agents> Agents = new Lockable<Agents>(new Agents());
}


and then:



var S = new State(); // usually this will be a static/singleton


now the only way to access Customers is via the Lock method like this:



S.Customers.Lock((ref Customers Customers) => {
Log(Customers.GetPhone("John"));
Customers=new Customers();
Customers.Add("Mary");
});


or to return a value I can do:



var count = S.Customers.Lock((ref Customers Customers) => Customers.Count());


Note that you can use the above to modify the state without locking i.e.:



var UnlockedCustomers = S.Customers.Lock((ref Customers Customers) => Customers);
UnlockedCustomers.Add("Dave"); // unlocked !!!


This is by design as I wanted to allow that but make it very explicit in the code (unlike forgetting to lock..), if this is not desired the locks returning values need to be removed (FuncRefs etc.).



If I need to lock both I combine the Locks:



S.Customers.Combine(S.Agents).Lock((ref Customers Customers, ref Agents Agents) => {
// both Agents and Customers are locked here !
});


I included versions of combining 2 and 3 Lockables. More can be added. Note that as with locks you have to always combine in the same order or risk deadlocks. It would be interesting to think of ways around this.










share|improve this question









New contributor




kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    What you may and may not do after receiving answers
    – Jamal
    16 mins ago
















1














I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock, I wanted something with a lot of syntactic sugar so that once the lock is acquired the resource (object) is used via a reference without a need for special getters and setters.



namespace Lockable {
public delegate void ActionRef<REF>(ref REF r1);
public delegate void ActionIn<REF>(in REF r1);
public delegate RES FuncRef<REF, RES>(ref REF r1);
public delegate RES FuncIn<REF, RES>(in REF r1);
public delegate void ActionRef<REF1, REF2>(ref REF1 r1, ref REF2 r2);
public delegate void ActionIn<REF1, REF2>(in REF1 r1, in REF2 r2);
public delegate RES FuncRef<REF1, REF2, RES>(ref REF1 r1, ref REF2 r2);
public delegate RES FuncIn<REF1, REF2, RES>(in REF1 r1, in REF2 r2);
public delegate void ActionRef<REF1, REF2, REF3>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate void ActionIn<REF1, REF2, REF3>(in REF1 r1, in REF2 r2, in REF3 r3);
public delegate RES FuncRef<REF1, REF2, REF3, RES>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate RES FuncIn<REF1, REF2, REF3, RES>(in REF1 r1, in REF2 r2, in REF3 r3);

public class Lockable<T> {
public Lockable() { }
public Lockable(T val) => this.val = val;
readonly object theLock = new object();
T val;

public void Lock(ActionRef<T> f) { lock (theLock) f(ref val); }
public void Lock(ActionIn<T> f) { lock (theLock) f(in val); }
public TRES Lock<TRES>(FuncRef<T, TRES> f) { lock (theLock) return f(ref val); }
public TRES Lock<TRES>(FuncIn<T, TRES> f) { lock (theLock) return f(in val); }

public class TwoLockable<T2> {
public TwoLockable(Lockable<T> val1, Lockable<T2> val2) { this.l1 = val1; this.l2 = val2; }
readonly Lockable<T> l1;
readonly Lockable<T2> l2;

public void Lock(ActionRef<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(ref l1.val, ref l2.val); }
public void Lock(ActionIn<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(in l1.val, in l2.val); }
public TRES Lock<TRES>(FuncRef<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(ref l1.val, ref l2.val); }
public TRES Lock<TRES>(FuncIn<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(in l1.val, in l2.val); }

public class ThreeLockable<T3> {
public ThreeLockable(Lockable<T> val1, Lockable<T2> val2, Lockable<T3> val3) { this.l1 = val1; this.l2 = val2; this.l3 = val3; }
readonly Lockable<T> l1;
readonly Lockable<T2> l2;
readonly Lockable<T3> l3;

public void Lock(ActionRef<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(ref l1.val, ref l2.val, ref l3.val); }
public void Lock(ActionIn<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(in l1.val, in l2.val, in l3.val); }
public TRES Lock<TRES>(FuncRef<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(ref l1.val, ref l2.val, ref l3.val); }
public TRES Lock<TRES>(FuncIn<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(in l1.val, in l2.val, in l3.val); }
}
public ThreeLockable<T3> Combine<T3>(Lockable<T3> l3) => new ThreeLockable<T3>(this.l1, this.l2, l3);
}
public TwoLockable<T2> Combine<T2>(Lockable<T2> l2) => new TwoLockable<T2>(this, l2);
}
}


With that code, I can now do this:



class State {
public readonly Lockable<Customers> Customers = new Lockable<Customers>(new Customers());
public readonly Lockable<Agents> Agents = new Lockable<Agents>(new Agents());
}


and then:



var S = new State(); // usually this will be a static/singleton


now the only way to access Customers is via the Lock method like this:



S.Customers.Lock((ref Customers Customers) => {
Log(Customers.GetPhone("John"));
Customers=new Customers();
Customers.Add("Mary");
});


or to return a value I can do:



var count = S.Customers.Lock((ref Customers Customers) => Customers.Count());


Note that you can use the above to modify the state without locking i.e.:



var UnlockedCustomers = S.Customers.Lock((ref Customers Customers) => Customers);
UnlockedCustomers.Add("Dave"); // unlocked !!!


This is by design as I wanted to allow that but make it very explicit in the code (unlike forgetting to lock..), if this is not desired the locks returning values need to be removed (FuncRefs etc.).



If I need to lock both I combine the Locks:



S.Customers.Combine(S.Agents).Lock((ref Customers Customers, ref Agents Agents) => {
// both Agents and Customers are locked here !
});


I included versions of combining 2 and 3 Lockables. More can be added. Note that as with locks you have to always combine in the same order or risk deadlocks. It would be interesting to think of ways around this.










share|improve this question









New contributor




kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    What you may and may not do after receiving answers
    – Jamal
    16 mins ago














1












1








1







I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock, I wanted something with a lot of syntactic sugar so that once the lock is acquired the resource (object) is used via a reference without a need for special getters and setters.



namespace Lockable {
public delegate void ActionRef<REF>(ref REF r1);
public delegate void ActionIn<REF>(in REF r1);
public delegate RES FuncRef<REF, RES>(ref REF r1);
public delegate RES FuncIn<REF, RES>(in REF r1);
public delegate void ActionRef<REF1, REF2>(ref REF1 r1, ref REF2 r2);
public delegate void ActionIn<REF1, REF2>(in REF1 r1, in REF2 r2);
public delegate RES FuncRef<REF1, REF2, RES>(ref REF1 r1, ref REF2 r2);
public delegate RES FuncIn<REF1, REF2, RES>(in REF1 r1, in REF2 r2);
public delegate void ActionRef<REF1, REF2, REF3>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate void ActionIn<REF1, REF2, REF3>(in REF1 r1, in REF2 r2, in REF3 r3);
public delegate RES FuncRef<REF1, REF2, REF3, RES>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate RES FuncIn<REF1, REF2, REF3, RES>(in REF1 r1, in REF2 r2, in REF3 r3);

public class Lockable<T> {
public Lockable() { }
public Lockable(T val) => this.val = val;
readonly object theLock = new object();
T val;

public void Lock(ActionRef<T> f) { lock (theLock) f(ref val); }
public void Lock(ActionIn<T> f) { lock (theLock) f(in val); }
public TRES Lock<TRES>(FuncRef<T, TRES> f) { lock (theLock) return f(ref val); }
public TRES Lock<TRES>(FuncIn<T, TRES> f) { lock (theLock) return f(in val); }

public class TwoLockable<T2> {
public TwoLockable(Lockable<T> val1, Lockable<T2> val2) { this.l1 = val1; this.l2 = val2; }
readonly Lockable<T> l1;
readonly Lockable<T2> l2;

public void Lock(ActionRef<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(ref l1.val, ref l2.val); }
public void Lock(ActionIn<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(in l1.val, in l2.val); }
public TRES Lock<TRES>(FuncRef<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(ref l1.val, ref l2.val); }
public TRES Lock<TRES>(FuncIn<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(in l1.val, in l2.val); }

public class ThreeLockable<T3> {
public ThreeLockable(Lockable<T> val1, Lockable<T2> val2, Lockable<T3> val3) { this.l1 = val1; this.l2 = val2; this.l3 = val3; }
readonly Lockable<T> l1;
readonly Lockable<T2> l2;
readonly Lockable<T3> l3;

public void Lock(ActionRef<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(ref l1.val, ref l2.val, ref l3.val); }
public void Lock(ActionIn<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(in l1.val, in l2.val, in l3.val); }
public TRES Lock<TRES>(FuncRef<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(ref l1.val, ref l2.val, ref l3.val); }
public TRES Lock<TRES>(FuncIn<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(in l1.val, in l2.val, in l3.val); }
}
public ThreeLockable<T3> Combine<T3>(Lockable<T3> l3) => new ThreeLockable<T3>(this.l1, this.l2, l3);
}
public TwoLockable<T2> Combine<T2>(Lockable<T2> l2) => new TwoLockable<T2>(this, l2);
}
}


With that code, I can now do this:



class State {
public readonly Lockable<Customers> Customers = new Lockable<Customers>(new Customers());
public readonly Lockable<Agents> Agents = new Lockable<Agents>(new Agents());
}


and then:



var S = new State(); // usually this will be a static/singleton


now the only way to access Customers is via the Lock method like this:



S.Customers.Lock((ref Customers Customers) => {
Log(Customers.GetPhone("John"));
Customers=new Customers();
Customers.Add("Mary");
});


or to return a value I can do:



var count = S.Customers.Lock((ref Customers Customers) => Customers.Count());


Note that you can use the above to modify the state without locking i.e.:



var UnlockedCustomers = S.Customers.Lock((ref Customers Customers) => Customers);
UnlockedCustomers.Add("Dave"); // unlocked !!!


This is by design as I wanted to allow that but make it very explicit in the code (unlike forgetting to lock..), if this is not desired the locks returning values need to be removed (FuncRefs etc.).



If I need to lock both I combine the Locks:



S.Customers.Combine(S.Agents).Lock((ref Customers Customers, ref Agents Agents) => {
// both Agents and Customers are locked here !
});


I included versions of combining 2 and 3 Lockables. More can be added. Note that as with locks you have to always combine in the same order or risk deadlocks. It would be interesting to think of ways around this.










share|improve this question









New contributor




kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I've been working for a while on locking resources (state objects) so that the only way to access them is by acquiring a lock, I wanted something with a lot of syntactic sugar so that once the lock is acquired the resource (object) is used via a reference without a need for special getters and setters.



namespace Lockable {
public delegate void ActionRef<REF>(ref REF r1);
public delegate void ActionIn<REF>(in REF r1);
public delegate RES FuncRef<REF, RES>(ref REF r1);
public delegate RES FuncIn<REF, RES>(in REF r1);
public delegate void ActionRef<REF1, REF2>(ref REF1 r1, ref REF2 r2);
public delegate void ActionIn<REF1, REF2>(in REF1 r1, in REF2 r2);
public delegate RES FuncRef<REF1, REF2, RES>(ref REF1 r1, ref REF2 r2);
public delegate RES FuncIn<REF1, REF2, RES>(in REF1 r1, in REF2 r2);
public delegate void ActionRef<REF1, REF2, REF3>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate void ActionIn<REF1, REF2, REF3>(in REF1 r1, in REF2 r2, in REF3 r3);
public delegate RES FuncRef<REF1, REF2, REF3, RES>(ref REF1 r1, ref REF2 r2, ref REF3 r3);
public delegate RES FuncIn<REF1, REF2, REF3, RES>(in REF1 r1, in REF2 r2, in REF3 r3);

public class Lockable<T> {
public Lockable() { }
public Lockable(T val) => this.val = val;
readonly object theLock = new object();
T val;

public void Lock(ActionRef<T> f) { lock (theLock) f(ref val); }
public void Lock(ActionIn<T> f) { lock (theLock) f(in val); }
public TRES Lock<TRES>(FuncRef<T, TRES> f) { lock (theLock) return f(ref val); }
public TRES Lock<TRES>(FuncIn<T, TRES> f) { lock (theLock) return f(in val); }

public class TwoLockable<T2> {
public TwoLockable(Lockable<T> val1, Lockable<T2> val2) { this.l1 = val1; this.l2 = val2; }
readonly Lockable<T> l1;
readonly Lockable<T2> l2;

public void Lock(ActionRef<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(ref l1.val, ref l2.val); }
public void Lock(ActionIn<T, T2> f) { lock (l1.theLock) lock (l2.theLock) f(in l1.val, in l2.val); }
public TRES Lock<TRES>(FuncRef<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(ref l1.val, ref l2.val); }
public TRES Lock<TRES>(FuncIn<T, T2, TRES> f) { lock (l1.theLock) lock (l2.theLock) return f(in l1.val, in l2.val); }

public class ThreeLockable<T3> {
public ThreeLockable(Lockable<T> val1, Lockable<T2> val2, Lockable<T3> val3) { this.l1 = val1; this.l2 = val2; this.l3 = val3; }
readonly Lockable<T> l1;
readonly Lockable<T2> l2;
readonly Lockable<T3> l3;

public void Lock(ActionRef<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(ref l1.val, ref l2.val, ref l3.val); }
public void Lock(ActionIn<T, T2, T3> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) f(in l1.val, in l2.val, in l3.val); }
public TRES Lock<TRES>(FuncRef<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(ref l1.val, ref l2.val, ref l3.val); }
public TRES Lock<TRES>(FuncIn<T, T2, T3, TRES> f) { lock (l1.theLock) lock (l2.theLock) lock (l3.theLock) return f(in l1.val, in l2.val, in l3.val); }
}
public ThreeLockable<T3> Combine<T3>(Lockable<T3> l3) => new ThreeLockable<T3>(this.l1, this.l2, l3);
}
public TwoLockable<T2> Combine<T2>(Lockable<T2> l2) => new TwoLockable<T2>(this, l2);
}
}


With that code, I can now do this:



class State {
public readonly Lockable<Customers> Customers = new Lockable<Customers>(new Customers());
public readonly Lockable<Agents> Agents = new Lockable<Agents>(new Agents());
}


and then:



var S = new State(); // usually this will be a static/singleton


now the only way to access Customers is via the Lock method like this:



S.Customers.Lock((ref Customers Customers) => {
Log(Customers.GetPhone("John"));
Customers=new Customers();
Customers.Add("Mary");
});


or to return a value I can do:



var count = S.Customers.Lock((ref Customers Customers) => Customers.Count());


Note that you can use the above to modify the state without locking i.e.:



var UnlockedCustomers = S.Customers.Lock((ref Customers Customers) => Customers);
UnlockedCustomers.Add("Dave"); // unlocked !!!


This is by design as I wanted to allow that but make it very explicit in the code (unlike forgetting to lock..), if this is not desired the locks returning values need to be removed (FuncRefs etc.).



If I need to lock both I combine the Locks:



S.Customers.Combine(S.Agents).Lock((ref Customers Customers, ref Agents Agents) => {
// both Agents and Customers are locked here !
});


I included versions of combining 2 and 3 Lockables. More can be added. Note that as with locks you have to always combine in the same order or risk deadlocks. It would be interesting to think of ways around this.







c#






share|improve this question









New contributor




kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 4 mins ago







kofifus













New contributor




kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 7 hours ago









kofifuskofifus

1093




1093




New contributor




kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






kofifus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    What you may and may not do after receiving answers
    – Jamal
    16 mins ago














  • 1




    What you may and may not do after receiving answers
    – Jamal
    16 mins ago








1




1




What you may and may not do after receiving answers
– Jamal
16 mins ago




What you may and may not do after receiving answers
– Jamal
16 mins ago










1 Answer
1






active

oldest

votes


















1














Welcome to maintanance-hell



The code in question is unreadable and un-reviewable. Stuffing that much code in single-lines is just horrible.



Before Sam the maintainer would try to fix a bug or add some new functionality to this code Sam would invent a time-travelling-machine to travel back in time and would have some serious talk with you which could get physical.



Code should be written in such a way that it is as easiest as possible, for Sam the maintainer or anybody who reads the code, to grasp at first glance what the code is about.






share|improve this answer





















  • yeah well I disagree, having the code in single lines here helps to easily see the differences between the different functions which are very similar, anyway this should be a comment not an answer, you want it your style run it though VS formatter .. I don't know Sam but if he goes into meltdown because there're two statements on one line maybe he shouldn't be in IT ..
    – kofifus
    1 hour ago












  • @kofifus if you cannot write human-readable code maybe it's you who shouldn't be in IT...
    – t3chb0t
    10 mins ago











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






kofifus is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211147%2fmanaging-locking-for-access%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Welcome to maintanance-hell



The code in question is unreadable and un-reviewable. Stuffing that much code in single-lines is just horrible.



Before Sam the maintainer would try to fix a bug or add some new functionality to this code Sam would invent a time-travelling-machine to travel back in time and would have some serious talk with you which could get physical.



Code should be written in such a way that it is as easiest as possible, for Sam the maintainer or anybody who reads the code, to grasp at first glance what the code is about.






share|improve this answer





















  • yeah well I disagree, having the code in single lines here helps to easily see the differences between the different functions which are very similar, anyway this should be a comment not an answer, you want it your style run it though VS formatter .. I don't know Sam but if he goes into meltdown because there're two statements on one line maybe he shouldn't be in IT ..
    – kofifus
    1 hour ago












  • @kofifus if you cannot write human-readable code maybe it's you who shouldn't be in IT...
    – t3chb0t
    10 mins ago
















1














Welcome to maintanance-hell



The code in question is unreadable and un-reviewable. Stuffing that much code in single-lines is just horrible.



Before Sam the maintainer would try to fix a bug or add some new functionality to this code Sam would invent a time-travelling-machine to travel back in time and would have some serious talk with you which could get physical.



Code should be written in such a way that it is as easiest as possible, for Sam the maintainer or anybody who reads the code, to grasp at first glance what the code is about.






share|improve this answer





















  • yeah well I disagree, having the code in single lines here helps to easily see the differences between the different functions which are very similar, anyway this should be a comment not an answer, you want it your style run it though VS formatter .. I don't know Sam but if he goes into meltdown because there're two statements on one line maybe he shouldn't be in IT ..
    – kofifus
    1 hour ago












  • @kofifus if you cannot write human-readable code maybe it's you who shouldn't be in IT...
    – t3chb0t
    10 mins ago














1












1








1






Welcome to maintanance-hell



The code in question is unreadable and un-reviewable. Stuffing that much code in single-lines is just horrible.



Before Sam the maintainer would try to fix a bug or add some new functionality to this code Sam would invent a time-travelling-machine to travel back in time and would have some serious talk with you which could get physical.



Code should be written in such a way that it is as easiest as possible, for Sam the maintainer or anybody who reads the code, to grasp at first glance what the code is about.






share|improve this answer












Welcome to maintanance-hell



The code in question is unreadable and un-reviewable. Stuffing that much code in single-lines is just horrible.



Before Sam the maintainer would try to fix a bug or add some new functionality to this code Sam would invent a time-travelling-machine to travel back in time and would have some serious talk with you which could get physical.



Code should be written in such a way that it is as easiest as possible, for Sam the maintainer or anybody who reads the code, to grasp at first glance what the code is about.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 hours ago









HeslacherHeslacher

45k460155




45k460155












  • yeah well I disagree, having the code in single lines here helps to easily see the differences between the different functions which are very similar, anyway this should be a comment not an answer, you want it your style run it though VS formatter .. I don't know Sam but if he goes into meltdown because there're two statements on one line maybe he shouldn't be in IT ..
    – kofifus
    1 hour ago












  • @kofifus if you cannot write human-readable code maybe it's you who shouldn't be in IT...
    – t3chb0t
    10 mins ago


















  • yeah well I disagree, having the code in single lines here helps to easily see the differences between the different functions which are very similar, anyway this should be a comment not an answer, you want it your style run it though VS formatter .. I don't know Sam but if he goes into meltdown because there're two statements on one line maybe he shouldn't be in IT ..
    – kofifus
    1 hour ago












  • @kofifus if you cannot write human-readable code maybe it's you who shouldn't be in IT...
    – t3chb0t
    10 mins ago
















yeah well I disagree, having the code in single lines here helps to easily see the differences between the different functions which are very similar, anyway this should be a comment not an answer, you want it your style run it though VS formatter .. I don't know Sam but if he goes into meltdown because there're two statements on one line maybe he shouldn't be in IT ..
– kofifus
1 hour ago






yeah well I disagree, having the code in single lines here helps to easily see the differences between the different functions which are very similar, anyway this should be a comment not an answer, you want it your style run it though VS formatter .. I don't know Sam but if he goes into meltdown because there're two statements on one line maybe he shouldn't be in IT ..
– kofifus
1 hour ago














@kofifus if you cannot write human-readable code maybe it's you who shouldn't be in IT...
– t3chb0t
10 mins ago




@kofifus if you cannot write human-readable code maybe it's you who shouldn't be in IT...
– t3chb0t
10 mins ago










kofifus is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















kofifus is a new contributor. Be nice, and check out our Code of Conduct.













kofifus is a new contributor. Be nice, and check out our Code of Conduct.












kofifus is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211147%2fmanaging-locking-for-access%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python