another answer to the question mohn had asked me once. why linux? low on motivation to read on linux?? read this. as usual a link from developerworks.
gentoo linux is a linux distro, founded by daniel robbins. read on to find out why he started with linux and made gentoo. pretty inspirational.
what do you guys think of open/free source. the concept of learning, sharing knowledge is what pulls me. the economics i am still not sure of. but i am sure some of the worlds best brains are involved in open source.
Friday, March 19, 2004
AOP
any of you worked with AOP (Aspect Oriented Programming) ? its supposed to be the next thing after OOPs. actually works with OOPs.
aspectj is an implementation of AOP in java.i just read this introductory article on java world. though the examples and explanation are in java its pretty basic java.
the page provided a link for AOP in C++ www.aspectc.org. are there AOP implementation for C# ? what do you guys feel about AOP?
aspectj is an implementation of AOP in java.i just read this introductory article on java world. though the examples and explanation are in java its pretty basic java.
the page provided a link for AOP in C++ www.aspectc.org. are there AOP implementation for C# ? what do you guys feel about AOP?
Wednesday, March 17, 2004
Re: C++ generics
this has to do a lot with the design of the languages.
Yup you're right, it does have to do with how the different platforms are designed. Java and .NET are much more dynamic than C++. This affects how they've implemented generics.
i can definitely not comment on generics in c++. but i am very relieved with the constraints part in java/c#.
It's funny because when I first read about constraints I was kind of disappointed. I think a lot of people were. In comparison to C++ templates they put more limitations on its use. So looking at what was there before, I guess people expected more rather than less. But when you think about it, it makes sense.
one part in generics that was really confusing me was that how can i know what "type" the generic class will have to work with so that some important/basic common property can be worked on. in other words, since i can constraint the generic to IComparable ( i guess == Comparable in java) it is much simpler to understand how a sorting algorithm can be created.
Exactly. Those checks would have to be done at runtime since the actual generic class instantiated object is generated at runtime by the JITer. That would be horrible for performance. One of the main goals of generics is performance so it would pretty much defeat the purpose. With constraints all the compiler has to make sure is that the types implement the specified Interface or derive from a Base Class. And if you don't specify any constraints you can only use methods defined in object. Those methods are guaranteed to work cause every type derives implicitly from object.
how do such things work in c++? do you just hope that the class used overloads some operator or something. else generate a compile error? say for the same sorting algorithm, is there some basic comparison method/operator the class is to define. is there no way to "constraint" that?
I dunno how it works exactly - Need a compiler book/class for that ;-) The basic idea is that for every template class instantiation, it creates a new class with the appropriate type. It then checks that the type supports whatever methods are called on it. If not, you get a compiler error. It works without constraints because all the instantiations are done at compile (or maybe link?) time.
The build times are super fast for Java/C# compared to C++ because of their dynamic nature. Another consequence of "static" compilation of C++ is code bloat. When it comes time to instantiate the template classes with actual types, C++ will generate a new class for EVERY type it encounters in the code regardless of whether the application goes down that branch or not. With Java and C# this won't happen. New types are generated only if they are encountered and as needed dynamically.
why do i even need to bother with bruce, when i have mohn here!!
Let's see...
Bruce Eckel - author of Thinking in Java, Thinking in C++, C++ Inside & Out. Published over 150 articles in numerous magazines. Founding member of the ANSI/ISO C++ committee. Provides public and private seminars & design consulting in C++ and Java.
Mohnish Rao - contributor to codeWord.
Eckel's got NOTHING on me.
so i guess i goofed up again.!! :) . so metadata means adding more type info other than the general class stuff.
When was the first time you goofed up?
You had the idea. I think it's more a case of naming that's causing confusion. Everything is being labeled "metadata"... especially in .NET. I just think of everything that will be used by the runtime and JITer (aside from IL) as metadata.
i am coming to questions on metadata/attributes now. how do they work?
Attributes allow you to "tag" your code (a specific class/method etc...). When compiling, the compiler sees these tags and injects it's own code. Like the example you gave - @Remote - the compiler probably injected some "infrastructure" code to expose it as a method that can be called remotely (is that what @Remote does? I'm guessing here). There is an attribute in .NET called "WebMethod". You can use that on any public method and it can be used as a web service. That's all you have to do. All the actual SOAP stuff is handled by the CLR. Another is "Serializable".
also if you ever get any info on how generics have been implemented in java pls let me know.
Doesn't Sun have some Whitepaper published on their dev site?
I just wanted to say that everthing I'm writing about this stuff is how I THINK it works... how I understand it from what I've read. It could very well be that I'm making a huge arse out of myself and writing utter bullshit.
The point of this blog is to discuss this stuff and learn from each other. In other words... to try and become less of an arse.
Yup you're right, it does have to do with how the different platforms are designed. Java and .NET are much more dynamic than C++. This affects how they've implemented generics.
i can definitely not comment on generics in c++. but i am very relieved with the constraints part in java/c#.
It's funny because when I first read about constraints I was kind of disappointed. I think a lot of people were. In comparison to C++ templates they put more limitations on its use. So looking at what was there before, I guess people expected more rather than less. But when you think about it, it makes sense.
one part in generics that was really confusing me was that how can i know what "type" the generic class will have to work with so that some important/basic common property can be worked on. in other words, since i can constraint the generic to IComparable ( i guess == Comparable in java) it is much simpler to understand how a sorting algorithm can be created.
Exactly. Those checks would have to be done at runtime since the actual generic class instantiated object is generated at runtime by the JITer. That would be horrible for performance. One of the main goals of generics is performance so it would pretty much defeat the purpose. With constraints all the compiler has to make sure is that the types implement the specified Interface or derive from a Base Class. And if you don't specify any constraints you can only use methods defined in object. Those methods are guaranteed to work cause every type derives implicitly from object.
how do such things work in c++? do you just hope that the class used overloads some operator or something. else generate a compile error? say for the same sorting algorithm, is there some basic comparison method/operator the class is to define. is there no way to "constraint" that?
I dunno how it works exactly - Need a compiler book/class for that ;-) The basic idea is that for every template class instantiation, it creates a new class with the appropriate type. It then checks that the type supports whatever methods are called on it. If not, you get a compiler error. It works without constraints because all the instantiations are done at compile (or maybe link?) time.
The build times are super fast for Java/C# compared to C++ because of their dynamic nature. Another consequence of "static" compilation of C++ is code bloat. When it comes time to instantiate the template classes with actual types, C++ will generate a new class for EVERY type it encounters in the code regardless of whether the application goes down that branch or not. With Java and C# this won't happen. New types are generated only if they are encountered and as needed dynamically.
why do i even need to bother with bruce, when i have mohn here!!
Let's see...
Bruce Eckel - author of Thinking in Java, Thinking in C++, C++ Inside & Out. Published over 150 articles in numerous magazines. Founding member of the ANSI/ISO C++ committee. Provides public and private seminars & design consulting in C++ and Java.
Mohnish Rao - contributor to codeWord.
Eckel's got NOTHING on me.
so i guess i goofed up again.!! :) . so metadata means adding more type info other than the general class stuff.
When was the first time you goofed up?
You had the idea. I think it's more a case of naming that's causing confusion. Everything is being labeled "metadata"... especially in .NET. I just think of everything that will be used by the runtime and JITer (aside from IL) as metadata.
i am coming to questions on metadata/attributes now. how do they work?
Attributes allow you to "tag" your code (a specific class/method etc...). When compiling, the compiler sees these tags and injects it's own code. Like the example you gave - @Remote - the compiler probably injected some "infrastructure" code to expose it as a method that can be called remotely (is that what @Remote does? I'm guessing here). There is an attribute in .NET called "WebMethod". You can use that on any public method and it can be used as a web service. That's all you have to do. All the actual SOAP stuff is handled by the CLR. Another is "Serializable".
also if you ever get any info on how generics have been implemented in java pls let me know.
Doesn't Sun have some Whitepaper published on their dev site?
I just wanted to say that everthing I'm writing about this stuff is how I THINK it works... how I understand it from what I've read. It could very well be that I'm making a huge arse out of myself and writing utter bullshit.
The point of this blog is to discuss this stuff and learn from each other. In other words... to try and become less of an arse.
Java, Mono, or C++?
http://ometer.com/desktop-language.html
Thoughts on the future of open source desktop development
Personal Take: There's Anti-MS sentiment in almost every other para. But a good article nonetheless.
Thoughts on the future of open source desktop development
Personal Take: There's Anti-MS sentiment in almost every other para. But a good article nonetheless.
Re: ansi c++ revisited(by me)
that won't work in C++, new returns the address of the object it created on the heap, so it will have to be
MyClass * x2 = new MyClass;
or
MyClass x2 = *(new Myclass);
Thanks. Keeping Java, C# AND C++ straight in yer head is hard!
MyClass * x2 = new MyClass;
or
MyClass x2 = *(new Myclass);
Thanks. Keeping Java, C# AND C++ straight in yer head is hard!
Re: C++ generics
firstly, thanks for all the amazing info you provided.
You CANNOT use ANY type you want when instantiating a generic class. In C++ you CAN. The constraints in C#/Java are there to enforce type safety.
this has to do a lot with the design of the languages. i can definitely not comment on generics in c++. but i am very relieved with the constraints part in java/c#. one part in generics that was really confusing me was that how can i know what "type" the generic class will have to work with so that some important/basic common property can be worked on. in other words, since i can constraint the generic to IComparable ( i guess == Comparable in java) it is much simpler to understand how a sorting algorithm can be created.
how do such things work in c++? do you just hope that the class used overloads some operator or something. else generate a compile error? say for the same sorting algorithm, is there some basic comparison method/operator the class is to define. is there no way to "constraint" that?
Anyway, so Eckel is saying if you have these constraints why bother with generics? What dyou feel he was saying?
why do i even need to bother with bruce, when i have mohn here!! if he was saying constraints are not a good thing, then i differ.
there is no metadata layer in a .class file. metadata in java == attributes in c#. so metadata in java is just injection of bytecode based on the implementation by the compiler.
I did a search for Java .class files and .. This is saying the .class file holds info about each method defined in the class in the "methods" array. See, all this type info HAS to be there for Reflection to work.
i have not read the vm spec, so the info yu provided was new to me. so thanks again for more info again!!
as yu know in java each class has to be in a seperate .java and hence goes into a seperate .class file. in .net yu can have multiple classes in a simgle file. so i am guessing that it was thought better to seperate all the type info of all classes into a seperate metadata layer, and leave the actual code in the IL layer. the vm spec for class files you showed has been present pre java 1.5. so the type info has always been there.
but the metadata introduced in java 1.5 was not type info. the example provided was equivalent to the attributes in .net. so this was what i was trying to say.
Attributes enbales you to generate more custom (you can create your own) info like this.
then i saw some stuff on metadata in java..
"The Metadata feature in J2SE 1.5 provides the ability to associate additional data alongside Java classes, interfaces, methods, and fields. This additional data, or annotation, can be read by the javac compiler or other tools, and depending on configuration can also be stored in the class file and can be discovered at runtime using the Java reflection API.""
this is what you were saying. so i guess i goofed up again.!! :) . so metadata means adding more type info other than the general class stuff.
i am coming to questions on metadata/attributes now. how do they work? there is additional metadata present so does the vm link this to the implementations at runtime or what?
also if you ever get any info on how generics have been implemented in java pls let me know. compiler-casting, i hope is an over simplification by me...
You CANNOT use ANY type you want when instantiating a generic class. In C++ you CAN. The constraints in C#/Java are there to enforce type safety.
this has to do a lot with the design of the languages. i can definitely not comment on generics in c++. but i am very relieved with the constraints part in java/c#. one part in generics that was really confusing me was that how can i know what "type" the generic class will have to work with so that some important/basic common property can be worked on. in other words, since i can constraint the generic to IComparable ( i guess == Comparable in java) it is much simpler to understand how a sorting algorithm can be created.
how do such things work in c++? do you just hope that the class used overloads some operator or something. else generate a compile error? say for the same sorting algorithm, is there some basic comparison method/operator the class is to define. is there no way to "constraint" that?
Anyway, so Eckel is saying if you have these constraints why bother with generics? What dyou feel he was saying?
why do i even need to bother with bruce, when i have mohn here!! if he was saying constraints are not a good thing, then i differ.
there is no metadata layer in a .class file. metadata in java == attributes in c#. so metadata in java is just injection of bytecode based on the implementation by the compiler.
I did a search for Java .class files and .. This is saying the .class file holds info about each method defined in the class in the "methods" array. See, all this type info HAS to be there for Reflection to work.
i have not read the vm spec, so the info yu provided was new to me. so thanks again for more info again!!
as yu know in java each class has to be in a seperate .java and hence goes into a seperate .class file. in .net yu can have multiple classes in a simgle file. so i am guessing that it was thought better to seperate all the type info of all classes into a seperate metadata layer, and leave the actual code in the IL layer. the vm spec for class files you showed has been present pre java 1.5. so the type info has always been there.
but the metadata introduced in java 1.5 was not type info. the example provided was equivalent to the attributes in .net. so this was what i was trying to say.
Attributes enbales you to generate more custom (you can create your own) info like this.
then i saw some stuff on metadata in java..
"The Metadata feature in J2SE 1.5 provides the ability to associate additional data alongside Java classes, interfaces, methods, and fields. This additional data, or annotation, can be read by the javac compiler or other tools, and depending on configuration can also be stored in the class file and can be discovered at runtime using the Java reflection API.""
this is what you were saying. so i guess i goofed up again.!! :) . so metadata means adding more type info other than the general class stuff.
i am coming to questions on metadata/attributes now. how do they work? there is additional metadata present so does the vm link this to the implementations at runtime or what?
also if you ever get any info on how generics have been implemented in java pls let me know. compiler-casting, i hope is an over simplification by me...
Re: ansi c++ revisited(by me)
MyClass x2 = new MyClass; // object created on heap
that won't work in C++, new returns the address of the object it created on the heap, so it will have to be
MyClass * x2 = new MyClass;
or
MyClass x2 = *(new Myclass);
dinesh.
that won't work in C++, new returns the address of the object it created on the heap, so it will have to be
MyClass * x2 = new MyClass;
or
MyClass x2 = *(new Myclass);
dinesh.
Tuesday, March 16, 2004
Re: ansi c++ revisited(by me)
firstly what do you guys feel of friend methods? how much do u use them within yur code. i got the feeling that as "friend"ly as they might be they broke the oops principle of encapsulation.
You are right about violating the principle of encapsulation. But I think it is a "controlled" violation. It's not like any class/method out there can claim to be your friend and access your privates. YOU decide who your friend is. I could even see this as a convenience feature. If you mess up in design and want someone in the outside world to see some data, but not everyone, make him a friend.
whats the difference between creating an instance using new vs without new
Without new, the instance is created on the stack and memory management is taken care by the compiler. With new, it's created on the c++ heap and you have to make sure and call delete.
new is supposed to be dynamic runtime allocation so are instances like stack a given a memory space just when the os creates the app
Yeah, I think that's what happens. But I'm not sure exactly how it works. If one of you could explain the process.
Also you have read stuff on OS right? Have you gone into details about what happens when an app is executed? Like what does the OS do? OS Loader, creating new process etc... Could you post about that? I have not done anything in OS, but am very interested in it.
also is there a heap and stack in c++. can i specify where i can create the instance. this is possible in c# right? code snippet please.
Yeah there's a heap and stack in c++... same with c# and java. In c++ classes can be created on the stack or the heap. In c# classes can ONLY be created on the heap and structs can be created ONLY on the stack. Structs in c# are NOT the same as structs in c++. Structs in c++ are the same as Classes but their default access level for members is public. Java has no structs, only classes and they can ONLY be created on the heap.
// C++
MyClass x; // object created on stack
MyClass x2 = new MyClass; // object created on heap
MyStruct y; // object created on stack
MyStruct y2 = new MyStruct; // object created on heap
// C#
MyClass x; // just declares x to be a reference to a MyClass object (initialized to null)
MyClass x2 = new MyClass(); // object created on heap
MyStruct y; // object created on stack (initialized to 0, by compiler)
MyStruct y2 = new MyStruct(); // object created on stack (default constructor called)
// Java
MyClass x; // just declares x to be a reference to a MyClass object (initialized to null)
MyClass x2 = new MyClass(); // object created on heap
does c# allow overloaded operators?
Yup. They have to be declared as static methods of the class...
public class MyClass
{
private int x;
public MyClass( int x )
{
this.x = x;
}
public static MyClass operator+( MyClass that )
{
return new MyClass( this.x + that.x );
}
}
You are right about violating the principle of encapsulation. But I think it is a "controlled" violation. It's not like any class/method out there can claim to be your friend and access your privates. YOU decide who your friend is. I could even see this as a convenience feature. If you mess up in design and want someone in the outside world to see some data, but not everyone, make him a friend.
whats the difference between creating an instance using new vs without new
Without new, the instance is created on the stack and memory management is taken care by the compiler. With new, it's created on the c++ heap and you have to make sure and call delete.
new is supposed to be dynamic runtime allocation so are instances like stack a given a memory space just when the os creates the app
Yeah, I think that's what happens. But I'm not sure exactly how it works. If one of you could explain the process.
Also you have read stuff on OS right? Have you gone into details about what happens when an app is executed? Like what does the OS do? OS Loader, creating new process etc... Could you post about that? I have not done anything in OS, but am very interested in it.
also is there a heap and stack in c++. can i specify where i can create the instance. this is possible in c# right? code snippet please.
Yeah there's a heap and stack in c++... same with c# and java. In c++ classes can be created on the stack or the heap. In c# classes can ONLY be created on the heap and structs can be created ONLY on the stack. Structs in c# are NOT the same as structs in c++. Structs in c++ are the same as Classes but their default access level for members is public. Java has no structs, only classes and they can ONLY be created on the heap.
// C++
MyClass x; // object created on stack
MyClass x2 = new MyClass; // object created on heap
MyStruct y; // object created on stack
MyStruct y2 = new MyStruct; // object created on heap
// C#
MyClass x; // just declares x to be a reference to a MyClass object (initialized to null)
MyClass x2 = new MyClass(); // object created on heap
MyStruct y; // object created on stack (initialized to 0, by compiler)
MyStruct y2 = new MyStruct(); // object created on stack (default constructor called)
// Java
MyClass x; // just declares x to be a reference to a MyClass object (initialized to null)
MyClass x2 = new MyClass(); // object created on heap
does c# allow overloaded operators?
Yup. They have to be declared as static methods of the class...
public class MyClass
{
private int x;
public MyClass( int x )
{
this.x = x;
}
public static MyClass operator+( MyClass that )
{
return new MyClass( this.x + that.x );
}
}
Monday, March 15, 2004
Re: C++ generics
you must have noticed the "Insights Into the .NET Architecture" series on artima. they did mention some stuff of multiple inheritance being implemented in the CLR/CLS
Yeah I did read that article. I guess Eiffel has implemented MI, but it doesn't "play well" will the other languages in .NET. As in, if you have a multi language project with subclassing from one language to another, then Eiffel won't work cause MI isn't in the CLS.
could you please put the bruce eckel blog on java generics in simpler language!!
Basically, C++ Templates != C#/Java Generics. Both of them have similar goals, but not exact same capabilities. C++ offers more freedom in what types you can use when instantiating a template class. In a previous post I had written a bit about constraints in C# (there is something similar in Java also).
You CANNOT use ANY type you want when instantiating a generic class. In C++ you CAN. The constraints in C#/Java are there to enforce type safety. Generally they are an Interface or Base Class. It means "instantiate this generic class/method with a type ONLY if it implements this interface or extends this Base Class".
Ex...
public T Max<T>( T x, T y ) where T : IComparable
{
// Call ONLY IComparable methods on x and y
if ( x.CompareTo( y ) > 0 )
{
return x;
}
else
{
return y;
}
}
or
public void Foo<T>( T bar ) where T : MyBaseClass
{
// Call ONLY MyBaseClass methods on bar
}
Anyway, so Eckel is saying if you have these constraints why bother with generics? Just use Interfaces or Base Classes directly instead of making a generic class and then telling the user to ONLY instantiate that class with a type that implements that interface or extends the base class. Atleast that's the meaning I got from it. What dyou feel he was saying?
I think there is a slight difference between JUST Interfaces vs Interfaces through Generics...
With Interfaces, the compiler just cares about the methods on the interface. It does NOT care about the underlying type. As in if class Dog and class Cat both implement interface IAnimal, the compiler won't distinguish between the two if you have an IAnimal reference to a Dog object or a Cat object...
private void DoSomethingWithAnimals( IAnimal x )
{
...
}
IAnimal animal;
animal = new Dog();
DoSomethingWithAnimals( animal ); // fine
animal = new Cat();
DoSomethingWithAnimals( animal ); // fine
But with interfaces through generics it DOES care...
private void DoSomethingWithAnimals<T>( T x ) where T : IAnimal
{
...
}
IAnimal animal;
animal = new Dog();
DoSomethingWithAnimals<Dog>( animal ); // fine
animal = new Cat();
DoSomethingWithAnimals<Dog>( animal ); // fails
This is how I think of it. So with generics, you are not only limited by the interface, but also the type that implements the interface.
there is no metadata layer in a .class file. metadata in java == attributes in c#. so metadata in java is just injection of bytecode based on the implementation by the compiler.
I did a search for Java .class files and got this... http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
It talks about storing the type information just like in .NET. The terminology might be different (.NET uses metadata for pretty much everything in the assembly aside from IL) but they DO store all the info in the file. Check it... I didn't go through in detail, but saw stuff like...
methods[]
Each value in the methods table must be a method_info (§4.6) structure giving a complete description of a method in this class or interface. If the method is not native or abstract, the Java virtual machine instructions implementing the method are also supplied.
The method_info structures represent all methods declared by this class or interface type, including instance methods, class (static) methods, instance initialization methods (§3.9), and any class or interface initialization method (§3.9). The methods table does not include items representing methods that are inherited from superclasses or superinterfaces.
This is saying the .class file holds info about each method defined in the class in the "methods" array.
See, all this type info HAS to be there for Reflection to work. How else will the runtime access this data? Attributes enbales you to generate more custom (you can create your own) info like this. All other type data is generated by default by the compiler.
Yeah I did read that article. I guess Eiffel has implemented MI, but it doesn't "play well" will the other languages in .NET. As in, if you have a multi language project with subclassing from one language to another, then Eiffel won't work cause MI isn't in the CLS.
could you please put the bruce eckel blog on java generics in simpler language!!
Basically, C++ Templates != C#/Java Generics. Both of them have similar goals, but not exact same capabilities. C++ offers more freedom in what types you can use when instantiating a template class. In a previous post I had written a bit about constraints in C# (there is something similar in Java also).
You CANNOT use ANY type you want when instantiating a generic class. In C++ you CAN. The constraints in C#/Java are there to enforce type safety. Generally they are an Interface or Base Class. It means "instantiate this generic class/method with a type ONLY if it implements this interface or extends this Base Class".
Ex...
public T Max<T>( T x, T y ) where T : IComparable
{
// Call ONLY IComparable methods on x and y
if ( x.CompareTo( y ) > 0 )
{
return x;
}
else
{
return y;
}
}
or
public void Foo<T>( T bar ) where T : MyBaseClass
{
// Call ONLY MyBaseClass methods on bar
}
Anyway, so Eckel is saying if you have these constraints why bother with generics? Just use Interfaces or Base Classes directly instead of making a generic class and then telling the user to ONLY instantiate that class with a type that implements that interface or extends the base class. Atleast that's the meaning I got from it. What dyou feel he was saying?
I think there is a slight difference between JUST Interfaces vs Interfaces through Generics...
With Interfaces, the compiler just cares about the methods on the interface. It does NOT care about the underlying type. As in if class Dog and class Cat both implement interface IAnimal, the compiler won't distinguish between the two if you have an IAnimal reference to a Dog object or a Cat object...
private void DoSomethingWithAnimals( IAnimal x )
{
...
}
IAnimal animal;
animal = new Dog();
DoSomethingWithAnimals( animal ); // fine
animal = new Cat();
DoSomethingWithAnimals( animal ); // fine
But with interfaces through generics it DOES care...
private void DoSomethingWithAnimals<T>( T x ) where T : IAnimal
{
...
}
IAnimal animal;
animal = new Dog();
DoSomethingWithAnimals<Dog>( animal ); // fine
animal = new Cat();
DoSomethingWithAnimals<Dog>( animal ); // fails
This is how I think of it. So with generics, you are not only limited by the interface, but also the type that implements the interface.
there is no metadata layer in a .class file. metadata in java == attributes in c#. so metadata in java is just injection of bytecode based on the implementation by the compiler.
I did a search for Java .class files and got this... http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
It talks about storing the type information just like in .NET. The terminology might be different (.NET uses metadata for pretty much everything in the assembly aside from IL) but they DO store all the info in the file. Check it... I didn't go through in detail, but saw stuff like...
methods[]
Each value in the methods table must be a method_info (§4.6) structure giving a complete description of a method in this class or interface. If the method is not native or abstract, the Java virtual machine instructions implementing the method are also supplied.
The method_info structures represent all methods declared by this class or interface type, including instance methods, class (static) methods, instance initialization methods (§3.9), and any class or interface initialization method (§3.9). The methods table does not include items representing methods that are inherited from superclasses or superinterfaces.
This is saying the .class file holds info about each method defined in the class in the "methods" array.
See, all this type info HAS to be there for Reflection to work. How else will the runtime access this data? Attributes enbales you to generate more custom (you can create your own) info like this. All other type data is generated by default by the compiler.
ansi c++ revisited(by me)
i decided to get out of my java shell and explore some more languages. so decided to go back and read some stuff on ansi c++. i really liked the amount of freedom given to the developer to do whatever he wants. so i'll ask some of my dumb questions on the list, and just comment on the lang..
firstly what do you guys feel of friend methods? how much do u use them within yur code. i got the feeling that as "friend"ly as they might be they broke the oops principle of encapsulation.
a question now. whats the difference between creating an instance using new vs without new, say like stack a;. new is supposed to be dynamic runtime allocation so are instances like stack a given a memory space just when the os creates the app? aren't java/c# based on runtime allocation of mem.
also is there a heap and stack in c++. can i specify where i can create the instance. this is possible in c# right? code snippet please.
does c# allow overloaded operators?
so a few questions to keep you busy for some time.
firstly what do you guys feel of friend methods? how much do u use them within yur code. i got the feeling that as "friend"ly as they might be they broke the oops principle of encapsulation.
a question now. whats the difference between creating an instance using new vs without new, say like stack a;. new is supposed to be dynamic runtime allocation so are instances like stack a given a memory space just when the os creates the app? aren't java/c# based on runtime allocation of mem.
also is there a heap and stack in c++. can i specify where i can create the instance. this is possible in c# right? code snippet please.
does c# allow overloaded operators?
so a few questions to keep you busy for some time.
Re: C++ Generics
Actually, they have an implementation of Eiffel that runs atop the CLR. Even though the CLR (CLS - Common Language Specification), doesn't support MI, they have managed to do it somehow.
you must have noticed the "Insights Into the .NET Architecture" series on artima. they did mention some stuff of multiple inheritance being implemented in the CLR/CLS. being as lazy (also dumb) as i am could you please put the bruce eckel blog on java generics in simpler language!!
"Metadata - Lets you avoid writing boilerplate code, .. That is actually also the definition of attributes. Attributes allow you to inject "custom" metadata.
can't you do most of the stuff simply by using reflections?
This is another reason why I think the metadata will not be too different between Java and .NET. Java also has Reflection capability.
the main difference is that in .net you have assembly = metadata + IL. right now i am not sure about the actual java 1.5 bytecode. but i'll tell you what i've gotten till now. there is no metadata layer in a .class file. metadata in java == attributes in c#. so metadata in java is just injection of bytecode based on the implementation by the compiler. similarly generics as of now seems casting by the compiler. hence there is NO metadata in java analogous to the metadata in c#. if any of you could confirm if what i said is right or wrong please correct. mohn i was wondering if you have any great faculty in yur coll, to whom u can/do ask such questions.
Those guys are Einstien's. I'm sure they have proper reasons for their choice. I was just stating my opinion.
yur opinions are always welcome!!
you must have noticed the "Insights Into the .NET Architecture" series on artima. they did mention some stuff of multiple inheritance being implemented in the CLR/CLS. being as lazy (also dumb) as i am could you please put the bruce eckel blog on java generics in simpler language!!
"Metadata - Lets you avoid writing boilerplate code, .. That is actually also the definition of attributes. Attributes allow you to inject "custom" metadata.
can't you do most of the stuff simply by using reflections?
This is another reason why I think the metadata will not be too different between Java and .NET. Java also has Reflection capability.
the main difference is that in .net you have assembly = metadata + IL. right now i am not sure about the actual java 1.5 bytecode. but i'll tell you what i've gotten till now. there is no metadata layer in a .class file. metadata in java == attributes in c#. so metadata in java is just injection of bytecode based on the implementation by the compiler. similarly generics as of now seems casting by the compiler. hence there is NO metadata in java analogous to the metadata in c#. if any of you could confirm if what i said is right or wrong please correct. mohn i was wondering if you have any great faculty in yur coll, to whom u can/do ask such questions.
Those guys are Einstien's. I'm sure they have proper reasons for their choice. I was just stating my opinion.
yur opinions are always welcome!!
Sunday, March 14, 2004
Saturday, March 13, 2004
Re: C++ Generics
something like its more pure oops.
Right... same thing I've also heard. I know that it is a system similar to Java and .NET with unified type system, garbage collection and totally OOP. It also supports multiple inheritance, which neither Java nor C# does. Actually, they have an implementation of Eiffel that runs atop the CLR. Even though the CLR (CLS - Common Language Specification), doesn't support MI, they have managed to do it somehow.
Eiffel is quite old. It was created in the mid/late 80's. So it had all those capabilites quite a few years before Java came out. I guess maybe the reason it's not so popular is cause it doesn't have the C/C++ syntax.
"Metadata - Lets you avoid writing boilerplate code, by enabling tools to generate it from annotations in the source code. This leads to a "declarative" programming style where the programmer says what should be done and tools emit the code to do it."
That is actually also the definition of attributes. Attributes allow you to inject "custom" metadata. In your example, the attribute (Remote), is something that the Java guys have provided as part of the platform, but you can write your own stuff. When you run the code, the compiler will see the attributes/metadata and inject RPC code in for you. That's how it is declarative. You don't have to do anything.
so metadata in java is very different.
"What exactly is the metadata? Basically, it is binary information that describes every type and member defined in your code."
I don't think it will be too different. If you don't involve attributes in anyway, then the metadata just consists of type/member info. But if you declare attributes (like Remote), then that info will be added to the metadata.
also another question that just popped into my head is on metadata in c#. can't you do most of the stuff simply by using reflections? there must be more advantages.
This is another reason why I think the metadata will not be too different between Java and .NET. Java also has Reflection capability. So the runtime has to have access to all the type/member info. The slight differences will probably be with Generics data. Apparently you can't tell what type a generic class was instantiated with in Java Generics.
i agree that generics and metadata seem more fake/pseudo in java, but they must have had some tough decisions to make.
I agree. Those guys are Einstien's. I'm sure they have proper reasons for their choice. Software is all about tradeoffs. I was just stating my opinion.
Right... same thing I've also heard. I know that it is a system similar to Java and .NET with unified type system, garbage collection and totally OOP. It also supports multiple inheritance, which neither Java nor C# does. Actually, they have an implementation of Eiffel that runs atop the CLR. Even though the CLR (CLS - Common Language Specification), doesn't support MI, they have managed to do it somehow.
Eiffel is quite old. It was created in the mid/late 80's. So it had all those capabilites quite a few years before Java came out. I guess maybe the reason it's not so popular is cause it doesn't have the C/C++ syntax.
"Metadata - Lets you avoid writing boilerplate code, by enabling tools to generate it from annotations in the source code. This leads to a "declarative" programming style where the programmer says what should be done and tools emit the code to do it."
That is actually also the definition of attributes. Attributes allow you to inject "custom" metadata. In your example, the attribute (Remote), is something that the Java guys have provided as part of the platform, but you can write your own stuff. When you run the code, the compiler will see the attributes/metadata and inject RPC code in for you. That's how it is declarative. You don't have to do anything.
so metadata in java is very different.
"What exactly is the metadata? Basically, it is binary information that describes every type and member defined in your code."
I don't think it will be too different. If you don't involve attributes in anyway, then the metadata just consists of type/member info. But if you declare attributes (like Remote), then that info will be added to the metadata.
also another question that just popped into my head is on metadata in c#. can't you do most of the stuff simply by using reflections? there must be more advantages.
This is another reason why I think the metadata will not be too different between Java and .NET. Java also has Reflection capability. So the runtime has to have access to all the type/member info. The slight differences will probably be with Generics data. Apparently you can't tell what type a generic class was instantiated with in Java Generics.
i agree that generics and metadata seem more fake/pseudo in java, but they must have had some tough decisions to make.
I agree. Those guys are Einstien's. I'm sure they have proper reasons for their choice. Software is all about tradeoffs. I was just stating my opinion.
Friday, March 12, 2004
Re: C++ Generics
have you guys heard of a language called eiffel?
i have heard very little stuff on eiffel. something like its more pure oops. so i wanted to know if any of you knew any features of the language vs java/c++/c#.
So I was saying, they should have changed the bytecode and emited some more metadata to handle generics. This way, those casts would be eliminated. The metadata would hold the generic class template as well as info about the type the class was instantiated with at runtime.
i guess you are speaking from c# experiece.i cannot confirm but things in java are very different. take this definition of metadata from joshua bloch, a lead architect in java.
"Metadata - Lets you avoid writing boilerplate code, by enabling tools to generate it from annotations in the source code. This leads to a "declarative" programming style where the programmer says what should be done and tools emit the code to do it."
and an example..
"
import javax.xml.rpc.*;
public class CoffeeOrder {
@Remote public Coffee [] getPriceList() {
...
}
@Remote public String orderCoffee(String name, int quantity) {
...
}
}
"
so metadata in java is very different. the above example simply exposes the method getPriceList() as a remote method. it simply auto-generates byte-code compared to if you would actually expose the method as a remote method. unlike what mohn had posted on metadata in c# ages ago
"What exactly is the metadata? Basically, it is binary information that describes every type and member defined in your code."
metadata in java is just the compiler doing stuff for you. the basic structure of the class file, jvm remains same. i agree that generics and metadata seem more fake/pseudo in java, but they must have had some tough decisions to make.
also another question that just popped into my head is on metadata in c#. can't you do most of the stuff simply by using reflections? there must be more advantages.
i have heard very little stuff on eiffel. something like its more pure oops. so i wanted to know if any of you knew any features of the language vs java/c++/c#.
So I was saying, they should have changed the bytecode and emited some more metadata to handle generics. This way, those casts would be eliminated. The metadata would hold the generic class template as well as info about the type the class was instantiated with at runtime.
i guess you are speaking from c# experiece.i cannot confirm but things in java are very different. take this definition of metadata from joshua bloch, a lead architect in java.
"Metadata - Lets you avoid writing boilerplate code, by enabling tools to generate it from annotations in the source code. This leads to a "declarative" programming style where the programmer says what should be done and tools emit the code to do it."
and an example..
"
import javax.xml.rpc.*;
public class CoffeeOrder {
@Remote public Coffee [] getPriceList() {
...
}
@Remote public String orderCoffee(String name, int quantity) {
...
}
}
"
so metadata in java is very different. the above example simply exposes the method getPriceList() as a remote method. it simply auto-generates byte-code compared to if you would actually expose the method as a remote method. unlike what mohn had posted on metadata in c# ages ago
"What exactly is the metadata? Basically, it is binary information that describes every type and member defined in your code."
metadata in java is just the compiler doing stuff for you. the basic structure of the class file, jvm remains same. i agree that generics and metadata seem more fake/pseudo in java, but they must have had some tough decisions to make.
also another question that just popped into my head is on metadata in c#. can't you do most of the stuff simply by using reflections? there must be more advantages.
Generics Aren't
"Thinking in ..." books author talks about Java generics in his weblog.
http://mindview.net/WebLog/log-0050
http://mindview.net/WebLog/log-0050
Assert is your friend
http://www.codeproject.com/cpp/assertisyourfriend.asp
Focuses on MFC/C++, but applies to any language.
Focuses on MFC/C++, but applies to any language.
Thursday, March 11, 2004
Re: C++ Generics
have you guys heard of a language called eiffel?
Yeah I've heard of it. But don't know much about it. Why dyou ask?
i have hardly read stuff on artima. but they seem very design oriented. you recommend any more articles?
That site is very good. They don't have articles per se... they mostly have interviews with the "big" guys in programming. They have a series going with C# designer Anders Hejlsberg, Java designer James Gosling as well as C++ designer Bjarne Stroustrup and many more. Those tell you about what their goals were when they were designing the languages.
also bill veneers, the creator of artima (i think) has this great book on java internals, the bytecode spec
There is a link on artima... http://www.artima.com/insidejvm/blurb.html. Is this what you're referring to?
he too came up with examples on auto_ptr and tupples.
Take a look at the STL documentation... http://www.sgi.com/tech/stl/table_of_contents.html. Pretty much everything on there is totally generic.
It seems it might have been a better idea for them to make changes to the bytecode and metadata to make this happen.
could you explain what u meant.
If they make changes to the bytecode or the metadata, the JVM will have to be updated to be able to handle it. To avoid this update (or to keep backwards compatibility), they chose NOT to do this. Instead, it's the same code (with casts), but done by the compiler.
So I was saying, they should have changed the bytecode and emited some more metadata to handle generics. This way, those casts would be eliminated. The metadata would hold the generic class template as well as info about the type the class was instantiated with at runtime.
Yeah I've heard of it. But don't know much about it. Why dyou ask?
i have hardly read stuff on artima. but they seem very design oriented. you recommend any more articles?
That site is very good. They don't have articles per se... they mostly have interviews with the "big" guys in programming. They have a series going with C# designer Anders Hejlsberg, Java designer James Gosling as well as C++ designer Bjarne Stroustrup and many more. Those tell you about what their goals were when they were designing the languages.
also bill veneers, the creator of artima (i think) has this great book on java internals, the bytecode spec
There is a link on artima... http://www.artima.com/insidejvm/blurb.html. Is this what you're referring to?
he too came up with examples on auto_ptr and tupples.
Take a look at the STL documentation... http://www.sgi.com/tech/stl/table_of_contents.html. Pretty much everything on there is totally generic.
It seems it might have been a better idea for them to make changes to the bytecode and metadata to make this happen.
could you explain what u meant.
If they make changes to the bytecode or the metadata, the JVM will have to be updated to be able to handle it. To avoid this update (or to keep backwards compatibility), they chose NOT to do this. Instead, it's the same code (with casts), but done by the compiler.
So I was saying, they should have changed the bytecode and emited some more metadata to handle generics. This way, those casts would be eliminated. The metadata would hold the generic class template as well as info about the type the class was instantiated with at runtime.
Re: C++ Generics
The whole point of introducing generics is to get rid of the casting completely so that you don't pay the performance penalty.
i read up on the article, and i think one you had posted before, on artima.com by the c# designer. i understand what you are saying but have no idea about java internals etc. i guess this is a price you have to pay for backward compatability!! post more stuff on language design's etc links whatever... have you guys heard of a language called eiffel?
i have hardly read stuff on artima. but they seem very design oriented. you recommend any more articles? also bill veneers, the creator of artima (i think) has this great book on java internals, the bytecode spec. the only thing i remember is java class files' magic number ... CAFEBABE ;) .
also i keep pestering dinesh with questions on stuff. (whenever i get the chance) he too came up with examples on auto_ptr and tupples. so mohn dinesh on similar freq.
It seems it might have been a better idea for them to make changes to the bytecode and metadata to make this happen.
could you explain what u meant.
i read up on the article, and i think one you had posted before, on artima.com by the c# designer. i understand what you are saying but have no idea about java internals etc. i guess this is a price you have to pay for backward compatability!! post more stuff on language design's etc links whatever... have you guys heard of a language called eiffel?
i have hardly read stuff on artima. but they seem very design oriented. you recommend any more articles? also bill veneers, the creator of artima (i think) has this great book on java internals, the bytecode spec. the only thing i remember is java class files' magic number ... CAFEBABE ;) .
also i keep pestering dinesh with questions on stuff. (whenever i get the chance) he too came up with examples on auto_ptr and tupples. so mohn dinesh on similar freq.
It seems it might have been a better idea for them to make changes to the bytecode and metadata to make this happen.
could you explain what u meant.
Wednesday, March 10, 2004
Tiger
http://nl.internet.com/ct.html?rtr=on&s=1,ro9,1,85un,eq8n,9zv,h0i1
The article mentions (very) briefly about what I said in the prev blog. With generics, the casting is just shifted to the compiler. I think this is a bit strange. The whole point of introducing generics is to get rid of the casting completely so that you don't pay the performance penalty. It seems it might have been a better idea for them to make changes to the bytecode and metadata to make this happen.
The article mentions (very) briefly about what I said in the prev blog. With generics, the casting is just shifted to the compiler. I think this is a bit strange. The whole point of introducing generics is to get rid of the casting completely so that you don't pay the performance penalty. It seems it might have been a better idea for them to make changes to the bytecode and metadata to make this happen.
Tuesday, March 09, 2004
Re: C++ Generics
could you give some places where templates, both class and function would be used. other than containers.
Containers are the most popular candidates because they are an abstraction that, by nature, are generic. I mean when you talk about an Array or List or Dictionary, you don't think about it in terms of a specific type. So when you think of templates etc... you immediately think of collections.
But there are many other places where genericity plays a role. For example, there is a class called auto_ptr in STL. This is a utility class that helps with memory management. In C++, when you create an object on the heap with "new", it is your responsibility to free it with "delete". But there are times when this fails to happen.
Consider this...
function foo()
{
MyClass* pBar = new MyClass;
DoSomethingThatCausesAnExceptionToBeThrown();
delete pBar;
}
In this case, you allocate/initialize on the heap. Then you jump to another function. That function throws an exception and the stack unwinds both functions. You never get to "delete pBar". Memory leak. You can use auto_ptr to help you out. auto_ptr takes a pointer (to an object on the heap). When it goes out of scope, it calls "delete" on the pointer you pass it...
function foo()
{
auto_ptr<MyClass> bar( new MyClass );
DoSomethingThatCausesAnExceptionToBeThrown();
}
Here, bar is just a local variable created on the stack. When the function ends or the stack unwinds (because of an exception), bar's destructor is called, which in turn calls delete on the pointer passed to it.
auto_ptr is a generic class. It can hold on to a pointer of ANY type you pass it.
Similar to auto_ptr is pair. This is a class that holds on to a tuple. It is generic in that it can hold on to two objects of ANY type...
template <typename T1, typenameT2>
class pair
{
private:
T1 first;
T2 second;
public:
pair( T1 f, T2 s ) : first( f ), second( s ) { }
...
}
should the 'size_t n' variable you created in the class template example be 'int n'??
size_t is an unsigned type defined in one of the standard C header files... dunno which one exactly. This is basically defined for any positive range like # of elements in a collection. It really is just a typedef for an unsigned integral.
how is the generics implementation in .net?
As I said before, in C++ everything happens at compile time. In C#, it's both compile and runtime. When you create a template class in C++, the compiler removes the actual template class and replaces it with classes of a specific type(s). In C#, the compiler emits IL code and metadata for the actual template. At runtime, the JITer will create actual classes of specific types as it is encountered.
In C# there is less freedom in the types you can use in templates. When you create a template, you define constraints on the types you can use the template with...
public class MyClass<T> where T : IComparable
{
// Do stuff with T on IComparable methods
}
The constraint here is that all types with which you instantiate MyClass have to implement IComparable. The compiler will ensure that it does. So at runtime you don't have to worry about checking whether a type defines a specific method or not.
i am basically trying to gear up for java 1.5.
I read that Java generics are being implemented such that no changes to the JVM will be required. This is a good benefit. But apparently, this means that it won't provide "true" template functionality because you can't modify the bytecode. As in, it's going to be syntactic sugar for the programmer. The compiler will be using Object for the type and inject casts in the bytecode. Also, when using reflection on a generic class, you won't be able to tell what type it was instantiated with. Have you heard anything about this?
Containers are the most popular candidates because they are an abstraction that, by nature, are generic. I mean when you talk about an Array or List or Dictionary, you don't think about it in terms of a specific type. So when you think of templates etc... you immediately think of collections.
But there are many other places where genericity plays a role. For example, there is a class called auto_ptr in STL. This is a utility class that helps with memory management. In C++, when you create an object on the heap with "new", it is your responsibility to free it with "delete". But there are times when this fails to happen.
Consider this...
function foo()
{
MyClass* pBar = new MyClass;
DoSomethingThatCausesAnExceptionToBeThrown();
delete pBar;
}
In this case, you allocate/initialize on the heap. Then you jump to another function. That function throws an exception and the stack unwinds both functions. You never get to "delete pBar". Memory leak. You can use auto_ptr to help you out. auto_ptr takes a pointer (to an object on the heap). When it goes out of scope, it calls "delete" on the pointer you pass it...
function foo()
{
auto_ptr<MyClass> bar( new MyClass );
DoSomethingThatCausesAnExceptionToBeThrown();
}
Here, bar is just a local variable created on the stack. When the function ends or the stack unwinds (because of an exception), bar's destructor is called, which in turn calls delete on the pointer passed to it.
auto_ptr is a generic class. It can hold on to a pointer of ANY type you pass it.
Similar to auto_ptr is pair. This is a class that holds on to a tuple. It is generic in that it can hold on to two objects of ANY type...
template <typename T1, typenameT2>
class pair
{
private:
T1 first;
T2 second;
public:
pair( T1 f, T2 s ) : first( f ), second( s ) { }
...
}
should the 'size_t n' variable you created in the class template example be 'int n'??
size_t is an unsigned type defined in one of the standard C header files... dunno which one exactly. This is basically defined for any positive range like # of elements in a collection. It really is just a typedef for an unsigned integral.
how is the generics implementation in .net?
As I said before, in C++ everything happens at compile time. In C#, it's both compile and runtime. When you create a template class in C++, the compiler removes the actual template class and replaces it with classes of a specific type(s). In C#, the compiler emits IL code and metadata for the actual template. At runtime, the JITer will create actual classes of specific types as it is encountered.
In C# there is less freedom in the types you can use in templates. When you create a template, you define constraints on the types you can use the template with...
public class MyClass<T> where T : IComparable
{
// Do stuff with T on IComparable methods
}
The constraint here is that all types with which you instantiate MyClass have to implement IComparable. The compiler will ensure that it does. So at runtime you don't have to worry about checking whether a type defines a specific method or not.
i am basically trying to gear up for java 1.5.
I read that Java generics are being implemented such that no changes to the JVM will be required. This is a good benefit. But apparently, this means that it won't provide "true" template functionality because you can't modify the bytecode. As in, it's going to be syntactic sugar for the programmer. The compiler will be using Object for the type and inject casts in the bytecode. Also, when using reflection on a generic class, you won't be able to tell what type it was instantiated with. Have you heard anything about this?
Subscribe to:
Posts (Atom)