Dart: microtypes - dart

Does Dart have any good patterns or libraries for "microtypes" / "branded types" (that is, a way to distinguish different flavours of more basic types like Strings in the type system). For example, you could have a type for an EmailAddress and a different one for a UserId, and you couldn't accidentally mix the two.

I don't think this is possible right now but there are a old issue for this here:
https://github.com/dart-lang/sdk/issues/2626
It seems this feature are planned to come in the near future if you read the latest comments on that issue.

Related

I need a service for generation sentence included a set of words

I need to generate random but lexically correct sentences with my words included. The sentence doesn't have to consist entirely of my words. But the more of them the better.
I have already searched through a lot of resources related to machine learning, but everywhere they write about generating RANDOM texts. I can't influence the result in any way by specifying the presence of at least a couple of my words as a condition.
Perhaps someone on this resource knows about repositories with similar libraries or APIs where I can get something like this?
After a week of searching, I can say that there is no ready-to-use library or service for this.
If you data scientist, you may found this problem interesting for a creation your own startup, i think.

RAML- !include strange behavior

I use this extension for Atom, to design my API, written in RAML.
I think I have a problem here :(I masked title and baseUri, sorry) :
If I follow RAML 1.0 specs, I should put a "!include". Strangely, apiworkbench detects no mistake.
If I do that :
Why didn't this work?
Very good conversations. Indeed the specification should be more clear about that, but the reason why libraries follows a different approach than normal !include is that an include simply adds new nodes to an existing where ever you used the !include keyword. Since it really is a simple "add" operation, it does not cover up for any cyclic dependencies.
Libraries are very much different and the use of namespaces (uses) are very much different. The purpose of libraries is to create a common shareable group of assets/definitions of best practices that people also use to create their own libraries or other definitions on top. Cyclic dependencies are inevitable. For that, the RAML workgroup had to come up with a different mechanism than what you have with !include. Hence, for libraries you should always use:
uses
lib: mylib.raml
Hope that explains the rationality behind it, but please let me know if you have more questions.
No, for libraries you must NOT use the include keyword.
It seems the specification is not very clear about this or at least I could not find it clearly specified anywhere. Thus raising an issue about this would be a good idea.
But if you check the examples in the specification you will see that when using libraries (with the "uses" keyword) the "!include" is omitted.

iOS event bus library with event objects?

We've used greenrobot's EventBus library extensively in Android development, and we're looking for something similar for iOS. It looks like a sort of event bus is already built in in the form of NSNotificationCenter, as well as quite a few third-party solutions that are essentially wrappers for this functionality with some added features for convenience.
However, we're rather accustomed to the concept of events being discrete objects with clearly defined member variables, with the additional benefit of polymorphism from being object-oriented. Most iOS libraries I've found so far have you passing in an arbitrary event name and an arbitrary bundle of data, which is a little too loosey-goosey for our purposes.
The only example of the object-oriented design I've found so far is Tolo, which looks great at first glance, but hasn't been updated in about three years, save for some minor documentation details. Also, given its age, it's still written in Objective-C, which could lead to some difficulties if we need to look under the hood at some point (we're pretty committed to Swift).
Are there any other options I haven't come across yet?
No reason why you cannot create a specific class that you pass as the object in NSNotificationCenter. Its true that many examples are lazy in this respect, obj-c is traditionally fairly loosely typed which probably explains this.
Its also fairly common (in projects bigger than online tutorials) to use a constant of some sort as the event name, either a class constant or a #define if using obj-c.
For anyone in 2017+ interested in this, I wrote this thing ages ago:
https://github.com/MooseMagnet/DeliciousPubSub
It offers strongly-typed pub-sub.
Under the hood it still uses strings as a key (just uses the name of the type) but you get compile-time goodness...
I left it sitting for a while under the assumption no one was using it, but recently received a PR from someone who had updated it for Swift 3. Wow, such OSS.

Generic Linked List for Delphi 2009

I was looking in Generics.Collections and noticed there was no linked list. Sure they are simple to make, but I thought it was odd there was not one (or I just missed it). Are linked lists just outdated when compared to new modern data structures, or is there a need for a general generic linked list? Does anyone know of one?
Do you know the DeHL?
I think the TLinkedList<T> from the DeHL.Collections.LinkedList.pas unit is exactly what you are looking for.
In the old days, almost any piece of serious software contained linked lists or trees.
I haven't used linked lists alot, but trees are another story.
With the introduction of dynamic arrays, there is not that much need for linked lists. But I can imagine that you want to use it if your datastructure is changed often (add + delete).
You can easily create a generic linked list yourself, using a container class and records for the elements.
I don't know of any generic, linked list in the existing Delphi RTL.
They are still very useful as a data structure, however. Especially if you include variants on a linked list such as a b-tree or a binary tree. Unlike a regular list, a linked list can be expanded, edited, or modified without moving data in memory. They are very easy to version, and work well in purely functional code which does not allow mutating existing data. So it is still a very useful data structure.
Isn't that what tStringList is for?
(ducking)
Actually, any generic tList works fine as a linked list, and supplies most of the functionality needed. The ancient technique passed down from our ancestors of storing a pointer to memory in each record, and navigating to that has been easily replaced by dynamic arrays and doing things...more generically.

How do you implement a multiculture web application

I believe several of us have already worked on a project where not only the UI, but also data has to be supported in different languages. Such as - being able to provide and store a translation for what I'm writing here, for instance.
What's more, I also believe several of us have some time-triggered events (such as when expiring membership access) where user location should be taken into account to calculate, like, midnight according to the right time-zone.
Finally there's also the need to support Right to Left user interfaces accoring to certain languages and the use of diferent encodings when reading submitted data files (parsing text and excel data, for instance)
Currently I'm storing all my translations for all my entities on a single table (not so pratical as it is very hard to find yourself when doing sql queries to look into a problem), setting UI translations mainly on satellite assemblies and not supporting neither time zones nor right to left design.
What are your experiences when dealing with these challenges?
[Edit]
I assume most people think that this level of multiculture requirement is just like building a huge project. As a matter of fact if you tihnk about an online survey where:
Answers will collected only until
midnight
Questionnaire definition and part of
the answers come from a text file
(in any language) as well as
translations
Questions and response options must
be displayed in several languages,
according to who is accessing it
Reports also have to be shown and
generated in several different
languages
As one can see, we do not have to go too far in an application to have this kind of requirements.
[Edit2]
Just found out my question is a duplicate
i18n in your projects
The first answer (when ordering by vote) is so compreheensive I have to get at least a part of it implemented someday.
Be very very cautious. From what you say about the i18n features you're trying to implement, I wonder if you're over-reaching.
Notice that the big boy (e.g. eBay, amazon.com, yahoo, bbc) web applications actually deliver separate apps in each language they want to support. Each of these web applications do consume a common core set of services. Don't be surprised if the business needs of two different countries that even speak the same language (e.g. UK & US) are different enough that you do need a separate app for each.
On the other hand, you might need to become like the next amazon.com. It's difficult to deliver a successful web application in one language, much less many. You should not be afraid to favor one user population (say, your Asian-language speakers) over others if this makes sense for your web app's business needs.
Go slow.
Think everything through, then really think about what you're doing again. Bear in mind that the more you add (like Right to Left) the longer your QA cycle will be.
The primary piece to your puzzle will be extensive use of interfaces on the code side, and either one data source that gets passed through a translator to whichever languages need to be supported, or separate data sources for each language.
The time issues can be handled by the interfaces, because presumably you will want things to function in the same fashion, but differ in the implementation details. To a large extent, a similar thought process can be applied to the creation of the interface when adjusting it to support differing languages. When you get down to it, skinning is exactly this, where the content being skinned is the interface, and the look/feel is the implementation.
Do what your users need. For instance, most programmer understand English, there is no sense to translate posts on this site. If many of your users need a translation, add a new table column with the language id, and another column to link a translated row to its original. If your target auditory contains the users from the Middle East, implement Right to Left. If time precision is critical up to an hour, add a time zone column to the user table, and so on.
If you're on *NIX, use gettext. Most languages I've used have some level of support; PHP's is pretty good, for instance.
I'll describe what has been done in my project (it wasn't my original architecture but I liked it anyways)
Providing Translation Support
Text which needs to be translated have been divided into three different categories:
Error text: Like errors which happen deep in the application business layer
UI Text: Text which is shown in the User interface (labels, buttons, grid titles, menus)
User-defined Text: text which needs to be translatable according to the final user's preferences (that is - the user creates a question in a survey and he can also create a translated version of that survey)
For each different cathegory the schema used to provide translation service is different - so that we have:
Error Text: A library with static functions which access resource files
UI Text: A "Helper" class which, linked to the view engine, provides translations from remote assemblies
User-defined Text: A table in the database which provides translations (according to typeID of the translated entity and object id) and is linked to the entity via a 1 x N relationship
I haven't, however, attacked the other obvious problems such as dealing with time zones, different layouts and picture translation (if this is really necessary). Does anyone have tackled this problem in a different way?
Has anyone ever tackled the other i18n problems?

Resources