Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I've heard a few times that Resource Dictionaries can slowly but surely build up and become drag on the performance of an app (especially as merged dictionaries begin to reference other merged dictionaries and it all clumps together into an unintended matrix of resources).
With this in mind, should styles be assimilated into c# as custom controls that intelligently try to carry out what the style(s) were going to set the properties of a given control to, set by an internally defined Enum="Example" instead of Style="{StaticResource Example}"?
And if so, at what point/level of ResourceDictionary 'severity' (for lack of a better word) should this be done?
Additionally, how much attention should XAML even be given over C# if it turns out C# is more efficient at runtime?
Should XAML simply be used as an area to place minimalistic tags ultimately defined, styled, given properties and controlled by C#?
In my opinion and experience, I would say resources are a very good tool provided by WPF engine. Now, question is performance issues, to answer that question I would point two huge tools Visual Studio and Blend both are build in WPF and UI elements are using dynamic resources heavily. But, there is no performance issues with the tool. So, to correctly answer your question, you should be using the correct technology at correct place. Resources provide you a great flexibility when you want to modify some thing like theme or visual appearance. Although to your point you need to be very careful of the usage and try to keep resources in check. Include only required resources in your page.
So, conclusion:
1. No, do not make a practice of converting everything into control and not use resources at all.
2. Yes, you need to make a considered effort in respect of resources to keep application performance optimized.
If you're referring to memory bloat due to repeatedly adding the same resources via transitive dependencies, check out the various implementations of SharedResourceDictionary floating about on the web. This can reduce working set and reduce startup time (in my experience) but you should take care to avoid memory leaks as most just store a static map from URI string to ResourceDictionary.
If you're making a more general question about whether resource dictionaries are useful or not, then yes, they are very useful and even essential for many kinds of common XAML patterns (such as StaticResource).
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I've written a (open source) C#/.NET library that contains a handful of strings that may be displayed to the user. Thus, it would be good to have them translatable.
I've worked at a couple of companies now and they always solved this problem via .resx files. However, as companies, they a) know exactly which languages their applications will be translated to and b) have the resources (man power, money) to have all of their strings translated.
As an open source author I neither want to limit the translation of my library to a certain set of languages nor do I have the resources to provide any translation at all.
So, ideally I would only provide the English "translation" for all my strings and user's of my library would have some way of translating these strings into their desired languages without any code changes to my library.
To my (limited) understanding, when using .resx files the default language (English) is compiled directly into the assembly/dll whereas other languages are provided as satellite assemblies. So, in theory, user's of my library could provide the satellite assemblies for their desired languages themselves.
Would this work for open source libraries (and if yes, how)? Or are there other, better (recommended) ways of how to deal with this problem?
(Ideally the solution should work with .NET Core.)
Having users of your library provide translations is not uncommon or unreasonable, I guess. At work we do the same with a commercial library where we also don't have the resources to provide all languages out of the box.
Translation still works with satellite assemblies, the only complicated part is to get the resource names correct (they use the default namespace of the project + any folders if you don't provide a custom name in the project file) so that they are picked up correctly at runtime.
You could use JSON to solve your translation problem
Slay the Spire is a really fun rouge-like deck building game
and to translate the game to various languages they came to the community with guidelines and files (which are basically JSON files).
Of course, i don't know the ins and outs of how they did that exactly but it seems you can use the same thing for your library
you can check the computer local language (or any other way) to get the user main language and pull(if exists) the right JSON file before the program starts up
TRANSLATOR_README
example for french translation
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have heared that sharing data using static class properties is not a good practice. Although I haven't seen any one using this approach but I can't find out what are the drawbacks for such appraoch!
To be more clear, Let's consider a WPF application composed of many UserControls that share data and parameters in a certain flow; using a static reference will make it easy to access/share these data, but no one seems to like this approach, Why?
I am expecting an anti-pattern related answer, I am just not sure what it is.
If it is only about parameters setup, don't see any problem with sharing them among different parts of application, instead of have multiple copies of the same data. It still stays on shoulders of SOLID principles, as the responsibility of that class is holding parameter/configuration options.
If you have also data, it becomes little bit more complicated. There is no one single best answer to this. Having data in one place violates SOLID principle, and
will be harder to write Unit Test
find bugs
harder to manage inside multi-threaded environment.
Note the word "harder", but not impossible.
On positive side
in modern computer architectures computations are way cheap then moving data from one place to another. so if you have compute intensive application, create data once and access it from different places is usually a better choice then pass it all around.
if you have multihtreaded, compute intensive application and by design of your data can guarantee no raise conditions on it, data-wise, it still is a better choice then having multiple copies. Create, copy/move memory is expensive.
Saying that. If you worry only about controls and UI stuff, I would suggest
to
configuration parameters keep in one static class (considering that you need single configuration setup during single run)
data information move to every class, which is responsible for it.
I don't think it's necessarily a bad practice, I just think it has the potential to be misused.
In your case, where you need state shared between user controls, it's probably not a good use because you want the state shared on the screen whereas static classes and their properties are shared across the entire application.
However, a static class is functionally a .NET version of the Singleton pattern and it's useful in similar circumstances.
http://en.wikipedia.org/wiki/Singleton_pattern
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
i am preparing for my finals and came across this question:
Learn about the reflection mechanisms of Java, C# and Prolog, all of
which allow
a program to inspect and reason about its own symbol table at run time. How
complete are these mechanisms? (For example, can a program inspect symbols that
aren’t currently in scope?) What is reflection good for? What uses should be
considered good or bad programming practice?
Why is this question asked in terms of symbol table? Can i write the same solution that i write in terms of classes and objects like mentioned in this SO question:
What is reflection and why is it useful?
I think of reflection as the basic tool to do metaprogramming.
This turns out to be a declarative way to solve (a kind of) problems.
Sometime, instead of building a solution, can be useful to write something that allow to describe the problem space. That is, see if your problem can be restated in a more practical language.
You see, we treat languages as components of algorithms, like data. Then we can exchange components between languages.
Practically, an example of interesting Java/Prolog reflection is JPL
Some time ago I found useful - and performant - C# reflection. United to emit package allows to produce compiled code.
Prolog use reflection in seamless ways: for instance DCGs are really a 'simple' rewrite of declared rules.
I've started a project that I hope I will take me to Prolog controlling Qt interface,
of course Qt reflection plays a fundamental role.
edit About your question on symbol tables: symbol is an extremely general term. Also all languages have a concept of symbols, (maybe) differently aggregated. That's the core of languages. Then the question is perfectly posed in very general terms, just to check your understanding of these basic language concepts.
The "symbol table" is just an internal concept that is needed for "reflection" to do what it does: the ability of a program to examine itself at runtime and do something dynamically with that. (be aware about the diff between - introspection vs. reflection).
So if you understand what reflection is good for, how it is implemented in your target platform (Java, C# etc.), and what might be the limitations, you should be able to answer all those questions I suppose.
Think about the symbol table as just an "implementation detail" of a platform/runtime. According to the question above I don't think they expect you to know exactly how this is implemented.
I'd suggest you to read the following pages to get an idea of reflection in the corresponding language:
JAVA
C#
Prolog - Search for 'Reflection'
After Reading those you shold see similarities of the methods.
To be honest, I've never worked with reflection in Prolog, but the docs should guide you through.
The symobl table is used by the reflection mechanisms to look the things up.
See here for a description of symbol tables.
Those resources should give you an idea on how to answer your questions
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I work on GUI and deal with complex objects that is objects have other objects and those object might have other objects.
These objects are manipulated (often almost at the same time) by various views, view models, services, nhibernate, and you name it - doing in simple things like, save/update/delete/validate and etc.
In most cases things like NotifyPropertyChanged is enough, but not always. Sometimes i resolve to calling EventAggregator BUT when object graph is big and especially collection of such objects - it gets so messy i keep loosing ends and not sure what is exact state of a particular object and often not sure if that is still same object or some loose copy of it;
So my question is what is best approach / methodology to manage object states and avoid "state explosion"?
Simplify by introducing additional structure. The best methodology is giving the application more structure. Divide the application into smaller parts internal living of which you can oversee and control well. Let these parts be hidden behind facade/adapter types which expose only a simplified view on that part of the system. Repeat recursively as long as necessary. Use formal models to define structure and inter-communication rules, e.g. UML 2.0 hierarchical state machines usually fit well... I know, this is just a generic engineering bla-bla, but it could help...
I advise you to take note of a book Agile Principles, Patterns, and Practices in C# by Robert C. Martin and Micah Martin, there are many good examples where it is shown how to design a system by UML, and other similar methods. Specifically, it is shown why you should refactor your code, that can be stored in abstract classes and what is not. You can immediately see an example with a coffee maker Mark IV, where he developed a truly independent interface.
According to my feelings, the main principle of MVVM - is the independence of the data from its representations. I like trying to make separate modules, which implement separate logic, not knowing about the data. For example, SQL module, SMTP module, etc, which simply contain some methods like ConnectToDb() or SendEmail(), the main logic is in ViewModel, she combines these Work-modules with the data model.
Useful to draw a diagram before designing the system, but do not get involved too. The main thing is to see the main parts in the paper, and that the others would understand it as well as you know (or architect).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm developing a price calculation engine. I've looked all over and there's nothing that really fits what we need. However, I'm now looking how to implement specific prices and/or discounts. I don't want to introduce a rule based engine to my end-users, because they won't get it.
For example, when you order an ItemX the price is $30. But in combination with ItemY the price of ItemX is $20. Or when ordering five of ItemX, each after it will be only $15.
Any ideas on where to start? How to take this on? Perhaps some (open source) example applications that contain practices like these? Any (technical) patterns I could use? Preferably in C#.
Thanks in advance!
There are many ways you can achieve this, but I think the one which might be most useful for you would be to define a DSL that you can use to express your discounts in such a way where they can be easily explained and rationalised with business users. An example from one of ayende's articles on DSLs in boo is:
apply_discount_of 5.percent:
when order.Total > 1000 and customer.IsPreferred
when order.Total > 10000
suggest_registered_to_preferred:
when order.Total > 100 and not customer.IsPreferred
As you can see you can see, this is the kind of thing you can print out and show to a client and they will immediately understand what's going on.
Of course developing something like this is time consuming, expensive and fraught with funky edge cases. However it has the benefit of being code which can be unit tested, executed and debugged.
If boo isn't your thing, then maybe you could look at defining something similar in ironruby, ironpython or F#. I would however suggest staying away from XML for defining these rules unless you really enjoy a world of pain.
This is however the kind of thing that products like Biztalk were designed to handle. Which rules engines have you evaluated and found lacking?
We use a Rule Engine for this type of complex calculation. Our platform is Java and we use Drools (which we're happy with). Drools is also available for .Net. Here's a list of open source Rules Engines for .NET.
I am sorry to have to say this, but this would seem like you would have to apply some Pricing Rule Engine to achive what you are after.
Would seem like you have to
Store the available items, and their
discounts on per pruchase.
Store which items in combination
would discount each other.
Also maybe thinking of per
unit/quantity purchased per unit, or
maybe per package/special.
Might want to look at keeping a
archive/storage of these
specials/packages, just incase the
customer wants a reprint of the
original invoice.
In general there is a lot of possible rules/combinations that can be thought of, and you as developer can implement these and hide them from the user, or allow the user to create them, but somebody has to do so.
And then, when you dont feel like implementing your own, GOOGLE shold provide some:
Open Source Rule Engines