- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "A question about classes / enumerated types/ best practice etc.."
Collapse
-
so what in C#
public readonly int X;
then if constants are like readonly variables?
Leave a comment:
-
Constants in computer field is more like read only values - we call them constants to help avoid errorneous assignment and allow compiler to optimise things better, however it does not mean they won't or should not change at all.
Leave a comment:
-
I would largely agree. But days of the week is maybe a bad example. Ordinally you're fine but the actual name of the day is dependant upon environment and is therefore a configuration setting (by your reasonable definition).Originally posted by DimPrawnConstants should be constants, like days of the week, PI, etc so it shouldn't cause a problem, BUT people declare constants for things like tax rates, telephone numbers and tulip like this they deserved to get burned.
Configuration settings are not constants. Constants are things that are constant, FOREVER.
It does seem a bit of a flaw though. Given the way it works I *think* that it would be better if it was not possible to make constants public or that they behaved as read only properties.
Previously they were defined in a compile time resource - some sort oh header file. If they are defined in some sort of run time resource the it is reasonable to expect them to change if the resource that defines them changes.
[Of course there would be a minor performance hit if they were treated as read only properties]
Leave a comment:
-
Constants should be constants, like days of the week, PI, etc so it shouldn't cause a problem, BUT people declare constants for things like tax rates, telephone numbers and tulip like this they deserved to get burned.
Configuration settings are not constants. Constants are things that are constant, FOREVER.
Leave a comment:
-
Yes, it seems to me that's compiler issue really - a constant does not mean it will never change, it just means it won't change during run-time of THAT DLL, seems like risky optimisation in compiler: they should have been performing this optimisation once DLL is loaded and current value of constant is obtained.
I was not argueing just was trying to understand
Leave a comment:
-
Don't know. I wasn't trying to start a quizOriginally posted by AtWBut if you strong name single DLL that you release as a patch - would that take care of the issue or not?
The situation is really simple. Compiling assembly B embeds the compile time values of public constants of assembly A into B. Deploy a new version of Assembly A (which is a valid thing to do). Oops, assembly A does not use the new "constant" values.
Now, if the assembly is strong named then one of two thing would happen (given I don't use strong naming this is of course just my expectation):-
1) The application fails to load because the version number has changed. This would presumably manifest itself as a type load exception.
2) The application loads the old version of the assembly (i.e. not the new one) if it can be located through assembly probing.
This seems to be a remarkably long winded way of trying to get you to concede my original point. "Public constants can cause trouble"
Leave a comment:
-
But if you strong name single DLL that you release as a patch - would that take care of the issue or not?
Leave a comment:
-
Yes, but then that stuffs the deployment model of just issuing a patch to the erroneous DLL.Originally posted by AtWWould not strong naming take care of this situation, which is effectively multiple versions of same named DLL?
But this started as a note to the OP of a reason why public constants may be a bad idea in some cases - which was the entire point. i.e. Do this and this will happen. It might be unhelpful.
Leave a comment:
-
Would not strong naming take care of this situation, which is effectively multiple versions of same named DLL?
Leave a comment:
-
Yes but the (dubious) point is that the normal expectation is that a client DLL is dependant upon that dll at run time - not at compile time. It's not an entirely unreasonable assumption that shipping the changed dll should satisfy the clients requirements for it referred methods/properties/constants. It only satisfies the first two. Thus it is an inconsistancy.
Leave a comment:
-
But surely deployment of a patch would include deployment of all changed DLLs, which for practical purposes means all of them? I generally avoid referencing DLLs (unless they never change, and by that I mean never) directly, I prefer to create solution with all relevant projects in the same solution, so that build of it would ensure everything is up to date.
Leave a comment:
-
Agreed, but the problem relates more to deployment of a later patch. This exemplefies the issue rather better than I did.Originally posted by AtWI am pretty sure almost all assemblies are copied into apps directory by VS, so if you change some dependency you need to recompile everything that depends on it.
http://haacked.com/archive/2005/01/02/1796.aspx
Leave a comment:
-
I am pretty sure almost all assemblies are copied into apps directory by VS, so if you change some dependency you need to recompile everything that depends on it.
Leave a comment:
-
This may well not be the case with enums (I doubt it is) but be careful with public constants in other assemblys. They are copied into a referencing assembly at compile time, thus if the constant is changed and the client assembly is not recompiled then you are stuffed. Expose them as properties instead and use that. Of course this behaviour may have changed since I fell over it but I cant be bothered to check.
Leave a comment:
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers

Leave a comment: