Refactoring a modelica library that doesn't use flow variable and stream variables - refactoring

I am digging into a modelica library called ThermoSysPro, but the connectors in this library don't use any flow variable and stream variable. This affects the code in the other components.
So If I wanna refactoring the code in this library, could anyone show me a similar example? Especially how to rewrite the code in the components to use stream variables.

To my knowledge there is no such example available. Nevertheless quite some work has been carried out in that regard. As a starting point I would suggest to read this. It explains in detail, which concepts have been used and why they have been sub-optimal. This includes in-/output, flow and stream connectors, also covering the Modelica-related fundamentals of each approach. It should therefore pretty much answer your question.

Related

Would it be appropriate to use Singles for RxAndroidBle reads and writes?

I'm still learning the Reactive paradigm, and just came across the Single<T> and SingleSubscriber<T> classes. It strikes me that these might be appropriate for "one-time" operations like reading or writing a control characteristic via BLE.
Does this make sense? What are the pros and cons? Would it require implementation by the authors of RxAndroidBle? Any explanation & discussion appreciated.
When the RxAndroidBle library was started there were no Single nor Completable classes in the RxJava library.
These constructs would fit well in the RxAndroidBle and are planned but it would need a bit of work from the library's author and would change the API - a version bump to 2.0.0 would be required.

PIC Programming

I truly apologize if my question is too amateurish or has been asked before (I searched and couldn't find anything).
I am working on a big project with a PIC MCU (MPLAB), I picked up where someone else stopped and he has no documentation of his code, it's horrible to look at.
The main problem is that I can't find any records online for functions that appear on the code (i.e rdft, I know it performs FFT but I want to know more about parameters structure etc.).
Is there a good online source for library function for PIC?
Or am I missing something and it's pure C written for embedded systems?
Thanks for your help.
Amir
With the provided information I cannot help with your particular code.
But answering your question:
Is there a good online source for library function for PIC?
Yes there is you can find it in http://www.microchip.com/doclisting/SoftwareLib.aspx
Where it includes several libraries including some to preform FFT's.
Or am I missing something and it's pure C written for embedded systems?
Well the IC provides several peripherals for different functionalities (SPI,I2C,ADC's, etc..) some IC's also include DSP's where one can implement FFT's making use of dedicated hardware on the IC's.
In the Software Lib's from Microchip you can find several libraries that provide an abstraction layer to access such hardware.
Well it's not easy to answer your questions, but when I program some C-Code in MPLAB X, I have no libraries, for the MCU. Well I program some 8-Bit MCUs like the PIC18F4550 or the PIC18F46K20, etc... But you can use some standard libraries like math.h, strings.h or so to implement. But the rest like an I2C-Port or an RS232-Port I write by my self in small functions. For the 8-Bit MCUs, there are practically no libraries available from Microchip themselves, at least what I know. :-)
My tip for you: Tell us which Microcontroller it is (if it is an 8-Bit or so) and take a look at the data sheet of it. Also, you could make a copy on your desktop of the Code and try to clean it up (with tabs), that it looks readable to you.
Well I don't know how else I could help you. :-)

Akka Promises and PromiseActorRef

I'm curious to learn more about Akka Promises but find the lack of adequate documentation most disturbing. In the v2.3.11 docs, the only reference to them that I can find is on the Addressing page where they give a rather vague definition of PromiseActorRef, and on the Futures page where they give a few code examples surrounding Futures.promise(). But no where (that I can find at least) do they actually dive into what a promise actually is, and what use cases are suited for using them. Thoughts?
Akka promises are just Scala promises.
http://docs.scala-lang.org/overviews/core/futures.html#promises
PromiseActorRef is an implementation detail you should not concern yourself with.

what does a web-based framework perform well?

thanks in advance.
Somewhere else I asked the same question but about scalability. Please let's not confuse both terms. I'd really like to understand what particular parameters I should look at when assessing if a framework performs acceptably.
I mean parameters such not over-querying the database for simple tasks just because the ORM above is not very well written, etc... Please let's try to answer this question without diving into a particular technology.
Lastly, let's assume that the underlying hardware is any that allow you to perform well, that is to say, there is no hardware bottleneck. I don't want a software that uses a cannon to kill mosquitos :).
Thanks again.
I mean parameters such not over-querying the database for simple tasks
just because the ORM above is not very well written, etc... Please
let's try to answer this question without diving into a particular
technology.
Succesfull ORM technologies are not under-performant. But if your web application is extremely simple (you don't define the scope of your question) then introducing a robust ORM that would be an overkill. Do a DAO pattern yourself instead.
Finally you can always do test measurements yourself to evaluate if the performance suits you

Should you wrap 3rd party libraries that you adopt into your project? [closed]

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
A discussion I had with a colleague today.
He claims whenever you use a 3rd party library, you should always write for it a wrapper. So you can always change things later and accomodate things for your specific use.
I disagree with the word always, the discussion arose regarding log4j and I claimed that log4j has well tested and time proven API and implementation, and everything thinkable can be configured a posteriori and there is nothing you should wrap. Even if you wanted to wrap there are proven wrappers like commons-logging and log5j.
Another example that we touched in our discussion is Hibernate. I claimed that it has a very big API to be wrapped. Furthermore it has a layered API which lets you tweak its inside if you so need. My friend claimed that he still believes it should be wrapped but he didn't do it because of the size of the API (this co-worker is much veteran than me in our current project).
I claimed this, and that wrapping should be done in specific cases:
you are not sure how the library will fit your needs
you will only use a small portion of a libary (in which case you may only expose a part of its API).
you are not sure of the quality of the library's API or implementation.
I also maintained that sometimes you can wrap your code instead of the library. For example, puting your database related code in a DAO layer, instead of preemptively wrapping all of hibernate.
Well, in the end this is not really a question, but your insights, experiences and opinions are highly appreciated.
It's a perfect example for YAGNI:
it is more work
it inflates your project
it may complicate your design
it has no immediate benefit
the scenarion you write it for may never manifest
when it does, your wrapper most likely needs to be re-written completely because it is tied too closely to the concrete library you were using and the new one's API simply doesn't match yours.
Well, the obvious benefit is for switching technologies. If you have a library that becomes deprecated, and you want to switch, you may end up rewriting a lot of code to accommodate the change, whereas if it were wrapped, you'd have an easier time writing a new wrapper for the new lib, than changing all your code.
On the other hand, it would mean that you have to write a wrapper for every trivial library that you include, which is probably an unacceptable amount of overhead.
My industry is all about speed, so the only time I'd be able to justify writing a wrapper is if it was around some critical library that was likely to change dramatically on a regular basis. Or, more commonly, if I need to take a new library and shoehorn it into old code, which is an unfortunate reality.
It's definitely not an "always" situation. It's something that may be desirable. But the time isn't always going to be there, and, in the end, if writing a wrapper takes hours and the long term code library changes are going to be few, and trivial...Why bother?
No. Java architects/wanna-bees are too busy designing against imaginary changes.
With modern IDE, it's a piece of cake when you do need change. Until then, keep it simple.
I agree with everything that's been said pretty much.
The only time wrapping third party code is useful (bar violating YAGNI) is for unit testing.
Mocking statics and so forth requires you to wrap the code, this is a valid reason to write wrappers for third party code.
In the case of logging code, its not needed though.
The problem here is partially the word 'wrapper', partially a false dichotomy, and partially a false distinction between the JDK and everything else.
The word 'wrapper'
Wrapping all of Hibernate, as you say, is a completely impractical enterprise.
Restricting the Hibernate dependencies to an identified, controlled, set of source files, on the other hand, may well be practical and achieve the same results.
The false dichotomy
The false dichotomy is the failure to recognize a third option: standards. If you use, say, JPA annotations, you can swap Hibernate for other things. If you are writing a web service and use JAX-WS annotations and JAX-B, you can swap between the JDK, CXF, Glassfish, or whatever.
The false distinction
Sure, the JDK changes slowly and is unlikely to die. But major open source packages also change slowly and are unlikely to die. Untold thousands of developers and projects use Hibernate. There's really no more risk of Hibernate disappearing or making radical incompatible API changes than there is of Java itself.
If the library you are planning to wrap is unique in its "access principles, metaphors and idioms" from other offerings in the same domain, then your wrapper is pretty much going to be similar to that library and won't do you any good if you one day switch to a different library since you will need a new wrapper.
If the library is accessed in a similar way to other libraries and the same wrapper can apply to these libraries, then they are probably written based on some existing standard and there is some common layer that already exists to access both of them.
I would only go with wrappers if I knew for sure that I would have to support multiple and substantially different libraries in production.
The main factor for deciding to wrap a library or not is the impact a library change will have on the code. When a library is only called from 1 class the impact of changing library will be minimal. If on the other side a library is called in all classes a wrapper is much more likely.
Any uncertainty around the choice of 3rd party library should be flushed out at the beginning of the project using prototypes to test the scalability/suitability/whatever of the 3rd party library.
If you decide to go ahead and provide full de-coupling/abstraction support it should be costed up and ultimately approved by the project sponsor - ultimately it's a commercial decision as someone has to pay for it and the work required to do it (unless it's absolutely trivial, in which case the api is probably low risk anyway).
Generally an experienced architect will chose a technology that they can be reasonably confident with, and have experience of, and that they are confident will last the lifetime of the app, OR else they will eliminate any risk in the decision early on in the project, thus removing any need to do this, most of the time
I'd tend to agree with most of your points. Using absolutes often gets you into trouble and saying you should "always" do something limits your flexibility. I'd add some more points to your list.
When you use wrapping code around a very common API, like Hibernate or log4j you make it more difficult to bring on new developers. New developers now have to learn a whole new API, where if you hadn't wrapped the code they would have been very familiar right away.
On the flip side of that, you also limit your developers' view into the API. Using an advanced feature of the API takes more time because you have to make sure that your wrapper is implemented in a way that can handle it.
Many of the wrapping layers I've seen also are very specific to the underlying implementation. So, if you write a log wrapper around log4j, you are thinking in log4j terms. If some new cool framework comes out, it may change the whole paradigm, so your wrapping code doesn't migrate as well as you had thought.
I'm definitely not saying wrapping code is always bad, but as you stated, there are a lot of factors you have to consider.
The purpose of wrapping even a well-tested and time-proven 3rd-party library is that you might decide to switch libraries at some point in the future. Wrapping it makes it easier to switch without changing any code in your core application. Only the wrapper needs to change.
If you're absolutely sure that you'll never (another absolute) use a different logging framework in your project, go ahead and skip the wrapper. Even having said that, I'd probably hold off on writing the wrapper until I knew I needed it, like the first time I need to switch.
This is kind of a funny question.
I've worked in systems where we've found showstopper bugs in libraries we were using, and which upstream was either no longer maintaining, or not interested in fixing. In a language like Java, you usually can't fix internal bugs from a wrapper. (Fortunately, if they're open-source, you can at least fix them yourself.) So it's no help here.
But I'm often working in a language where you can easily modify libraries at any time, without seeing or even having their source code -- I commonly add new methods to existing classes, for example. So in this case, there's no point in wrapping: just make the change you want.
Also, does your colleague draw the line at things called "libraries"? What about Java itself? Does he wrap built-in classes? Does he wrap the filesystem? The thread scheduler? The kernel? (That is, with his own wrappers -- in a sense, everything is a wrapper around the CPU, but it sounds like he's talking about wrappers in your source repo that are completely under your control.) I've had built-in functionality change or disappear when new versions of it appear. Java is not immune from this.
So the idea to always write a wrapper comes down to a bet. Assuming he's only wrapping third-party libraries, he seems to be implicitly betting that:
"first-party" functionality (like Java itself, the kernel, etc.) will never change
when "third-party" functionality changes, it will always be done in a way that can be fixed in a wrapper
Is that true in your case? I don't know. Of the medium-large Java projects I've done, it's rarely true for me. I wouldn't spend effort wrapping all third-party libraries, because it seems like a poor bet, but your situation is certainly different from mine.
There is one situation where you with good reason can wrap. Namely if you need to test stuff, and the default third party object is heavy weight. Then having an interface can really make a difference.
Note, this is not to replace the library ,but make it manageable where it doesn't matter much.
Wrapping a whole library is boilerplate, ineffective, and wrong in most cases. It can be done in a much clever way. I'd say that wrapping a library is appropriate mostly in case of UI component libraries, and again, you have to be adding some additional core functionality of yours to all the components for this to be needed.
if too much modifications and additions are needed, this is most likely not the library you are looking for
if there is a moderate amount of additions and modifications - there are always the design patterns that come handy in those cases. The Decorator pattern (allows new/additional behaviour to be added to an existing object dynamically) , for example, is rather suitable for the most cases.
IDE search/replace and refactoring capabilities offer an easy way to change your code in all required places if some important change is needed and a wrapping object appears. (of course, unit-tests would be helpful here ;) )
In my experience the question becomes fairly moot if you're using abstractions sufficiently. Coupling to a library is just like coupling to any other interface. Thus you want to reduce accidental coupling and the scope of rewrite necessary if you need to swap out the implementation. Don't bind your application logic to some construct, but don't just form a bunch of stupid (literally) wrappers around something and expect to gain any benefit.
A wrapper doesn't usually gain you anything unless it's answering a specific purpose (such as polymorphizing a non-polymorphic construct). They often show up in refactoring, but I wouldn't recommend forming an architecture on them. There's a few exceptions of course, but there is with any principle.
This doesn't speak toward adapters. An adapter can be a pretty important component for when you want to actually alter the interface of a library and its use to be in line with architecture, code, or domain concepts in your project.
You should do it always, often, sometimes, rarely, or never. Not even your colleague does it always, but the instructive cases are always and never. Suppose that it is sometimes necessary. If you never wrapped a library, the worst consequence is that one day you discovered that it was necessary for a library that you had used all over the place. It would take you some time to wrap that library and to perform shotgun surgery on the clients. The question is whether that eventuality would take more time than habitually providing wrappers that are rarely necessary, but having never to perform the shotgun surgery.
My instinct is to appeal to the YAGNI (you ain't gonna need it) principle and opt for "rarely".
I would not wrap it as a one to one thing, but I would layer the app so that each part it replaceable as much as possible. The ISO OSI model works well for all types of software :-)

Resources