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

Hello

Hello What I expect from my Design and Architecture course is to learn all the concepts shown and understand them fully, and I'm very excited to learn the programming language, Ruby. I have different hobbies such as sports like climbing and boulder, riding bicycle, basketball. Also I love nature, I really like to go camping, grow plants, and I like animals. Other hobbies I really like is electronics, like building and learning about music synths, MIDI Controllers, and other stuff related. Music and art have been a very important part of my life, i play the guitar and other instruments, I like to paint. Here is a following list of the books that I really like: The teachings of Don Juan - Carlos Castaneda Siddharta - Herman Hesse Demian - Herman Hesse Brave New World - Aldous Huxley Batallas en el desierto - José Emilio Pacheco Dos Crímenes - Jorge Ibarguengoitia Aura - Carlos Fuentes 1984 - George Orwell Animal Farm - George Orwell Pulp - Charles Bukowski Hol...

Software Architecture

For developing a very efficient system, it has to me modulated, in a way each module has its own functions and communicates with other modules through the whole system. In order to maintain the efficiency of this system is by analyzing every module at its own way. Seeing each and every module as a black box, that receives information from other modules to perform a very complex task, the way of looking to all modules as a black box is in point of view from seeing the whole complete system. But like a microscope, by observing each module will give the information of that special feature each modules performs. By mentioning modules it also comes the term component, in a well designed system, it has to have a balance between modules and component, trying to assure low coupling and high cohesion. Depending on the systems problem complexity, it as a certain type of architecture, such as, layered architecture, pipe and filter architecture, client server architecture, component based architec...

Moon Machines EP3: Navigation Computer

It is very interesting the process behind vast projects such as everything that involve getting a Rocket to the Moon. Is the continuous testing and researching into new technologies and ways to figure and solve all problems presented in the way, what really catches my attention is the whole hard work into the modules that conforms the complete project. As shown in the documentary, it is visible that a vast team of physicists and engineers can create incredible things. The development of new technologies is a new portal of discovery, because being new, its potential is very unknown. Seeing al the progress they did , in a very analog way and the techniques of storing data are the very roots of the technology we have today. Thinking about history, I ask myself , how could it be all the possible approaches in order to complete this task/project. All the key minds that manage to give and solve, the solutions in a very short period of time, show how the improvisation is made, be...