From documentation, it looks like the attribute 'require' does not exist for resource types such as 'exec', 'package', 'file', etc.
I've seen several posts on stackoverflow where folks have been showing examples of using 'require' as an attribute to perform some kind of resource ordering and dependencies. Require appears to be a class function only.
Has there been changes to this? Or is the community misled about the usage of 'require' as a resource attribute?
Has there been changes to this?
No.
Or is the community misled about the usage of 'require' as a resource attribute?
No.
require is one of Puppet's metaparameters. These can be used with every resource type, including custom types and defined types. This has been the case since before the earliest Puppet I have experience with, v0.24.8. Since they apply to every single resource type, and have exactly the same meaning for each, they are documented in their own section (linked above). The language reference also discusses them and their universal nature.
Related
I walk the first steps in codeigniter4.
Now I ask myself what are the big differences between a "Model" where I do at first all database related things, a "Helper" where I defined a set of functions or a "Libary"?
In which cases should I create my own libary, helper, model?
The CI4 Docu won't give me a answer for that, so I hope someone can explain it for me (and other ones)
The documentation is pretty straight forward when it comes to Models, there's really no caveats there. A Model is a class that represents a single table in the database and it provides to you a wide variety of related functionality: built-in CRUD methods, the ability to save Entities, transparent use of Query Builder methods, etc.
In general, you would typically have one Model class per database table that you're working with. That being said, you do not necessarily need Models in order to work with a database; however if you expect to need the functionality a Model provides, it can be used to save you the work of doing it yourself.
The documentation is indeed far more opaque on the differences between Libraries and Helpers. As such, I've found the most objective measure of difference to be in how CodeIgniter itself utilizes them, and the distinction is rather subtle:
Libraries provide their functionality through methods that exist within the namespace of the class they're defined in.
Helpers provide their functionality through functions that exist within the namespace of the importing class.
(NB: In PHP, a method is simply the name for a function that's defined within a class)
In other words, Libraries are typically non-static classes that (like all non-static classes) must be 'constructed' before use. The methods defined within that class reside within the namespace of the class itself, not the class they're called from.
For example, to gain access to the current Session object, I retrieve an instance of the Session Library class: $session = session(); Using $session, I can then invoke methods provided by that Session class, like $session->destroy().
On the other hand, Helpers are typically just a collection of functions that are imported into the namespace of the importing class itself. They are called in the current context and their use is not predicated upon the use of an object.
For example, if I loaded the Array Helper (helper('array');), it would grant me access to a handful of functions that I could call directly from the current context (e.g. $result = array_deep_search(...)). I didn't have to create an object first, that function was imported directly into my current namespace.
This distinction could matter for a couple of reasons, the biggest of which is probably naming conflicts. If you have two Helpers, each with an identically-named function, you can't import both of those functions at the same time. On the other hand, you could have one hundred different classes with the destroy() method defined, because each of those method definitions resides within the namespace of the defining class itself and is invoked through an instance of that specific class.
You may notice that all of CI's Helper functions are prefixed with the name of the Helper itself, e.g. 'array' or 'form'; this is to prevent the aforementioned naming conflict.
This probably doesn't answer when you want to use one or the other, and in truth that really comes down to your opinion. In the end, it's all just namespacing. You can put things wherever you want, as long as the code that needs it knows where to look for it. I personally try to follow CI's lead on things, so I tend to follow their distinction between the two.
When building an event store, the typical approach is to serialize the event and then persist the type of the event, the body of the event (the serialized event itself), an identifier and the time it occurred.
When it comes to the event type, are there any best practises as to how these should be stored and referenced? Examples I see store the fully qualified path of the class ie.
com.company.project.package.XXXXEvent
What effort is then required though if you decide to refactor your project structure?
After years running event-sourced applications in production, we avoid using fully qualified class names or any other platform-specific identifiers for event types.
An event type is just a string that should allow any kind of reader to understand how the event should be deserialized. You are also absolutely right about the issue with refactoring the application structure that might lead to changes in the class name.
Therefore, we use a pre-configured map that allows resolving the object type to a string and to reverse the string to an event type. By doing so, we detach the event type meta from the actual class and get the freedom to read and write events using different languages and stacks, also being able to freely move classes around of needed.
What effort is then required though if you decide to refactor your project structure?
Not a lot of effort, but some discipline.
Events are messages, and long term viability of messages depend on having a schema, where the schema is deliberately designed to support forward and backward compatibility.
So something like "event type" would be a field name that can be any of an open set of identifiers which would each have an official spelling and semantics.
The spelling conventions that you use don't matter - you can use something that looks like a name in a hierarchical namespace, or you can use a URI, or even just a number like a surrogate key.
The identifiers, whatever convention you use, are coupled to the specification -- not to the class hierarchy that implements them.
In other words, there's no particular reason that org.example.events.Stopped necessarily implies the existence of a type org.example.events.Stopped.
Your "factories" are supposed to create instances of the correct classes/data structures from the messages, and while the naive mapping from schema identifier to class identifier works, then yes, they can take that shortcut. But when you decide to refactor your packages, you have to change the implementation of the factory such that the old identifiers from the message schema map to the new class implementations.
In other words, using something like Class.forName is a shortcut, which you abandon in favor of doing the translation explicitly when the short cut no longer works.
Since event sourcing is about storing Domain Events, we prefer to avoid package-names or other technical properties in the events. Especially when it comes to naming them, since the name should be part of ubiquitous language. Domain Experts and other people don't lean on package names when making conversation about the domain. Package names are a language construct that also ties the storage of the Domain Events with the use of them within your software, which is another reason to avoid this solution.
We sometimes use the short class name (such as Class.forName in Java) to make mapping to code simpler and more automatic, but the class names should in that case be carefully chosen to match the ubiquitous language so that it still is not too implementation-specific.
Additionally, adding a prefix opens upp the possibility to have multiple Event Types with the same name but using different prefixes. Domain Events are part of the context of the Aggregate they are emitted from and therefore the Aggregate type can be useful to embed in the event. It will scope your events so you don't have to make up synthetic prefixes.
If you store events from multiple bounded contexts in one store, BoundedContext.EventThatHappened. Past tense for events, and event names are unique for a bounded context. As your events will change implementation, there is no direct connection to a class name.
I have several schemas that inherit one or more elements from a collection of 'common' schemas. In this particular instance, I'm importing one of these schemas to make use of a single complex type defined in it.
When I generate the java objects from the schema, I get my schema types, and the element I referenced as expected, however I also get objects generated for the 30+ other types from the common schema.
I want to use the common schema, because I want to rely on automated builds for updating my schema when the common schema changes, but I do not want the extra java classes generated.
Suggestions ?
There's no out of the box approach to achieve what you want. The reason I am offering an opinion here is rather to point out (maybe for others) some issues one needs to take into account no matter which route ones go.
The 'extra' label is not always straightforward. Substitution group members are interesting. In Java, think about a class (A) using an interface (I), and a class (B:I) implementing (I). Some may say there's no dependency between A and B, while others would require B in the distribution. If you replace (I) with a concrete class, things become even less clear - consider that the substitution group head doesn't need to be abstract; or if the type of the substitution group head is anyType (Object in Java).
More so, if the XML processing was designed to accommodate xsi:type then it is even harder to tell (by looking at the schema) what is expected to work where.
Tools such as QTAssistant (I am associated with it) have a default setting that will pull in all strict dependencies (A and I above); and either ALL that might work (B above), or nothing else. Anything in between, the user needs to manually define what goes in the release. This is called automatic XSD refactoring and could be used easily in your scenario.
I'm quite new to Puppet, and so far I worked through the official tutorial, at least the introduction and part 1. So I guess I should have a basic understanding of how Puppet works and its terminology.
Anyway, there is one thing I don't get: In Puppet you have classes, which basically are nothing but outsourced manifests. So far, so good.
But why are they called class?
I have an OOP and CSS background, and I can also imagine the general concept of a class as a container for objects that have something in common. But none of these definitions match the concept of a class in Puppet. At least I don't get the analogy.
Can anybody bring some light into this?
PS: I know that there is no objective answer to this question, but primarily opinion-based, but I don't know where to ask elsewhere, so I hope for some advice :-)
You can relate Classes in puppet with division or separation of manifest bases on its role.
Classes are named blocks of Puppet code which are not applied unless they are invoked by name.
For the modularity and understanding of manifest it is recommended that different role of manifest code should be present in different file, which is called as classes.
And the name of class should denote its role. For example user(to create user), params(to pass parameters).
I believe it's recommended by Puppet and I'm sure it says this in the docs somewhere that you make classes for each of your node's roles that each contain requires for all other classes needed by that role with the same requires in multiple role classes if need be (which is allowed when you use the require command rather than include). This way you could have self contained classes such as 'fileserver' or 'webserver' which just need to be included in the node resources.
More on overlapping role classes:
http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html#aside-history-the-future-and-best-practices
I didn't take the usual CS route to learning programming and I often hear about namespaces but I don't really understand the concept. The descriptions I've found online are usually in the context of C which I'm not familiar with.
I am been doing Ruby for 2 years and I'm trying to get a deeper understanding of the language and OOP.
I am going to provide a more commonplace description.
Say my wife has a sister named Sue, and so do I. How can I tell them apart in a conversation? By using their last names ("Sue Larson" vs "Sue Jones"). The last name is the namespace.
This is a limited example of course, and in programming, the potential family members may be far more numerous than my example, therefore the potential for collisions is higher. Namespaces are also hierarchical in some languages (e.g. java), which is not paralleled with last names.
But otherwise it is a similar concept.
Definition of namespace from Wikipedia:
A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers (i.e., names). ...
For example, one place you can find namespaces usable is something like this:
You define a constant or a variable, or even a class which has a generic name. If you don't wish to rename this constant/variable/class, but need to have another one with the same name, you can define that new instance in different namespace.
In ruby, a module is basically the same thing a namespace is in C++.
eg:
module Foo
BAZ = 1
end
module Bar
BAZ = 2
end
puts Foo::BAZ #=> 1
puts Bar::BAZ #=> 2
So, there, you have constant BAZ declared in two modules (aka namespaces in ruby)
A namespace provides a container to hold things like functions, classes and constants as a way to group them together logically and to help avoid conflicts with functions and classes with the same name that have been written by someone else.
In Ruby this is achieved using modules.
just think of it as a logical grouping of objects and functionality
Shortest answer: Namespaces create scope.
Wikipedia has a short but useful article on namespaces in general, as well as a much more detailed one for namespaces in computer science, with language-specific examples &c.
The key point is that, when you cannot "logically group" names into namespaces, i.e. you only have a single undifferentiated "spaces" where all names live, to avoid accidental clashes you end up clumsily re-implementing rudimental namespace functionality by such tricks as name prefixes &c. For example, "to draw" means something very different to an artist or to a gunslinger; if you couldn't have separate namespaces for artist-stuff and gunslinger-stuff, you'd end up with identifiers such as artist_draw and gunslinger_draw, and still risk accidental clashes if some library authors use different conventions, etc, etc.
From php.net:
What are namespaces? In the broadest
definition namespaces are a way of
encapsulating items. This can be seen
as an abstract concept in many places.
For example, in any operating system
directories serve to group related
files, and act as a namespace for the
files within them. As a concrete
example, the file foo.txt can exist in
both directory /home/greg and in
/home/other, but two copies of foo.txt
cannot co-exist in the same directory.
In addition, to access the foo.txt
file outside of the /home/greg
directory, we must prepend the
directory name to the file name using
the directory separator to get
/home/greg/foo.txt. This same
principle extends to namespaces in the
programming world.
So, as another poster mentioned, namespaces can be used to group items together.
To see why this might be useful, suppose you want to write a plug-in for, say, Wordpress, and you want to create a class named 'MyClass'. The trouble is, though, you have no idea if some other developer has already written another Wordpress plug-in using a class named 'MyClass'. So to avoid naming conflicts, instead you name your class 'MyPluginMyClass'. This is annoying, but it probably avoids naming conflicts.
But then comes the release of PHP 5.3, which finally supports namespaces (let's assume, too, that Wordpress and all of the servers on which it is deployed upgrade to PHP 5.3). Now you can create a namespace, say 'MyPlugin', and encapsulate 'MyClass' within it. Having done this, you can publish your plugin without worrying that your version of 'MyClass' will conflict with someone else's version of 'MyClass'.