One year ago, we published a set of slides about the main concepts implemented by our framework. Mainly about ORM (and ODM), NoSQL, JSON, SOA, MVC (and MVVM), SOLID, DDD, CQRS and some patterns like Stubs, Mocks, Factory, Repository, Unit-Of-Work. Worth a look, if you want to find out the benefits […]
Tag - GoodPractice
2015-05-08
I do not like people shoot in my foot, do you?
2015-05-08. Pascal Programming
There was some discussion about the new
TStringHelper
feature introduced in latest versions of
Delphi.
I was
told to be some kind of archaic guy, not able to see the benefit of
this.
Reducing opinions to a conservative/progressive approach - another famous 10
kinds of coders - is very reductive.
Of course, this was IMHO unfair and my point was that I have the feeling
that some decisions about the Delphi language and RTL are inadequate.
Some changes are welcome. I enjoy the introduction of generics - even if it is
was painful, and even buggy (do not use TList<T> with
managed record types in XE8!).
But some upcoming changes about the string
policy - breaking
everything just because we want to align with mainstream C# or Java habits -
are just non sense to me.
I really think that Embarcadero deciders like to shoot their own foot.
Or - certainly worse - our own feet!
I will post here some part of the discussion...
So that we may be able to share our ideas.
2015-05-03
SOLID Design Principles
2015-05-03. Pascal Programming

I've just updated the documentation part about the SOLID Design
Principles.
The former blog article
(almost 4 years old!) sounds like a bit deprecated now...
This is why I would extract here an updated version of this material.
Ensure you checked the corresponding part of the mORMot documentation, which is the updated reference, and probably the easiest to read - including links to all the other documentation.
The acronym SOLID is derived from the following OOP principles (quoted from the corresponding Wikipedia article):
- Single responsibility principle: the notion that an object should have only a single responsibility;
- Open/closed principle: the notion that "software entities ... should be open for extension, but closed for modification";
- Liskov substitution principle: the notion that "objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program” - also named as "design by contract";
- Interface segregation principle: the notion that "many client specific interfaces are better than one general purpose interface.";
- Dependency inversion principle: the notion that one should "Depend upon Abstractions. Do not depend upon concretions.". Dependency injection is one method of following this principle, which is also called Inversion Of Control (aka IoC).
If you have some programming skills, those principles are general statements you may already found out by yourself. If you start doing serious object-oriented coding, those principles are best-practice guidelines you would gain following.
They certainly help to fight the three main code weaknesses:
- Rigidity: Hard to change something because every change affects too many other parts of the system;
- Fragility: When you make a change, unexpected parts of the system break;
- Immobility: Hard to reuse in another application because it cannot be disentangled from the current application.
2015-04-12
Why Transmitting Exceptions in SOA services is not a good idea
2015-04-12. Open Source › mORMot Framework
Usually, in Delphi application (like in most high-level languages), errors
are handled via exceptions. By default, any Exception
raised on the server side, within an interface
-based service
method, will be intercepted, and transmitted as an error to the client side,
then a safe but somewhat obfuscated EInterfaceFactoryException
will be raised on the client side, containing additional information serialized
as JSON.
You may wonder why exceptions are not transmitted and raised directly on the client side, with our mORMot framework interface-based services, as if they were executed locally.
We will now detail some arguments, and patterns to be followed.
2015-03-31
ORM Master/Slave Replication
2015-03-31. Open Source › mORMot Framework

As stated during
TSQLRecord fields definition, the ORM is able to maintain a revision
number for any TSQLRecord
table, so that it the table may be
easily synchronized remotely by another TSQLRestServer
instance.
If you define a TRecordVersion
published property, the ORM core
will fill this field just before any write with a monotonically increasing
revision number, and will take care of any deletion, so that those
modifications may be replayed later on any other database.
This synchronization will work as a strict master/slave replication
scheme, as a one-way on demand refresh of a replicated table.
Each write operation on the master database on a given table may be easily
reflected on one or several slave databases, with almost no speed nor storage
size penalty.
2014-10-25
Are "Micro Services" the proper way of writing SOA?
2014-10-25. Open Source › mORMot Framework
I just wanted to share a great article by Martin Fowler, about Micro Services. IMHO such "Micro Services" are the proper way of defining a SOA project, following SOLID principles. If we follow the "Single Responsibility" principle, we will define small uncoupled services, which […]
2014-09-13
Some thoughts about "modern" pascal, generics, code and data structures
2014-09-13. Pascal Programming
In a comment of a Google+ announcement about new C# features, Stephan did react about my naive enthusiasm about SmartPascal.
Apart from the fact that he did miss the numerous ways of creating Windows executable in this dialect (I quoted at least 5 diverse ways), he was chocked by the fact that the SmartPascal syntax, in its actual idiom, does not support generics.
But are generics mandatory?
I'm not speaking about any drug identified by its chemical name rather than its
brand name (Wikipedia).
I would neither comment on the current Delphi implementation of generics (which
may appear not so polished, nor very widely used, even in the Delphi RTL/FMX,
but for TList<T> TDictionary<>
).
Just share some thoughts about what is, to my opinion - which may be wrong and
biased! - the most important part of today's programming.
2014-09-12
Legacy code, mORMot, and database sharing
2014-09-12. Open Source › mORMot Framework
It is pretty much possible that you would have to maintain and evolve a legacy project, based on an existing database, with a lot of already written SQL statements - see Legacy code and existing projects.
For instance, you would like to use mORMot for new features, and/or
add mobile or HTML clients - see Cross-Platform
clients.
In this case, the ORM advanced features - like ORM Cache or BATCH process, see
BATCH
sequences for adding/updating/deleting records - may conflict with the
legacy code, for the tables which may have to be shared.
Here are some guidelines when working on such a project.
To be exhaustive about your question, we need to consider each ORM CRUD
operation.
We may have to divide them in three kinds: read queries, insertions, and
modifications of existing data.
2014-08-16
Will WebSocket replace HTTP? Does it scale?
2014-08-16. Open Source › mORMot Framework
You certainly noticed that WebSocket is the current
trendy flavor for any modern web framework.
But does it scale? Would it replace HTTP/REST?
There is a feature
request ticket about them for mORMot, so here are some thoughts -
matter of debate, of course!
I started all this by answering a StackOverflow
question, in which the actual answers were not accurate enough, to my
opinion.
From my point of view, Websocket - as a protocol - is some kind of monster.
You start a HTTP stateless connection, then switch to WebSocket
mode which releases the TCP/IP dual-direction layer, then you may switch later
on back to HTTP...
It reminds me some kind of monstrosity, just like encapsulating everything over
HTTP, using XML messages... Just to bypass the security barriers... Just
breaking the OSI layered
model...
It reminds me the fact that our mobile phone data providers do not use
broadcasting for streaming audio and video, but regular Internet HTTP servers,
so the mobile phone data bandwidth is just wasted when a sport event occurs:
every single smart phone has its own connection to the server, and the same
video is transmitted in parallel, saturating the single communication
channel... Smart phones are not so smart, aren't they?
WebSocket sounds like a clever way to circumvent a
limitation...
But why not use a dedicated layer?
I hope HTTP 2.0 would allow
pushing information from the server, as part of the standard... and in one
decade, we probably will see WebSocket as a deprecated
technology.
You have been warned. Do not invest too much in WebSockets..
OK. Back to our existential questions...
First of all, does the WebSocket protocol scale?
Today, any modern single server is able to server millions of clients at
once.
Its HTTP server software has just to be is Event-Driven (IOCP)
oriented (we are not in the old Apache's one connection = one
thread/process equation any more).
Even the HTTP server built in Windows (http.sys - which is used in
mORMot) is IOCP oriented and very efficient (running in kernel
mode).
From this point of view, there won't be a lot of difference at scaling between
WebSocket and a regular HTTP connection. One TCP/IP connection
uses a little resource (much less than a thread), and modern OS are optimized
for handling a lot of concurrent connections: WebSocket and HTTP
are just OSI 7 application layer protocols, inheriting from this TCP/IP
specifications.
But, from experiment, I've seen two main problems with WebSocket:
- It does not support CDN;
- It has potential security issues.
2014-08-15
Background Backup of a SQLite3 Database
2014-08-15. Open Source › mORMot Framework
The primary purpose of any software Backup is to recover data after
its loss, be it by data deletion or corruption.
Data loss can be a common experience of computer users. A 2008 survey found
that 66% of respondents had lost files on their home PC, as Wikipedia quotes.
As a consequence, for any professional use of data, like in our mORMot server, a backup policy is mandatory.
We just introduced officially the SQLite3 Backup API to our low-level
SynSQLite3.pas
unit, and wrote dedicated methods to make
background backup of a running mORMot server easy and safe, without
any noticeable performance penalty.
2014-07-12
Static class variables are just global variables in disguise
2014-07-12. Pascal Programming
Cape Cod Gunny just wrote a blog article about how to replace a global variable by a static class instance.
But I had to react!
Using such static declaration is just another way of creating a global
variable.
This is just a global variable in disguise.
In fact, the generated asm will be just like a global variable!
It encapsulates the global declaration within a class name space, but it is
still IMHO a very wrong design.
I've seen so many C# or Java code which used such a pattern (there is no global
variable in those languages), and it has the same disadvantages as global
variables.
Just like the singleton
syndrome,
Code is just not re-entrant nor thread-safe.
Nightmare to debug and let evolve.
2014-06-22
Audit-trail for ORM change tracking
2014-06-22. Open Source › mORMot Framework
Since most CRUD operations are centered within the scope of our
mORMot server, we implemented in the ORM an integrated mean of
tracking changes (aka Audit Trail) of any TSQLRecord
.
In short, our ORM is transformed into a time-machine, just like the good old
DeLorean!
Keeping a track of the history of business objects is one very common need
for software modeling, and a must-have for any accurate data modeling,
like Domain-Driven Design.
By default, as expected by the OOP model, any change to an object will forget
any previous state of this object. But thanks to mORMot's exclusive
change-tracking feature, you can persist the history of your objects.
Enabling audit-trail
By default, change-tracking feature will be disabled, saving performance and
disk use.
But you can enable change tracking for any class, by calling the following
method, on server side:
aServer.TrackChanges([TSQLInvoice]);
This single line will let aServer: TSQLRestServer
monitor all
CRUD operations, and store all changes of the TSQLInvoice
table
within a TSQLRecordHistory
table.
2014-06-09
Performance comparison from Delphi 6, 7, 2007, XE4 and XE6
2014-06-09. Pascal Programming
Since there was recently some articles about performance comparison between several versions of the Delphi compiler, we had to react, and gives our personal point of view.
IMHO there won't be any definitive statement about this.
I'm always doubtful about any conclusion which may be achieved with such kind
of benchmarks.
Asking "which compiler is better?" is IMHO a wrong question.
As if there was some "compiler magic": the new compiler will be just like a new
laundry detergent - it will be cleaner and whiter...
Performance is not about marketing.
Performance is an iterative process, always a matter of circumstances,
and implementation.
Circumstances of the benchmark itself.
Each benchmark will report only information about the process it
measured.
What you compare is a limited set of features, running most of the time an
idealized and simplified pattern, which shares nothing with real-world
process.
Implementation is what gives performance.
Changing a compiler will only gives you some percents of time change.
Identifying the true bottlenecks of an application via a profiler, then
changing the implementation of the identified bottlenecks may give order of
magnitudes of speed improvement.
For instance, multi-threading abilities can be achieved by following
some simple rules.
With our huge set of regression tests, we have at hand more than 16,500,000 individual checks, covering low-level features (like numerical and text marshaling), or high-level process (like concurrent client/server and database multi-threaded process).
You will find here some benchmarks run with Delphi 6, 7, 2007, XE4 and XE6
under Win32, and XE4 and XE6 under Win64.
In short, all compilers performs more or less at the same speed.
Win64 is a
little slower than Win32, and the fastest appears to be Delphi 7, using our
enhanced and
optimized RTL.
2014-05-30
Software Design, Brook, mORMot, RAD, SOLID and OOP
2014-05-30. Open Source › mORMot Framework
We got a very instructive
discussion in our forums, with Silvio, the maintainer of the
Brook Framework.
Brook is a nice framework for writing web applications using Free
Pascal.
It comes to my mind what mORMot can offer.
We did not want to compare the features or say that one framework is better
than the other, but it appeared to me that a lot of object pascal programmers
are tied to 20th century programming model.
In fact, to embrace the potentials of mORMot, you need to switch your mind, and enhanced your RAD and OOP background, into 21th century SOLID model.
2014-05-25
New crc32c() function using optimized asm and SSE 4.2 instruction
2014-05-25. Open Source › mORMot Framework
Cyclic Redundancy Check (CRC) codes are widely used for integrity checking
of data in fields such as storage and networking.
There is an ever-increasing need for very high-speed CRC computations on
processors for end-to-end integrity checks.
We just introduced to mORMot's core unit
(SynCommons.pas
) a fast and efficient
crc32c()
function.
It will use either:
- Optimized x86 asm code, with unrolled loops;
- SSE 4.2 hardware crc32 instruction, if available.
Resulting speed is very good.
This is for sure the fastest CRC function available in Delphi.
Note that there is a version dedicated to each Win32 and Win64 platform - both
performs at the same speed!
In fact, most popular file formats and protocols (Ethernet, MPEG-2, ZIP,
RAR, 7-Zip, GZip, and PNG) use the polynomial $04C11DB7
, while
Intel's hardware implementation is based on another polynomial,
$1EDC6F41
(used in iSCSI and Btrfs).
So you would not use this new crc32c()
function to
replace the zlib's crc32()
function, but as a
convenient very fast hashing function at application level.
For instance, our TDynArray
wrapper will use it for fast items
hashing.
2014-05-18
New sample for JSON performance: mORMot vs SuperObject/XSuperObject/dwsJSON/DBXJSON
2014-05-18. Open Source › mORMot Framework
We have just added a new "25 - JSON performance" sample to benchmark JSON process, using well most known Delphi libraries...
A new fight
featuring
mORMot vs SuperObject/XSuperObject/dwsJSON/DBXJSON
On mORMot side, it covers TDocVariant
, late binding,
TSQLTable
, ORM, record access, BSON...
We tried to face several scenarios:
- parse/access/write iteration over a small JSON document,
- read of deeply nested 680 KB JSON (here mORMot is slower than SO/dwsJSON),
- read of one 180 MB JSON file (with on-the-fly adaptation to fit a record layout),
- named access to all rows and columns of a 1 MB JSON table, extracted from a SQL request (with comparison with our ORM performance).
On average and in details, mORMot is the fastest in almost all scenarios (with an amazing performance for table/ORM processing), dwsJSON performs very well (better than SuperObject), and DBXJSON is the slowest (by far, but XE6 version is faster than XE4).
2014-05-09
BREAKING CHANGE: TSQLRestServerStatic* classes are now renamed as TSQLRestStorage*
2014-05-09. Open Source › mORMot Framework

From the beginning, server-side storage tables which were not store in
a SQLite3 database were implemented via some classes
inheriting from TSQLRestServerStatic.
, which did not make much sense (but was
made for laziness years ago, if I remember well).
This TSQLRestServerStatic
was inheriting
from TSQLRestServer
Now, a new TSQLRestStorage
class, directly inheriting from
TSQLRest
, is used for per-table storage.
This huge code
refactoring results in a much cleaner design, and will enhance code
maintainability.
Documentation has been updated to reflect the changes.
Note that this won't change anything when using the framework (but the new class names): it is an implementation detail, which had to be fixed.
2014-05-07
Benchmarking Mustache libraries: native SynMustache vs mustache.js/SpiderMonkey
2014-05-07. Open Source › mORMot Framework

I just wrote a small sample program, for benchmarking Mustache libraries: native SynMustache vs mustache.js running on SpiderMonkey 24...
And the winner is ...SynMustache, which is 10 times faster, uses
almost no memory during process, and handles inlined
{{>partials}}
natively (whereas we have to handle them manually
with mustache.js)!
Who says that Garbage Collection and
immutable
strings in modern JITted runtimes are faster than "native" Delphi
applications?
Are you still preferring the "NextGen"
roadmap?
MongoDB + mORMot benchmark
2014-05-07. Open Source › mORMot Framework
Here are some benchmark charts about MongoDB integration in mORMot's ORM.
MongoDB appears as a serious competitor to SQL databases, with the potential benefit of horizontal scaling and installation/administration ease - performance is very high, and its document-based storage fits perfectly with mORMot's advanced ORM features like Shared nothing architecture (or sharding).
MongoDB + mORMot ORM = ODM
2014-05-07. Open Source › mORMot Framework
MongoDB (from "humongous") is
a cross-platform document-oriented database system, and certainly the best
known NoSQL database.
According to http://db-engines.com in April
2014, MongoDB is in 5th place of the most popular types of database
management systems, and first place for NoSQL database management
systems.
Our mORMot gives premium access to this database, featuring full
NoSQL and Object-Document Mapping (ODM) abilities to the
framework.
Integration is made at two levels:
- Direct low-level access to the MongoDB server, in the
SynMongoDB.pas
unit; - Close integration with our ORM (which becomes defacto an ODM), in
the
mORMotMongoDB.pas
unit.
MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), which matches perfectly mORMot's RESTful approach.
This second article will focus on integration of MongoDB with our ORM.
« previous entries - page 2 of 5 - next entries »