Will there be an equivelent of the c# Reflection.Emit namespace in dart?
Reflection.Emit has a number of classes that are used to build types at run time and adding properties, configering their getters and setter and building methods and event handlers all at run time, which is really powerfull when it comes to metaprogramming.
my idea is about generating my data models at run time and caching them in a map so i can create instances at run time and add new methods and properties to them when i need to and not having to use mirrors often after generating the class, this could be really useful when writing ORMs and more dynamic applications where you use reflection once rather than using it every time you need to modify an instance
My questions are:
Will there be such thing in the future versions of dart? they mention
something about a Mirror Builder but i am not sure if does the same
thing, can some one please confirm if thats what a Mirror Builder is
about?
another question is, if i am able to generate my data types on the
server as strings, is there a way to to compile them before sending
them to the client and map them in a Map and use this Map to create instances?
I have seen discussions that this should be supported at some time but as far as I know will not be started to work on in the near future.
Similar requirements are usually solved by code generation at build time (Polymer, Angular, others) by transformers which analyze the code and generated code for reflective property access or code snippets in HTML.
Smoke is a package that aims to simplify this.
Code generation has the advantage that the amount of code needed to be downloaded by the client is much smaller.
When you do code generation at runtime you need a compiler and that is a lot of code that needs to be downloaded into the browser.
try.dartlang.org takes a such an approach. The source is available here https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/site/try/ .
It includes dart2js (built to JavaScript) and runs a background isolate that compiles the Dart code to JS.
Related
I've been reading about encapsulation and keep seeing comments about how changing the privacy of a class or adding getters and setters where there were none before can 'break the code' of people who use your library. I don't really understand this. I'm very inexperienced in programming, and my understanding is that you download a library onto your computer and it's included in the files of the program you're writing, so if the original author changed something in THEIR COPY of the library, it wouldn't affect your copy. Is this wrong? For example, is a library more like a website that your computer connects to through the internet and the original author can update, so that changes they make to it can affect how your code works?
Software is constantly changing, so we must have a way to keep track of the different versions - hence software versions. When you download a library to use in your own program, you (usually, like with a dependency management tool) end up downloading a very specific version of that library.
If a library author was to change the interface to use it, developers using that library would also have to change how they use it when they download the version with those changes. Otherwise, it would break any code that follows an outdated interface.
As long as a library author follows proper versioning procedures, for instance including breaking changes in a new major version, and the changes improve the clarity of the library's interfaces without sacrificing other properties, then the argument is moot. Developers can either continue using the old version or update their code to be compatible with the new version.
Except for maybe in low resource, embedded systems that can use all optimizations available, like accessing object/structure properties directly rather than through a function.
Libraries:
By definition a collection of non-volatile resources used by computer
programs, often for software development. These may include
configuration data, documentation, help data, message templates,
pre-written code and subroutines, classes, values or type
specifications.
Explanation
Let me spend time on defining in coding aspects: Lets say you have a
create a soccer game, what does that need, field, ball, players,
flags.
All this we encapsulate in Class to make as Object Game which
comprises all above.
Now you start building game and realise you are spending redudant time making repeated player names, shirt design , details filling, etc.
To avoid this you make functions which are business specific like 1. generate tshirts and pass (color, design , cloth type) and it returnes you tshirt object in return.
Similary you get player information by passing country and his ID and all this details are return as Player object which have his name, place, country, contacts ets.
This is how the functions in class behaves.
Your ask
privacy of a class or adding getters and setters, ...an 'break the code' of people who use your library
These are ways how you access the object parameters or set values for them , in some languages the getter and setters are auto generated and not required to explicitly set unless you need custom settings during class object creation.
The best advantage of the getting and setter is it ensures the default class creation can be assigned some values which you dont want to change in defaults and also not allow people to enforce new values to that specific parameter of class.
This is how the control is made in place during defining your class and its functions. getter and setter are functions as well with class variables having factility to get/set values as you define the function logic inside.
You ask
my understanding is that you download a library onto your computer and
it's included in the files of the program you're writing, so if the
original author changed something in THEIR COPY of the library, it
wouldn't affect your copy. Is this wrong?
Yes think it like a CD Copy , I sent you a copy so you can use those info from the copy i made, but once i have new features and things added in CompactDisc(CD) it wouldnt be there in your copy i burnt during that time hence you code uses the old version and may use till there is need to update.
You can only get impacted if you take my new CD copy which is called as upgrading your software with my new library version.
Normally big guys software dont immediately change the library in their systems unless there is thorough analysis done with 1. need, 2. security 3. bugs in old fixed in new. factors to address for a new upgrade.
Happy Coding
Software world is free of your mind to code so dont think what is wrong or right just code.
Take a Maths Library building task in hand use anything python, java, c#, objective C, swift, javascript ...
Create library with modules with Circle, Square, Polygon, Sphere objects
Each object they will have thier respective Classes created with theier paramters (circle sample : radius, center(x,y), etc and functions like setRadius, getCircumference, etc)
Similar way all objects makes thier own classes
Abstrat word you used means some function you make private that only class can internally access but not exposed to outside when you create new Maths Object.
Hope this was helpful, happy coding.
I'm new to stackoverflow and I'd like to ask a question regarding the use of dofile()/dostring() in lua. Basically, what I'd like to do is run a piece of code using either dofile() or dostring(), which is created at runtime. However, it is possible for variables or classes to overlap with the "normal" source code/rest of the program. Thus it could happen that the code generated at runtime alters and manipulates the values of variables it shouldn't touch. Since the generated code depends on the user, I have no control over this and can't necessarily prevent it.
Is there a way to run code at runtime in lua, but independently from the rest of the program?
My problem is a simple one. I've created a class library for Delphi 2007 and added the modelling support to it that Delphi offers. It generates nice class overviews of my code, which I'd like to use. But it's not enough. I want to export the generated UML to Altova's UModel to generate some additional documentation and nicer-looking models.
I can't find a way to export the UML from Delphi, though. I can't even find anything in Delphi that would help me to generate any other documentation, except for the class model images that it allows me to save.
My main problem with my class library is that while it's usage is simple, it's creation was quite complex. I've used several techniques to encapsulate functionality, types within types, interfaces and delegations, type aliases and a lot more. The result is actually three simple-looking classes that only expose methods needed to call a specific web service with one class for the WS itself, one class to manage the input and one to manage the output. The class interface is thus kept simple to make it's usage simple. Unfortunately, the complexity of the WS required me to create some complex code.
I need to generate two kinds of documentation now for this code. One simple document that explains how it's used. That one is simple. A second one that explains how to maintain the code, what is where and how and why certain decisions have been taken. That one is complex and requires me to model the whole thing.
I have UModel, which is a great product, especially with C# and Java code. Unfortunately, it can't import Delphi code. I've tried Enterprise Architect, which can manage Delphi code, but this code happens to be way too complex. EA doesn't understand a thing about types within types and other features I've used. Also tried StarUML but had to cry after 10 minutes of usage since that product is just real bad... And doesn't even support Delphi... My hard disk feels real dirty now after I've installed it...
And while I could continue to try other modelling tools, I think I should have a better chance in findiing some way to convert the Together UML stuff to a regular XMI file.
You might want to try ModelMaker.
It has an add-on that allows you to export the UML as XMI, which you can import in Altova UModel.
ModelMaker supports both the Delphi and C# language.
--jeroen
I'm afraid there's no such thing as "regular XMI file" (see for instance this example, that shows the differences in the XMI representation of the same model depending on the tool you use).
We’re rewriting a calculation core from scratch in Delphi, and we’re looking for ways to let other people write code against it.
Automation seems a fairly safe way to get this done. One use we’re thinking of is making it available to VBA/Office, and also generating a .NET assembly (based on the Automation object, that's easy).
But the code should still be easy to use from Delphi, since we’ll be writing our (desktop) UI with that.
Now I’ve been looking into creating an Automation server in Delphi, and it looks like quite a hassle to have to design the components in the Type Library wizard, and then generate the base code.
The calculations we’re having to implement are described in official rules and regulations that are still not ratified, and so could still change before we’re done — they very probably will, perhaps quite extensively. Waiting for the final version is not an option.
An alternative way could be to finish the entire object model first, and write a separate Automation server which only describes the top-level object, switch $METHODINFO ON, and use TObjectDispatch to return all the subordinate objects. As I see it, that would entail having to write wrappers to return the objects by IDispatch interface. Since there's over a 100 different classes in there, that doesn’t look like an attractive option.
Edit: TObjectDispatch is smart enough to wrap any objects returned by properties and methods as well; so only the top object(s) would need to be wrapped. Lack of a complete type library does mean only late-binding is possible, however.
Is there an other, easier (read: hassle-free) way to write a COM-accessible object model in Delphi?
You don't have to use the type library designer. You can write or generate (e.g. from RTTI of your Delphi classes) a .ridl file and add it to your Automation library project.
Generating interface description from RTTI is a great idea! After you have your interfaces generated you can generate a delphi unit from them and implementing in your classes. Of course the majority are implemented already since you have generated the interfaces from those classes after all. The late binding resolution can be done after that by hand using RTTI and implementing IDispatch and IDispatchEx in a common baseclass of the scriptable classes.
I have existing java code and need to create Design Document based on that.
For starter even if I could get all functions with input / output parameters that will help in overall proces.
Note: There is not commeted documentation on any procedures, function or classes.
Last but not least. Let me know for any good tool which will reduce time required for this phase. As currently we write every flow and related stuffs.
What you want is just too much. Quoting Linus Torvalds: “Good code is its own best documentation.”. Anyway, I digress.
You might want to look into UML tools which generate class/sequence diagrams from the code. There are many of them but only a handful support reverse engineering (into and from the class diagram), and even fewer subset support the same to/from sequence diagram. I only know MagicDraw could do this, but I am biased as I used to work for the manufacturer of this tool so do your shopping around first.
Use java docs: http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
or Introspection: http://docs.oracle.com/javase/tutorial/reflect/class/classMembers.html