Ir al contenido principal

Understanding the SOLID Principles

There exist some principles that make a procedure easier to perform, with this resource, it is viable to create clean products. In programming, exist something called SOLID principles that ensure quality and good performance while developing code, this acronym SOLID are the 5 widely accepted principles:

S - Single Responsibility Principle

A class should have exactly one responsibility.

O - Open/Closed Principle

A class or a function should be open for extension but closed for modification.

L - Lisvok Substitution Principle

Keep the relationship between classes and functions.

I – Interface Segregation Principle

Avoiding interfaces that overloads classes with responsibilities that this classes don’t actually need.

D – Dependency Inversion Principle

Depend upon abstractions not upon concretions.”

By understanding each one of this SOLID Principles, we could manage to create good code, and by good code I mean cleaner code that is maintainable and modular. Programming has important responsibilities while developing code for yourself and third parties. At the moment one writes code its understandable at that specific moment in time, but if this code is not well documented or the structure of the code has not a defined structure it is very difficult to manage and it is almost impossible to understand it after the code was developed.

In other hand we have obfuscated code, the art of converting code into not readable code, it is ingenious. The both counterparts exist for different purposes. I wonder if SOLID principles contests exist, because The International Obfuscated C Code Contest exists. (https://www.ioccc.org/)

Obfuscate: tr.v. -cated, -cating, -cates.
    1. To render obscure.
    1. To darken.
  1. To confuse: his emotions obfuscated his judgment.
    [LLat. obfuscare, to darken : ob(intensive) + Lat. fuscare,
    to darken < fuscus, dark.] -obfuscation n. obfuscatory adj

The goals are the following:

The IOCCC:
  • To write the most Obscure/Obfuscated C program within the rules.
  • To show the importance of programming style, in an ironic way.
  • To stress C compilers with unusual code.
  • To illustrate some of the subtleties of the C language.
  • To provide a safe forum for poor C code. :-)
for example:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdint.h>
Q unsigned d; Q char E; Q int k;
Q long u; Q size_t t; Q const char U;
#define L toupper
#define M SIZE_MAX-1
#ifndef S
#define S 38
#elif S < 38
#undef S
#define S 38
#elif S > M
#undef S
#define S M
#endif
#define l S-1
#define Y strlen
#define Z printf
#define K static
#define z do{
K E W[]="stqvvwxzwtzuvvryusuxvtrqsruxttrxvwqxq"; K E T[S]= {77,69,84,72,73,78,75,83,32,73,84,32,73,83,32,76,73,75,69,32,65,32,87,69,65,83,69,76,0} ;
K U C[]=" !\"&'(),.0123456789;?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/*NO*/
K E P[2][sizeof(T)]; K t G=0;
#ifndef N
#define N 25
#elif N < 4
#undef N
#define N 3
#elif N > M
#undef N
#define N M
#endif
/*BLOB*/
K u R=1; K d D=0; K k X(k f,k t){ return (rand()%((t)-(f)+1)+(f)); }
K E c() {return C[X(0,(k)Y(C)-1)];%> Q struct x { E G[sizeof T];
t F; } x; K x O[N];
/* Special C main() handler (encapsulation): */
#define r(main) main
r(k main(k a, E **V)) { x x; E*b;
U *A=T; k h=0,s,q=0,m=0,y=0,n=N==97,J=0; t i,j,

/* prototype for special C parser H() below */
F H(); H(<% H(for (s = 1; s < a && *V[s++]; ) H(<%
H(E *v=V[s-1]; H(if (*v!='-'||h) H(g(o) w(f) H(
while (*++v) H(switch (*v) { w(case '-') h=1; g(f)
w(case 'r') H(if ((R=strtol(v+1,&b,0)) < 1 || R > 100)/*CODING*/
<% Z("mutation rate out of range\n") ; m=1); %> else m=0; g(f)
w(case 'q') q=1; Z("quiet output\n") ; g(f) w(case 'm') J=1;
g(f) w(default) g(f) %>); H(continue))); H(w(o) H(y=1;
H(i = Y(V<:s-1]); H(if(i > l) i=l; H( strncpy(T,V[s-1:>,i)
; H(T[i]='\0')))))))); })); }); H(H(if (n&&!y) for (j=0
; j<37; ++j) T[j]=W[j]-'A'); H(for ( ; *A && strchr(C, L(*A))
; ++A)); H(if (*A) <% Z("'%c' not in keyboard \"%s\"\n", *A,C)
; return 1; })/*THIS*/); H(srand((d)time(0)); memset(&x, 0, sizeof x);
memset(O,0,sizeof O)); H(Z(/*IS*/"target '%s'\n", T); H(Z(
"mutation rate %ld\n", R)); H(if((m=(m||J||N<4)))
Z("monkey at typewriter\n"); H(for ( j=0; j<N; ++j) H(for
(i=0; i<Y(T); ++i) O[j].G[i]=c())))); H(while (!D) { H(if (++

G==M) {Z("Too many attempts, blaming the monkey Eric even if "
"he isn't typing or doesn't exist. Bye.\n"); return 1; } H(for
(j=0; j<N&&!D; ++j) { F = 0;/*NOT*/ H(for (i =0; i < Y(T); ++i)) { H(
if (L(O[j].G[i]) == L(T[i]))) ++F; } /*A*/ O[j].F=F; H(if (((D=(F==Y(T)))
||G==1)&&(!q||D)) Z("Generation %4zu\tOffspring %2zu: %s\n",G
-1,j+1,O[j] .G); })); H(if (D)break;); s=0; /*COMPACT*/ H(if (m) g(p) else H(z
s=1; H(for(i=0; i<N-1; ++i) { H(if (O<:i].F >= O[i+1].F) g(h)) x=O[
i+1:>; O[i]=O[i+1]; O[i+1]=x; s=0; w(h); }); }while(!s))); w(p
) H(strcpy(P[0],O[0].G); strcpy(P[1],O[1].G)); H(for (j=0; j<N; ++j)
{ H(for (i=0;!m&&i<Y(T); ++i) H(if ( X(0,9)<5) O[j] .
G[i]=P[0][i]); H(else O[j] . G[i]=P[1][i];)); /*BLOB*/ H(if (!
q) Z("Generation %4zu\tOffspring %2zu: %s -> " ,G,j+1,O[j].
G); H(for/*OF*/ (i=0; i<Y(T); ++i) { H(if (X(1,100) <= R || m)
O[j].G[i]=c(); })); H(if (!q) Z("%s (%s)\n",O[j].G,m
?"monkey typing" : "mutation"))); /*OCTETS*/ }); H(if (!
q) Z("**\n")); })); return 0; }

(Ferguson 2018 : prog-simple.c)


It is very hard to read….

References:

https://www.ioccc.org/index.html
https://www.ioccc.org/2018/2018.tar.bz2
http://34.212.143.74/s201911/tc3049/solid.html

Comentarios

Entradas más populares de este blog

Software Craftsmanship

Software Craftsmanship can be seen as a methodology in order to create good software, which has strong key elements that established the measures and techniques to create professional software development. It is the strong and complete philosophy to practice and helping others learn this craft, and as the Software Craftsmanship Manifesto ( http://manifesto.softwarecraftsmanship.org/ ) established some “rules” that completes this task. Such as the work on software that has to be performed to a well-crafted software, the response to change and the steadily adding value, the relationship between individuals and interactions and through the community of professionals developing software and finally customer collaboration with also productive partnership. Software Craftsmanship has a strong structure that can help the software industry in order to produce software quality, this philosophy can be applied in other topics. During the podcast with Bob Martin, or well known as “Uncle Bo...

Hidden Figures

Movies can become into an interesting resource to present certain stories and events that haven’t been known or not well known In the case of the movie, Hidden Figures , 3 main characters are being presented, which had an important role in history during the first steps of the Space Program in the United States, calculations had to be performed in order to get the right scenario for the rockets to l and. Of course dramatization is presented, it is Hollywood, but with the observation of the created cinematic context it is possible to get into the characters shoes and in a way experience their environment and actions, for that empathy grows, and the observers, see themselves involved into that movie scenario. Speaking of the movie content it is very noticeable the roles women had to endure in certain decades such as the 60’s, and in the sense of the movie, it is shown the context, scenario and roles, black women had to endure during this time. For that, the observer could had a good pe...

Microservices

Adaptability is always the answer, depending on the environment is how everything else is going to adapt. In the case of micro services, it is known by a new model for the big monolith replacement, but it is not a replacement, is just another type of architecture that had its benefits because certain features it has, but ensuring that micro services is the only path to follow, causes a problem, this architecture is proper for specific scenarios. In the industry, the massive over use of a new technology is often, for newer creations comes the extended massive usage. At this point other creations or technology can be developed to enter the competition scenario, for now, the old monolithic model is left behind, while micro services models are more used and potential growth is heading that way. As mention before, for some scenarios is viable using micro services, but in not the only alternative, it always depend on what is being worked on. It is true that segmentation and modulation can d...