Reputation
Top tag
Next privilege 200 Rep.
See reduced ads
Badges
6
Newest
 Editor
Impact
~297 people reached

  • 0 posts edited
  • 0 helpful flags
  • 117 votes cast
Jan
21
comment class in OOP language and type
A type is more than just a range of possible values, types also have defined purpose and behavior.
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782. YES, different choices would have had different results. C has been successful largely because of its efficiency, Any scheme allowing for run-time identification of type would have killed that efficiency. It would require always returning an extra value holding the type identifier, evaluation of the type identifier and emitting dozens of extra instructions that ultimately would never be executed. As others have stated, the compiler does not know the return-value. Unless the return-value is a constant it never really knows the return-value.
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@sweethome of course the full story is more complicated than is allowed (or in this case I felt prudent) to place in a comment.
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782: Bottom line to the question: Why does language X do/require Y? Because that is the choice the designers made. You seem to be are arguing that the designers of the one of the most successful languages ever should have made different choices decades ago rather than trying to understand those choices in the context they were made. The answer to your question: Why do we need forward declaration? has been given: Because C uses a one-pass compiler. The simplest answer to most of your follow up questions is Because then it wouldn't be a one-pass compiler.
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782: It seems you are now suggesting the computer architecture be modified. Going down that route makes it no longer a language question...
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782 for the run-time question: As others have stated, the processor does not 'find' the return value, it doesn't know types. A compiled program is simply a series of instructions that work on raw data stored in memory. ADDi $1 $2 $3 (Add the int from $1 to the int from $2 and store it at $3) JMPr $5, MV $6 $7. Any given address in memory might be an int, or it might be a float, or it might be an instruction, or a char, or... In general there is no way of looking at that memory and determining what it is.
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782 For the compile time question: It is possible to write a language in which all this type analysis can be done at compile time. C is not such a language. The C compiler can't do it because it is not designed to do it. Could it have been designed differently? Sure, but it would take much more processing power and memory to do so. Bottom line is it wasn't. It was designed in a manner the computers of the day were best able to handle.
Apr
8
revised How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”
updated in light of only one I2CDevice instance existing in the program.
Apr
8
comment How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”
I would not pass this class into each class (you would want/need one wrapper deviceconfiguration. The wrapper as an abstract base for each of your device classes would work, or the wrapper as a private member of one of your device classes.I'll add an example.
Apr
8
revised How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”
updated in light of only one I2CDevice instance existing in the program.
Apr
8
comment How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”
@GisMofx I misread/misunderstood part of your original post. Namely that you have one instance of I2CDevice. In that case, thw wrapper should not create its own or manage the life, but it should also be passed into the constructor. How were you originally planning to pass ic2bus to your Device1, Device2 classes?
Apr
8
awarded  Editor
Apr
8
revised How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”
added example wrapper
Apr
8
answered How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”
Apr
8
comment How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”
if you are returning function(device) should make that T With(DeviceConfig config, Func<Device, T> function)...
Apr
8
comment How To Invoke A Method When It's Class is Accessed (Any Method) - “OnClassEnter”
You might want to look into Aspects. Also, have you considered writing a wrapper for I2CDevice, and using that in your classes instead. The wrapper would take your configuration as constructor parameter. For each of the I2CDevice methods, the wrapper has its own version which applies its configuration before calling the I2CDevice version.
Mar
7
comment Can a system be 100% Data Driven?
@JeremyStein beat me to it. I was going to say my data was stored in Subversion, and changes to my 'configuration' are applied through the continuous integration system, and other deployment processes.
Feb
25
comment How to address the concerns of the software architect but still maintain collective code ownership?
@Gangnus: I agree they are not enough. Here we minimally should also have unit tests and some level of automated integration testing, and long term probably re-architecting to reduce/remove the interdependency. I read your previous comments not as 'worthwhile, but not enough on its own', but as 'Not enough, so no point'
Feb
25
comment How to address the concerns of the software architect but still maintain collective code ownership?
@Gangnus: Even with the worst architected project, code reviews can only help move it in the right direction. If the reviewers are chosen randomly a given developer may not be the ideal person to catch a particular problem, but over time, all developers would become more familiar with all aspects of the project and become better at identifying problems. Not an immediate fix, but with large tangled messes there usually are none. Also, how do you carefully choose reviewers? If you don't know the problems a change may cause in the first place, how do you pick people to look for those problems?
Nov
14
comment Is there any “real” reason multiple inheritance is hated?
At what point could a compiler ever assume that variables of the same name from different parent classes are safe to combine? What guarantee do you have that caninus.diet and pet.diet actually serve the same purpose? What would you do with function/methods with the same name?