{"id":1558,"date":"2024-02-02T09:55:28","date_gmt":"2024-02-02T09:55:28","guid":{"rendered":"https:\/\/cppdepend.com\/blog\/?p=1558"},"modified":"2024-02-07T10:56:49","modified_gmt":"2024-02-07T10:56:49","slug":"loki-the-best-c-library-to-learn-design-patterns-lets-modernize-it","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/loki-the-best-c-library-to-learn-design-patterns-lets-modernize-it\/","title":{"rendered":"Loki: The Premier C++ Library for Mastering Design Patterns &#8211; Join Us in Its Modernization!"},"content":{"rendered":"\n<p>Should you opt to delve into modern C++ design with a background in Object-Oriented Programming (OOP), consider starting your journey with the <a href=\"https:\/\/github.com\/dutor\/loki\">Loki library<\/a>.<\/p>\n\n\n\n<p>Loki is a C++ software library authored by Andrei Alexandrescu, developed alongside his book &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Modern_C%2B%2B_Design\">Modern C++ Design<\/a>.&#8221;<\/p>\n\n\n\n<p>In the C++ community, there&#8217;s a need for a library that provides a robust framework for design patterns. Loki stands out as a strong contender for such a role. Therefore, modernizing Loki and incorporating as many widely used design patterns as possible would greatly benefit C++ developers.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>The library extensively utilizes C++ template metaprogramming to implement several widely used constructs, including typelists, functors, singletons, smart pointers, object factories, visitors, and multimethods.<\/p>\n\n\n\n<p>Here is the motivation behind the library&#8217;s design, as explained by the author:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Loki allows users to selectively use only the features they need, with each component functioning independently of the others.<\/li>\n\n\n\n<li>Embracing the principle that &#8220;Small is beautiful,&#8221; Loki keeps its internal dependencies minimal.<\/li>\n\n\n\n<li>The library prioritizes &#8220;Multiplicative excellence,&#8221; focusing on achieving nuanced, specialized designs through the combination of concise, abstract behavior modules (policies).<\/li>\n\n\n\n<li>Loki emphasizes strategic over tactical approaches, prioritizing design and architectural components over granular details.<\/li>\n\n\n\n<li>Being a collection of design patterns rather than a monolithic design, Loki minimizes assumptions about its operating environment and offers flexibility through well-defined extension points for integrating default decisions.<\/li>\n\n\n\n<li>Loki is tailored for modern compilers, striving for code clarity within the standards of C++ without compromising for less capable compilers.<\/li>\n\n\n\n<li>Its components are designed to be compact, straightforward to comprehend and implement, effective whether used alone or in combination, and significantly beneficial for projects.<\/li>\n<\/ul>\n\n\n\n<p>Loki incorporates several valuable design patterns, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Factory<\/li>\n\n\n\n<li>Abstract Factory<\/li>\n\n\n\n<li>Visitor<\/li>\n\n\n\n<li>Singleton<\/li>\n<\/ul>\n\n\n\n<p>Numerous idioms have been utilized for this purpose:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>policy based design<\/li>\n\n\n\n<li>Multiple dispatcher<\/li>\n\n\n\n<li>Pimpl<\/li>\n\n\n\n<li>Printf&nbsp;(a typesafe printf replacement)<\/li>\n\n\n\n<li>Ordered static object creation<\/li>\n\n\n\n<li>Scope guard pointer<\/li>\n\n\n\n<li>Small Object&nbsp;Allocator<\/li>\n\n\n\n<li>Smart pointer<\/li>\n\n\n\n<li>Compile time check<\/li>\n<\/ul>\n\n\n\n<p>A detailed explanation of the idioms mentioned can be found in this insightful <a href=\"https:\/\/en.wikibooks.org\/wiki\/More_C%2B%2B_Idioms\">resource<\/a>.<\/p>\n\n\n\n<p>CoderGears has initiated a <a href=\"https:\/\/cppdepend.com\/blog\/c-contest-to-promote-the-new-c-standards\/\">contest<\/a> to update this remarkable library. The primary objective is to understand design patterns through a well-crafted library and to leverage the new features introduced in recent C++ standards as much as possible.<\/p>\n\n\n\n<p>For developers eager to undertake its modernization, the initial query to address is: <strong>What is the first step in this refactoring process?<\/strong><\/p>\n\n\n\n<p>Loki was created prior to the introduction of newer C++ standards, meaning that some of the classes originally designed and developed by the author now have equivalents in these recent standards. We can list:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SmartPointer<\/li>\n\n\n\n<li>Tuple<\/li>\n\n\n\n<li>NullType<\/li>\n\n\n\n<li>Typelist <\/li>\n\n\n\n<li>static_check<\/li>\n<\/ul>\n\n\n\n<p>Therefore, the initial step involves eliminating these classes and substituting their usage throughout the remaining source code.<\/p>\n\n\n\n<p>In the near future, we plan to release a series of posts about this incredible library to assist developers in its modernization.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Should you opt to delve into modern C++ design with a background in Object-Oriented Programming (OOP), consider starting your journey with the Loki library. Loki is a C++ software library authored by Andrei Alexandrescu, developed alongside his book &#8220;Modern C++ Design.&#8221; In the C++ community, there&#8217;s a need for a library that provides a robust &hellip; <a href=\"https:\/\/cppdepend.com\/blog\/loki-the-best-c-library-to-learn-design-patterns-lets-modernize-it\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Loki: The Premier C++ Library for Mastering Design Patterns &#8211; Join Us in Its Modernization!&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[231,223,220,238,241,236,242,239,228,219,222,240,233,225,234,232,237,229,226,86,224,221,227,235,230],"class_list":["post-1558","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-abstract-factory","tag-andrei-alexandrescu","tag-c-design-patterns","tag-codergears-contest","tag-community-driven-development","tag-compile-time-checks","tag-continuous-integration-testing","tag-design-pattern-implementation","tag-factory-pattern","tag-loki-library","tag-modern-c-standards","tag-modern-compiler-compatibility","tag-multiple-dispatch","tag-object-oriented-programming-oop","tag-pimpl-idiom","tag-policy-based-design","tag-refactoring-c","tag-singleton-pattern","tag-smart-pointers","tag-software-development","tag-software-modernization","tag-template-metaprogramming","tag-typelists","tag-typesafe-printf","tag-visitor-pattern"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/comments?post=1558"}],"version-history":[{"count":6,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1558\/revisions"}],"predecessor-version":[{"id":1567,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1558\/revisions\/1567"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=1558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=1558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=1558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}