differences between 'weak' and 'unowned' references in vala? - weak-references

What are the differences between weak and unowned references in Vala.
Based on what I've learned from Vala tutorials both weak and unowned references are not counted, and when the real instance goes out of scope they will refer to null(!!).
Why there should be tow distinct means for one reason?(if they do the same job)
If not, could someone give me a simple example to show why and when we have to use each of them?!
Thanks a lot

There is no difference between the two right now. The language developers chose two distinct keywords to indicate the possibility that there may be a difference in the future, see this quote from the documentation:
At the moment weak and unowned can be used interchangeably. However, you should use weak only for breaking reference cycles and unowned only for ownership issues as described above.
Weak references are used, as far as I can see, on GLib.Object subclasses, and unowned references are used on non-reference-counted ("compact" in Vala terminology) classes imported from non-GObject C libraries. There are examples on the documentation page I linked to above.

Related

Linking Entities with sentences

When an ontology is created from text consisting of a set of sentences, it can be useful to bind any given concept with all the sentences, where it is present. But that inevitably leads to a nasty duplication of sentences, when the usual Annotation is used for storing the related text.
E.g. the sentence "Attributive language is the base language which allows: Atomic negation (negation of concept names that do not appear on the left hand side of axioms), Concept intersection, Universal restrictions, Limited existential quantification." would need to be copied as an Annotation to the Entities: Attributive language, Language, Atomic negation, Negation, Concept names, Axiom, Concept intersection, Universal restriction, Limited existencial quantification.
What is in your opinion a good way to avoid copying the same sentence to several locations and yet to have traces from the Entity to the relevant sentences?
I would create a named individual with an IRI and attach the sentence to it, then add a relationship from the concepts to the individual.
The individual might have a type, e.g., Sentence, but this is not necessary. Properties used can be annotation properties or data/object properties.

OWL Terminology: Why do Individuals Have ObjectProperties (Instead of IndividualProperties)

In the W3 OWL specification the properties of individuals are divided in to two groups: datattype properties and object properties. Object properties are defined (as one article I found put it):
"Object properties (owl:ObjectProperty) relates individuals (instances) of two OWL classes.
So in essence, object properties could also be called "individual properties", because they don't just point to generic objects of any sort, they point specifically to individuals.
Now, if this was just some random spec I would assume the authors simply chose their names poorly, but this is a W3 spec, and one specifically on the storage of knowledge no less; I have to assume people thought about the names of things!
Therefore, I'm hoping someone here can explain this seemingly strange naming choice. After all, you can call damn near anything in any spec an "ObjectFoo", because Object is a super-generic term, but normally people use the most specific term possible, not the least, when they name things.
Is there perhaps some other case where an ObjectProperty can refer to something other than an individual, or anything else I'm missing that might explain this?
The term "ObjectProperty" was (most probably) coined to distinguish it from "DatatypeProperty", in the sense that the latter can only have (datatyped) literal values, as opposed to full objects. And yes, it's not just individuals that can be the value of an ObjectProperty, classes can be values of them too - although if you do that, your ontology is no longer valid OWL DL and becomes OWL Full instead. But it's valid from a modeling perspective.
My answer is also a comment to Jeen. OWL DL and OWL Full are 2 distinct languages with a different (even disjoint) abstract syntax. OWL DL syntax is defined in terms of its structural specification. OWL Full syntax is RDF. The structural specification of OWL does not even contain any RDF triple.
Now, in OWL DL, it is invalid to relate two classes with an object property. Object properties can only relate instances of owl:Thing. They cannot relate literals, properties, ontologies, or datatypes either. If you call the notion IndividualProperty, you are creating an inconsistency in naming because DatatypeProperty does not mean a property that relates datatypes. It is a property that relates literals. So a better name would be ClassProperty. Or you would have to change both DatatypeProperty and ObjectProperty into LiteralProperty and IndividualProperty.
All in all, there are various ways to deal with this, the working group chose the one which gathered more votes. That's all how it always works in a standardisation group.
The name comes from "Subject Predicate Object". Those are properties that link the Subject with the Object, as opposite to Datatype Properties that are merely attributes.

typical educational constraint processing examples

I'm writing a course describing several topics of Artificial Intelligence. Currently I'm working on the "Constraint Processing" part. To illustrate constraint processing I would like to include a simple example. This examples should have the following qualities:
I want to draw an OR-tree so the example can't have that much variables and options
Illustrating node consistency, backtracking, backjumping, backmarking, weak relaxation and arc consistency. (The examples should illustrate that these methods make sense and add some value to constraint processing).
Easy to understand and represent. (Not a two page long array of constraints).
I have browsed the web for some time, but all examples by now don't meet these qualities. (I've also tried to simplify existing problems).
Are there any typical exampes to illustrate these methods/techniques? Giving two different examples and distribute the techniques between these two examples wouldn't be a problem too.
The Traveling Tournament Problem might fit some of your requirements. It's NP hard and doesn't have much variables and options:
Official page
Problem statement

Object vs Document Storage (Databases) = Difference (nosql)?

i would be thankfull for a short explanation of these different concepts. Wikipedia mentions both in context of NoSQL but I did not find any further information whats the difference between both.
Update regarding the comments:
http://en.wikipedia.org/wiki/NoSQL#Object_database
vs
http://en.wikipedia.org/wiki/NoSQL#Document_store
But the difference is completely unclear to me. (Stackoverflow does not allow me to post two links as newbie so the links are actually disabled)
For most practical purposes, there is no difference - A document is often just a serialized object, and if you only need basic storage, any key/value store can hold objects.
There may be differences in things like how partial updates and queries are handled, but since there is no such thing as standard NoSQL, you get just as many differences between products in the same category.
"S3 is an object store ... DynamoDB is a document database" They go into some detail about the differences here: https://serverless.pub/s3-or-dynamodb/

Table Naming: Underscore vs Camelcase? namespaces? Singular vs Plural?

I've been reading a couple of questions/answers on StackOverflow trying to find the 'best', or should I say must accepted way, to name tables on a Database.
Most of the developers tend to name the tables depending on the language that requires the database (JAVA, .NET, PHP, etc). However I just feel this isn't right.
The way I've been naming tables till now is doing something like:
doctorsMain
doctorsProfiles
doctorsPatients
patientsMain
patientsProfiles
patientsAntecedents
The things I'm concerned are:
Legibility
Quick identifying of the module the table is from (doctors||patients)
Easy to understand, to prevent confusions.
I would like to read any opinions regarding naming conventions.
Thank you.
Being consistent is far more important than what particular scheme you use.
I typically use PascalCase and the entities are singular:
DoctorMain
DoctorProfile
DoctorPatient
It mimics the naming conventions for classes in my application keeping everything pretty neat, clean, consistent, and easy to understand for everybody.
Since the question is not specific to a particular platform or DB engine, I must say for maximum portability, you should always use lowercase table names.
/[a-z_][a-z0-9_]*/ is really the only pattern of names that seamlessly translates between different platforms. Lowercase alpha-numeric+underscore will always work consistently.
As mentioned elsewhere, relation (table) names should be singular: http://www.teamten.com/lawrence/programming/use-singular-nouns-for-database-table-names.html
Case insensitive nature of SQL supports Underscores_Scheme. Modern software however supports any kind of naming scheme. However sometimes some nasty bugs, errors or human factor can lead to UPPERCASINGEVERYTHING so that those, who selected both Pascal_Case and Underscore_Case scheme live with all their nerves in good place.
An aggregation of most of the above:
don't rely on case in the database
don't consider the case or separator part of the name - just the words
do use whatever separator or case is the standard for your language
Then you can easily translate (even automatically) names between environments.
But I'd add another consideration: you may find that there are other factors when you move from a class in your app to a table in your database: the database object has views, triggers, stored procs, indexes, constraints, etc - that also need names. So for example, you may find yourself only accessing tables via views that are typically just a simple "select * from foo". These may be identified as the table name with just a suffix of '_v' or you could put them in a different schema. The purpose for such a simple abstraction layer is that it can be expanded when necessary to allow changes in one environment to avoid impacting the other. This wouldn't break the above naming suggestions - just a few more things to account for.
I use underscores. I did an Oracle project some years ago, and it seemed that Oracle forced all my object names to upper case, which kind of blows any casing scheme. I am not really an Oracle guy, so maybe there was a way around this that I wasn't aware of, but it made me use underscores and I have never gone back.
I tend to agree with the people who say it depends on the conventions of language you're using (e.g. PascalCase for C# and snake_case for Ruby).
Never camelCase, though.
After reading a lot of other opinions I think it's very important to use the naming conventions of the language, consistency is more important than naming conventions only if you're (and will be) the only developer of the application. If you want readability (which is of huge importance) you better use the naming conventions for each language. In MySQL for example, I don't suggest using CamelCase since not all platforms are case sensitive. So here underscore goes better.
These are my five cents. I came to conclusion that if DBs from different vendors are used for one project there are two best ways:
Use underscores.
Use camel case with quotes.
The reason is that some database will convert all characters to uppercase and some to lowercase. So, if you have myTable it will become MYTABLE or mytable when you will work with DB.
Naming conventions exist within the scope of a language, and different languages have different naming conventions.
SQL is case-insensitive by default; so, snake_case is a widely used convention. SQL also supports delimited identifiers; so, mixed case in an option, like camelCase (Java, where fields == columns) or PascalCase (C#, where tables == classes and columns == fields). If your DB engine can't support the SQL standard, that's its problem. You can decide to live with that or choose another engine. (And why C# just had to be different is a point of aggravation for those of us who code in both.)
If you intend to ever only use one language in your services and applications, use the conventions of that language at all layers. Else, use the most widely used conventions of the language in the domain where that language is used.
C# approach
Singular/Plural
singular if your record in row contains just 1 value.
If it is array then go for plural. It would make perfect sense also when you foreach such element. E.g. your array column contains MostVisitedLocations: London, NewYork, Bratislava
then:
foreach(var mostVisitedLocation in MostVisitedLocations){
//go through each array element
}
Casing
PascalCase for table names and camelCase for columns made the best sense to me. But in my case in .NET 5 when I had json objects saved in dbs with json object names in camelCase, System.Text.Json wasnt able to deserialise it to object. Because your model has to be public and public properties are PascalCase. So mapping table columns(camelCase) and json object names(camelCase) to these properties can result in error(because mapping is case sensitive).
Btw with NeftonsoftJson this problem is not present.
So I ended app with:
Tables: App.Admin, App.Pricing, UserData.Account
Columns: Id, Price, IsOnline.
2 suggestions based on use cases:
Singular table names.
Although I used to believe in pluralizing table names once, I found in practise that there is little to no benefit to it other than the human mind to think in terms of tables as collections.
When singularising the table names, you can silently add -table to the singular table name in your head, and then it all makes sense again.
SELECT username FROM UserTable
Sounds more natural than
SELECT username FROM UsersTable
But post-fixing every table with is just a waste.
The actual practical argumentation for singularising table names:
What is the plural of person: persons or people?
This is still ok.
But how do you like a table with postfix -status? Statuses?
That sucks, sorry.
It is easy to inadvertently make a human mistake by singularizing the status table, but pluralizing the other tables.
PascalCasing + Underscore convention.
Given table User, Role and a many-to-many table User_Role.
Considering underscore cased user_role is dubious when all table names are using underscore per default.
Is user_role a table that contains user roles? In this case it is not, it is a join table.
When deciding on table name conventions I think it is useful to let go of personal preference and take into account the real practical considerations of real life problems in order to minimize dubious situations to occur.
As the many answers and opinions have indicated, whatever your personal opinion is, different people think differently, and you will not be the only person working on the database despite being the one who sets it up (unless you do, in which case you're only helping yourself).
Therefore it is useful to have practical argumentation (practical in the sense of, does it help my future co-workers to avoid dubious situations) when your past decision is being questioned.
Unfortunately there is no "best" answer to this question. As #David stated consistency is far more important than the naming convention.
there's wide variability on how to separate words, so there you'll have to pick whatever you like better; but at the same time, it seems there's near consensus that the table name should be singular.

Resources