Précédent   Forum du club des développeurs et IT Pro > Le club des professionnels en informatique > La taverne du Club : Humour et divers > Humour Informatique
Humour Informatique Le Forum des meilleures anecdotes en humour informatique
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 30/01/2012, 23h01   #101
Anarchy64
Candidat au titre de Membre du Club
 
Homme LoveMetal
Inscription : janvier 2012
Messages : 15
Détails du profil
Informations personnelles :
Nom : Homme LoveMetal
Localisation : France

Informations forums :
Inscription : janvier 2012
Messages : 15
Points : 12
Points : 12
Citation:
Envoyé par Bluedeep Voir le message
Désolé, mais on arrive même pas à comprendre de quoi il est question.
Pour la clarté du code, je m'étais pas relu et c'est effectivement assez difficile à comprendre, n'ayant fourni aucune explications (j'aurais peut-être pas dû poster à 3 heures du mat' aussi) et je m'en excuse; je vais refaire un paragraphe explicatif.

Citation:
Envoyé par Bluedeep Voir le message
et je n'ai pas la moindre idée de ce que peut bien être un "demomaker qui [fait] des miracles avec un pc puissant et 64 ko". Je suppose ne pas être le seul.
Moui bon faut pas pousser non plus, tapes demomaker sur google tu as des dizaines de réponses pertinentes.
Voici quand même un lien qui résume assez bien la demoscene (le concept) et le lien d'une demo 64k très impressionante.


Reprenons ce code et tout ce qui va avec...

Déjà la fonction inline : c'est une directive du langage C++ que l'on peut placer devant une fonction. Exemple :

Code Sans inline :
1
2
3
4
5
6
7
8
type fonction(parametres) {
instructions
}

int main(void) {
instructions
type fonction(parametres); /*Appel de la fonction*/
}

Code Avec inline :
1
2
3
4
5
6
7
8
inline type fonction(parametres) {
instructions
}

int main(void) {
instructions
inline type fonction(parametres); /*Appel de la fonction*/
}

Quel est son but ? Et bien dès que le compilateur convertira le code source en binaire, au lieu de compiler la fonction dans un coin de l'exécutable et de faire un renvoi vers cette fonction à chaque fois qu'elle est appelée (comme ça se passerait dans le premier code); la fonction sera recompilée à chaque fois à l'endroit où elle est appelée.
Si vous n'avez toujours pas compris, allez voir ici, le gars est assurément beaucoup plus pédagogue que moi .

Quel est son utilité ? Pour un programme de base, il n'y en a pas vraiment, mais pour les demomakers, il y en a une de taille.
Prenons une des bases de la demoscene : faire le plus de choses en le moins d'espace possible. Et bien avec cette fonction, on pourrait croire que l'exécutable prendrait plus de place étant donné que la fonction est recompilée à chaque fois qu'elle est appelée; le truc c'est que les demomakers utilisent des compresseurs très puissants tels que kkrunchy, et si la fonction est répétée plusieurs fois, alors autant de fois kkrunchy la compressera.

Comprenez-vous déjà un peu mieux ?
Revoici le shéma du code écrit plus lisiblement :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* contenu du fichier header.h : */
inline type fonction1(parametres) {
/*Trois instructions*/
}

inline type fonction2(parametres) {
/*Trois instructions*/
}

/* contenu du fichier header2.h : */
inline type fonction3(parametres) {
/*Trois instructions*/
}

/* contenu du fichier main.c : */
 type fonction2(parametres);
 debut:
 type fonction1(parametres);
 if ( test != fonction3(parametres) )
    goto debut;
 fonction2(parametres)
 for ( i = fonction1((fonction3(parametres)); i <= j | i != fonction2(fonction1(parametres)); i++ ) {
 fonction2(parametres)
/* Et ça continue tout le long du code */
 }
Anarchy64 est déconnecté   Envoyer un message privé Réponse avec citation 61
Vieux 19/04/2012, 14h29   #102
Code62
Membre émérite
 
Homme Frédéric Bruyère
Chef de projet NTIC
Inscription : novembre 2008
Messages : 135
Détails du profil
Informations personnelles :
Nom : Homme Frédéric Bruyère
Âge : 30
Localisation : Belgique

Informations professionnelles :
Activité : Chef de projet NTIC
Secteur : Conseil

Informations forums :
Inscription : novembre 2008
Messages : 135
Points : 940
Points : 940
Code php :
1
2
3
4
5
6
7
8
9
10
11
<?php
// (...)
$old_pre =  (string)"11";
$old_pre_vers = (string)"2";
$old_post =  (string)"51";
$old_post_vers = (string)"0";
 
$new_1 =  (string)"52";
$new_1_vers = (string)"0";
$new_2 =  (string)"53";
$new_2_vers = (string)"0";
casting de string en strings, au cas où l'interpréteur php déciderait d'ignorer les quotes ?

et plus bas:
Code php :
1
2
	$kexam=$old_pre;
	$exam=$eval['data']["$kexam"];
...ok.
__________________
"Le premier venu peut écrire du code qu'un ordinateur peut comprendre. Les bons programmeurs écrivent du code que les humains peuvent comprendre."
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
(Martin Fowler)
Code62 est déconnecté   Envoyer un message privé Réponse avec citation 30
Vieux 19/04/2012, 14h44   #103
MiaowZedong
Membre Expert
 
Avatar de MiaowZedong
 
Grand Timonier des Chats
Inscription : décembre 2011
Messages : 610
Détails du profil
Informations professionnelles :
Activité : Grand Timonier des Chats

Informations forums :
Inscription : décembre 2011
Messages : 610
Points : 2 278
Points : 2 278
Citation:
Envoyé par Code62 Voir le message
Code php :
1
2
3
4
5
6
7
8
9
10
11
<?php
// (...)
$old_pre =  (string)"11";
$old_pre_vers = (string)"2";
$old_post =  (string)"51";
$old_post_vers = (string)"0";
 
$new_1 =  (string)"52";
$new_1_vers = (string)"0";
$new_2 =  (string)"53";
$new_2_vers = (string)"0";
casting de string en strings, au cas où l'interpréteur php déciderait d'ignorer les quotes ?
Tu n'y es pas; dans un futur standard PHP, les quotes pourraient avoir une autre signification: par exemple dénoter un int. Là le code de ton collègue resterait valable!

En plus, comme chacun le sait, l'optimisation prématurée est la source de tous les maux: éviter le cast sur une variable de type connu serait une optimisation, donc ton collègue a fait des casts inutiles pour s'épargner les maux d'une optimisation prématurée
MiaowZedong est déconnecté   Envoyer un message privé Réponse avec citation 101
Vieux 19/04/2012, 15h43   #104
Bousk
Modérateur
 
Homme Cyrille
Network programmer
Inscription : juin 2010
Messages : 1 546
Détails du profil
Informations personnelles :
Nom : Homme Cyrille
Âge : 25
Localisation : France

Informations professionnelles :
Activité : Network programmer

Informations forums :
Inscription : juin 2010
Messages : 1 546
Points : 4 084
Points : 4 084
Une fonction pour supprimer d'un vector selon un paramètre :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
//Vector<MonObjet*> vec;
int nb = vec.GetSize();
for (int i = 0; i < nb; ++i)
{
  if (vec[i] == toDelete)
  {
    delete vec[i];
    vec.Erase(i);
    i = i-1;
    nb = vec.GetSize();
  }
}
Bousk est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/11/2012, 15h34   #105
Loceka
Expert Confirmé
 
Avatar de Loceka
 
Tlouye Ci
Inscription : mars 2004
Messages : 1 804
Détails du profil
Informations personnelles :
Nom : Tlouye Ci

Informations forums :
Inscription : mars 2004
Messages : 1 804
Points : 2 929
Points : 2 929
Un code sur lequel je viens de tomber dans un fichier XSL (pour info, c'est le seul template présent dans le fichier) :

Code XML :
1
2
3
4
5
6
7
8
9
10
11
12
13
<xsl:template name="get-revdate">
	<xsl:param name="date"/>
	<xsl:variable name="year" select="substring($date,1,4)"/>
	<xsl:variable name="mois" select="substring($date,5,2)"/>
	<xsl:variable name="jour" select="substring($date,7,2)"/>
	<fo:inline>
		<ext:rev-value-of select="$jour"/>
		<ext:rev-text>/</ext:rev-text>
		<ext:rev-value-of select="$mois"/>
		<ext:rev-text>/</ext:rev-text>
		<ext:rev-value-of select="$year"/>
	</fo:inline>
</xsl:template>

Apparement le développeur devait être indécis sur la langue à utiliser pour les variables...
Loceka est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/02/2013, 16h32   #106
a.rami
Invité de passage
 
Homme rami
Développeur Java
Inscription : novembre 2011
Messages : 1
Détails du profil
Informations personnelles :
Nom : Homme rami
Localisation : Maroc

Informations professionnelles :
Activité : Développeur Java
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : novembre 2011
Messages : 1
Points : 3
Points : 3
Envoyer un message via Skype™ à a.rami
dans le code d'un collegue :

Code :
 select id_coli into v_exsist_init from colis where id_coli = null; :massacre:
a.rami est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 19/02/2013, 11h21   #107
r0d
Expert Confirmé Sénior
 
Inscription : août 2004
Messages : 3 668
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations forums :
Inscription : août 2004
Messages : 3 668
Points : 4 429
Points : 4 429
Je suis tombé sur une fonction pas mal l'autre jour:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
template <typename TypeDataSource>
void DetermineDiscreteAndContinuousOrdinalVariableDistributions(TypeDataSource& dataSource)
{
	size_t memconsumption(GetMemoryConsumptionBinning());
 
 
	// go through all continuous variables
	size_t indexEnd(0);
	while (indexEnd < universeDescription.GetDataDescription().GetCollectionContinuousOrdinal().size())
	{
		ComputeAndShowMemoryInUse();
 
		typedef std::vector<DataDescription::TypeCollectionDescriptionContinuousOrdinalVariable::key_type> TypeCollectionVariablesToTreat;
 
		// QuantileComputationHelper class to encapsulate some variables and functionality for intelligent quantile computation
		// bpsm: encapulation of auxilary variables into structure.
		// some of them are free'd here, others aren't.
		class QuantileComputationHelper
		{
		public:
 
			QuantileComputationHelper(size_t numberOfRequiredMemorySlots, const TypeCollectionVariablesToTreat& collectionDescriptionContinuousOrdinalVariable)
			: quantileMem((float**)malloc(collectionDescriptionContinuousOrdinalVariable.size() * sizeof(float*)))
			, indexQuantile((int*)malloc(collectionDescriptionContinuousOrdinalVariable.size() * sizeof(int)))
			{
				float* tmpq((float*)malloc(numberOfRequiredMemorySlots * sizeof(float)));
 
				if ((tmpq==NULL) || (quantileMem==NULL) || (indexQuantile==NULL))
				{
					std::cout << "out of memory: cannot compute quantiles." << std::endl;
 
					exit(Application::EXIT_ERROR_GENERAL);
				}
 
				memset(tmpq, 0, numberOfRequiredMemorySlots * sizeof(float));
				memset(indexQuantile, 0, collectionDescriptionContinuousOrdinalVariable.size() * sizeof(int));
 
				int i(0);
				for (TypeCollectionVariablesToTreat::const_iterator it = collectionDescriptionContinuousOrdinalVariable.begin(); it != collectionDescriptionContinuousOrdinalVariable.end(); ++it) 
				{ 
					quantileMem[i] = tmpq + 1;
					tmpq += (*it)->nNonNullInR + 2; // bpsm: +2 for sentinels of intelligent quantiles algorithm
					indexQuantile[i] = 0;
 
					++i;
				}
			}
 
			~QuantileComputationHelper()
			{
				free(quantileMem[0]-1);
				free(quantileMem);
				free(indexQuantile);
			}
 
 
 
			void SetValue(float value, size_t variable)
			{
				quantileMem[variable][indexQuantile[variable]] = value;
				++(indexQuantile[variable]);
			}
 
			void FinalizeSetValue()
			{
				free(indexQuantile);
				indexQuantile = NULL;
			}
 
 
			float* GetQuantilesMemorySlot(size_t variable)
			{
				return quantileMem[variable];
			}
 
 
		private:
 
 
			float** quantileMem;
			int* indexQuantile;
		};
 
 
 
 
		size_t indexBegin(indexEnd);
 
		// Check memory consumption to define how many of the next variables we can read in simultaneously
		size_t neededSlots(0);
		while
		(
			  (indexEnd < universeDescription.GetDataDescription().GetCollectionContinuousOrdinal().size())
		   && (neededSlots < memconsumption)
		)
		{
			DataDescription::TypeCollectionDescriptionContinuousOrdinalVariable::const_iterator it(universeDescription.GetDataDescription().GetCollectionContinuousOrdinal().begin());
			std::advance(it, indexEnd);
 
			neededSlots += (*it)->nNonNullInR + 2; // bpsm: +2 for sentinels of intelligent quantiles algorithm
 
			++indexEnd;
		}
 
 
		// collect the variables that need to be treated this time around
		TypeCollectionVariablesToTreat variablesToTreat;
 
		for (size_t i = indexBegin; i < indexEnd; ++i)
		{
			DataDescription::TypeCollectionDescriptionContinuousOrdinalVariable::const_iterator it(universeDescription.GetDataDescription().GetCollectionContinuousOrdinal().begin());
			std::advance(it, i);
 
			variablesToTreat.push_back(*it);
		}
 
 
		QuantileComputationHelper quantileComputationHelper(neededSlots, variablesToTreat);
 
 
		// Go through the data source to load values for quantile computation
		dataSource.Restart();
		while (dataSource.GetNext())
		{
			for (size_t i = 0; i < variablesToTreat.size(); ++i)
			{
				bool isEmpty(false);
				double dv = Utility::TextParsing::ReadDoubleFromString(dataSource.GetValue(variablesToTreat[i]->lineIndex), &isEmpty);
 
				// detection of unknown values:
				if (isEmpty || variablesToTreat[i]->isEmptyValue(dv))
					continue;
 
				quantileComputationHelper.SetValue(float(dv), i);
			}
		}
 
		quantileComputationHelper.FinalizeSetValue();
 
 
		std::cout << std::endl;
 
 
		// Parellel processing: sorting and quantile computation
		{
			std::cout << "  Sorting and optimal cut computation..." << std::endl;
 
			fflush(0);
 
			float progress(0);
 
#ifdef _DEBUG
			// bpsm: in debug there's a complaint of the compiler:
			// error C3052: '__LINE__Var' : variable doesn't appear in a data-sharing clause under a default(none) clause
			#pragma omp parallel for shared(variablesToTreat, progress, indexBegin, indexEnd, quantileComputationHelper, std::cout)
#else
			// Fred: removed default(none) 
			#pragma omp parallel for shared(variablesToTreat, progress, indexBegin, indexEnd, quantileComputationHelper, std::cout)
#endif
			for (int currentVariable = 0; currentVariable < static_cast<int>(variablesToTreat.size()); ++currentVariable)
			{
				progress = std::max(progress, ((float)((currentVariable+indexBegin+1)*100.0))/static_cast<int>(universeDescription.GetDataDescription().GetCollectionContinuousOrdinal().size()));
 
				printf(" %6.2f %%\r", progress);
				fflush(0);
 
#ifdef _DEBUG
 
				if (currentVariable == static_cast<int>(indexBegin))
				{
					std::cout << "number of threads used for quantile computation: " << omp_get_num_threads() << std::endl;
				}
 
#endif
 
				float* pQuantilesMemorySlot(quantileComputationHelper.GetQuantilesMemorySlot(currentVariable));
 
 
 
 
				int len = variablesToTreat[currentVariable]->nNonNullInR;
				std::sort(pQuantilesMemorySlot, pQuantilesMemorySlot + len);
 
 
 
				float s=0;
				for (int j=0; j<len; ++j)
					s += pQuantilesMemorySlot[j];
 
				variablesToTreat[currentVariable]->mean = s/((double)len);
				//variablesToTreat[currentVariable]->stdDev = VariableDistribution::stdDeviation(variablesToTreat[currentVariable]->mean, len, pQuantilesMemorySlot);
				variablesToTreat[currentVariable]->stdDev = Utility::Math::stdDeviation(variablesToTreat[currentVariable]->mean, len, pQuantilesMemorySlot);
				variablesToTreat[currentVariable]->median = pQuantilesMemorySlot[len/2];
 
				int k = variablesToTreat[currentVariable]->nDiffVal = variablesToTreat[currentVariable]->countModalities(0, len, pQuantilesMemorySlot);
 
				if (k < variablesToTreat[currentVariable]->nMaxQuantile)
				{
					// not enough different modalities: fall back to nominal with order case 
					// must compute 'name' (=val) of each modality
					variablesToTreat[currentVariable]->nModality = k+1; // +1 because of missing
					variablesToTreat[currentVariable]->nQuantile = k;
					variablesToTreat[currentVariable]->jumpsv = NULL;
 
					variablesToTreat[currentVariable]->sizeOfMemoryReferredToByPointers = k*sizeof(double)+k*sizeof(float)+(k+1)*sizeof(int);
 
					double* tmpq2 = (double*)malloc(k*sizeof(double)+k*sizeof(float)+(k+1)*sizeof(int));
					variablesToTreat[currentVariable]->qv = tmpq2;
 
					float* tmpq3 = (float*)(tmpq2+k);
					variablesToTreat[currentVariable]->qp = tmpq3;
 
					int* nOcc = (int*)(variablesToTreat[currentVariable]->qp+k); // +1 because of missing
					variablesToTreat[currentVariable]->nOcc=nOcc;
 
					*nOcc = universeDescription.GetNumberOfLines()-len; // empty/missing
 
					double dvold = (*pQuantilesMemorySlot) - (float)1e30;
					for (int j=0; j<len; ++j)
					{
						double dvnew = (double)*(pQuantilesMemorySlot++);
						if (dvnew == dvold)
							++(*nOcc);
						else
						{
							*(tmpq2++) = dvnew;
							dvold = dvnew;
							++nOcc;
							*nOcc = 1;
							*(tmpq3++) = ((float)(j+1))/len;
						}
					}
 
					universeDescription.SetNumberOfModalitiesMaximal(std::max(universeDescription.GetNumberOfModalitiesMaximal(), variablesToTreat[currentVariable]->nModality));
				}
				else
				{
					int nQuantMod = variablesToTreat[currentVariable]->nModMax;
					variablesToTreat[currentVariable]->qv = (double*)malloc((2*UniverseDescriptionInfo::MAXIMALNUMBEROFQUANTILES+3*nQuantMod)*sizeof(double)+(nQuantMod+1)*sizeof(int));  // +1 because of missing
					variablesToTreat[currentVariable]->modv = variablesToTreat[currentVariable]->qv + UniverseDescriptionInfo::MAXIMALNUMBEROFQUANTILES;
					variablesToTreat[currentVariable]->modv2 = variablesToTreat[currentVariable]->modv + nQuantMod;//NQUANTILESMOD;
					variablesToTreat[currentVariable]->qp = (float*)(variablesToTreat[currentVariable]->modv2 + nQuantMod);
					variablesToTreat[currentVariable]->modp = variablesToTreat[currentVariable]->qp + UniverseDescriptionInfo::MAXIMALNUMBEROFQUANTILES;//NQUANTILESMOD;
					variablesToTreat[currentVariable]->nOcc = (int*)(variablesToTreat[currentVariable]->modp + nQuantMod);//NQUANTILESMOD);
					variablesToTreat[currentVariable]->jumpsv = NULL;
					variablesToTreat[currentVariable]->nOcc[0] = universeDescription.GetNumberOfLines()-len; // empty/missing
 
 
					variablesToTreat[currentVariable]->sizeOfMemoryReferredToByPointers = (2*UniverseDescriptionInfo::MAXIMALNUMBEROFQUANTILES+3*nQuantMod)*sizeof(double)+(nQuantMod+1)*sizeof(int);
 
					size_t tSize(std::max((int)(2*nQuantMod*sizeof(double)), (int)(2*(std::max(UniverseDescriptionInfo::MAXIMALNUMBEROFQUANTILES,nQuantMod)+1)*sizeof(int))));
					int* t = (int*)malloc(tSize);
					memset(t, 0, tSize);
 
					if (!t)
					{
						std::cout << "unable to allocate memory to store quantiles." << std::endl;
						exit(Application::EXIT_ERROR_GENERAL);
					}
 
					_CrtCheckMemory();
 
					int nCutForcedSz = 0;
 
					cutForced* c = cutArray(UniverseDescriptionInfo::MAXIMALNUMBEROFQUANTILES, &nCutForcedSz, pQuantilesMemorySlot, len, variablesToTreat[currentVariable]->specCut);
 
					_CrtCheckMemory();
 
					k = getCutIdx(c, nCutForcedSz, len, t, UniverseDescriptionInfo::MAXIMALNUMBEROFQUANTILES, pQuantilesMemorySlot, -1) + 1; // +1 bcs nQuantiles=nCuts+1
 
					_CrtCheckMemory();
 
					assert(k <= UniverseDescriptionInfo::MAXIMALNUMBEROFQUANTILES);
 
					//QuantileGraph::Plot(variablesToTreat[currentVariable]->name, pQuantilesMemorySlot, len, t, k-1, c, -1);
 
					free(c);
					variablesToTreat[currentVariable]->nQuantile=k;
					for (int j=0; j<k; ++j) 
					{ 
						variablesToTreat[currentVariable]->qv[j] = pQuantilesMemorySlot[t[j]];
						variablesToTreat[currentVariable]->qp[j] = ((float)t[j]) / len;
					}
 
					variablesToTreat[currentVariable]->qv[k-1] += (float)1e-10; // to prevent rounding errors
 
					int minBinSz;
					if (variablesToTreat[currentVariable]->minModSz < 1)
						minBinSz = (int)(universeDescription.GetNumberOfLines() * variablesToTreat[currentVariable]->minModSz);
					else
						minBinSz = (int)variablesToTreat[currentVariable]->minModSz;
 
					minBinSz = std::max(10,minBinSz);
 
					c = cutArray(nQuantMod ,&nCutForcedSz, pQuantilesMemorySlot, len, variablesToTreat[currentVariable]->specCut, minBinSz);
 
					_CrtCheckMemory();
 
					k = getJumpVal(c, nCutForcedSz, len, (float*)t, nQuantMod, pQuantilesMemorySlot, -1) + 1;
 
					_CrtCheckMemory();
 
					variablesToTreat[currentVariable]->nJumps = k;
					if (k>1)
					{
						((float*)t)[k-1] += (float)1e-10; // to prevent rounding errors
						variablesToTreat[currentVariable]->jumpsv = (double*)malloc(k*sizeof(double));
						variablesToTreat[currentVariable]->sizeOfMemoryReferredToByPointers = k*sizeof(double);
						for (int j=0; j<k; ++j)
							variablesToTreat[currentVariable]->jumpsv[j] = (double)((float*)t)[j];
					}
 
					k = getCutIdx(c, nCutForcedSz, len, t, nQuantMod, pQuantilesMemorySlot, -1) + 1; // +1 bcs nQuantiles=nCuts+1
 
					_CrtCheckMemory();
 
 
					if (variablesToTreat[currentVariable]->aGraph)
						QuantileGraph::Plot(variablesToTreat[currentVariable]->name, pQuantilesMemorySlot, len, t, k-1, c, -1, minBinSz);
 
					free(c);
					_CrtCheckMemory();
 
 
					variablesToTreat[currentVariable]->nModality = k+1; // +1 because of missing
					universeDescription.SetNumberOfModalitiesMaximal(std::max(universeDescription.GetNumberOfModalitiesMaximal(), variablesToTreat[currentVariable]->nModality));
					for (int j=0; j<k; ++j) 
					{ 
						variablesToTreat[currentVariable]->modv[j] = (double)pQuantilesMemorySlot[t[j]]; 
						variablesToTreat[currentVariable]->modp[j] = ((float)t[j]) / len;
						variablesToTreat[currentVariable]->modv2[j] = (double)pQuantilesMemorySlot[t[j]+1];
					}
 
					variablesToTreat[currentVariable]->modv[k-1] += (double)1e-10; // to prevent rounding errors
					variablesToTreat[currentVariable]->modv2[k-1] += (double)1e-10; // to prevent rounding errors
					variablesToTreat[currentVariable]->nOcc[1] = t[0]+1;
 
					for (int j=1; j<k; ++j)
					{
						variablesToTreat[currentVariable]->nOcc[j+1] = t[j] - t[j-1];
					}
 
					free(t);
					_CrtCheckMemory();
				}
			}
 
			std::cout << std::endl;
		}
	}
 
	// Separate discretized continuous variables from other numerical variables
	universeDescription.GetDataDescription().SplitContinuousAndDiscretizedVariables();
}
Hé oui, ce n'est qu'une seule fonction.
Et je dois maintenir ça...
r0d est déconnecté   Envoyer un message privé Réponse avec citation 30
Vieux 19/02/2013, 13h05   #108
shadowmoon
Membre Expert
 
Avatar de shadowmoon
 
Homme thomas
Ingénieur développement logiciels
Inscription : mai 2005
Messages : 807
Détails du profil
Informations personnelles :
Nom : Homme thomas
Âge : 31
Localisation : France, Rhône (Rhône Alpes)

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : Industrie

Informations forums :
Inscription : mai 2005
Messages : 807
Points : 1 261
Points : 1 261
Citation:
Envoyé par r0d Voir le message
Hé oui, ce n'est qu'une seule fonction.
Et je dois maintenir ça...
Ça va, j'ai connu pire, une application C#, d'environ 5 000 lignes, où TOUT était dans le main, sans commentaires et avec des noms de fonctions et de variables du style var1, var2, i,j,k ...


En survolant vite fait ton exemple de code, il me semble que les commentaires ont l'air utiles et les variables à peu prés correctement nommées.

Après, il faut que je le lise plus attentivement pour voir s'il aussi compréhensible qu'il le parait.
__________________
il n'y a jamais eu qu'un seul chrétien et il est mort sur la croix Friedrich Nietzsche

L'homme est un apprenti, la douleur est son maitre Alfred de Musset

pour les problèmes de partition, les derniers recours sont testdisk et le formatage bas-niveau

pour faire le menage efficacement sur vos DD, utilisez Ccleaner
shadowmoon est déconnecté   Envoyer un message privé Réponse avec citation 41
Vieux 19/02/2013, 14h44   #109
r0d
Expert Confirmé Sénior
 
Inscription : août 2004
Messages : 3 668
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations forums :
Inscription : août 2004
Messages : 3 668
Points : 4 429
Points : 4 429
C'est vrai qu'il y a pire, mais tout de même:
- une fonction template de plus de 300 lignes (l'analyseur syntaxique n'y a pas survécu! Et SRP dans tout ça? Et va implémenter des test unitaires là-dessus...)
- des classes déclarées et implémentées au sein de la fonction (dans une boucle, qui plus est)
- un mélange de C et de C++ (du malloc, du free, du template, du printf, du cout...)
- openMP utilisé sauvagement en plein milieu (ce qui rend illusoire toute tentative de profiling)
- des pointeurs dans tous les sens avec des déréférencements qui peuvent péter n'importe quand.
r0d est déconnecté   Envoyer un message privé Réponse avec citation 30
Vieux 28/02/2013, 16h00   #110
ch0c4
Futur Membre du Club
 
Homme
Développeur Web
Inscription : février 2012
Messages : 21
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Développeur Web
Secteur : Communication - Médias

Informations forums :
Inscription : février 2012
Messages : 21
Points : 19
Points : 19
Bonjour, vu aujourd'hui sur un code daté de 2010
Code :
1
2
3
4
5
6
7
8
9
10
function ecriture($fichier,$chaine)
{
	if ($chaine != "") {
		if (file_exists($fichier)) chmod ($fichier,0777);
		$fd=fopen($fichier,"w") or die('PBM !!!!!');
		$fout=fwrite($fd,$chaine);
		fclose($fd);
	}
}
Si on peut pas l'ouvrir il y'a vraiment un problème !!!!! ^^
ch0c4 est déconnecté   Envoyer un message privé Réponse avec citation 06
Vieux 28/02/2013, 16h11   #111
Bluedeep
Expert Confirmé Sénior
 
Homme François
Chef de projet NTIC
Inscription : janvier 2007
Messages : 6 547
Détails du profil
Informations personnelles :
Nom : Homme François
Âge : 52
Localisation : France

Informations professionnelles :
Activité : Chef de projet NTIC

Informations forums :
Inscription : janvier 2007
Messages : 6 547
Points : 13 916
Points : 13 916
Citation:
Envoyé par ch0c4 Voir le message
Si on peut pas l'ouvrir il y'a vraiment un problème !!!!! ^^
Pas compris ...
__________________

Je ne réponds pas aux questions techniques par MP ! Le forum est là pour ça...


Une réponse vous a aidé ? utiliser le bouton

"L’ennui dans ce monde, c’est que les idiots sont sûrs d’eux et les gens sensés pleins de doutes". B. Russel
Bluedeep est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 01/03/2013, 08h09   #112
transgohan
Expert Confirmé
 
Avatar de transgohan
 
Homme Baptiste ROUSSEL
Développeur Temps réel Embarqué
Inscription : janvier 2011
Messages : 1 295
Détails du profil
Informations personnelles :
Nom : Homme Baptiste ROUSSEL
Localisation : France, Territoire de Belfort (Franche Comté)

Informations professionnelles :
Activité : Développeur Temps réel Embarqué

Informations forums :
Inscription : janvier 2011
Messages : 1 295
Points : 2 856
Points : 2 856
Citation:
Envoyé par ch0c4 Voir le message
Si on peut pas l'ouvrir il y'a vraiment un problème !!!!! ^^
C'est tout à fait possible, il suffit que le programme qui exécute ces lignes n'ai pas l'autorisation de faire un chmod sur ce fichier et qu'il n'ai pas non plus l'autorisation de lecture/écriture dessus pour qu'on rentre dans le die().
__________________
Toujours se souvenir que la majorité des ennuis viennent de l'espace occupé entre la chaise et l'écran de l'ordinateur.
transgohan est déconnecté   Envoyer un message privé Réponse avec citation 11
Vieux 02/03/2013, 09h16   #113
zecreator
Membre actif
 
Inscription : janvier 2006
Messages : 243
Détails du profil
Informations forums :
Inscription : janvier 2006
Messages : 243
Points : 180
Points : 180
Envoyer un message via AIM à zecreator Envoyer un message via MSN à zecreator Envoyer un message via Yahoo à zecreator
10 GOTO 10
__________________
"En démocratie, c'est le peuple qui choisit ses dictateurs." (Patrick Sébastien)
zecreator est déconnecté   Envoyer un message privé Réponse avec citation 20
Vieux 02/03/2013, 11h55   #114
fcharton
Membre Expert
 
Homme
Inscription : avril 2009
Messages : 1 359
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 48
Localisation : France

Informations forums :
Inscription : avril 2009
Messages : 1 359
Points : 2 044
Points : 2 044
Citation:
Envoyé par shadowmoon Voir le message
Ça va, j'ai connu pire, une application C#, d'environ 5 000 lignes, où TOUT était dans le main, sans commentaires et avec des noms de fonctions et de variables du style var1, var2, i,j,k ...
Sans avoir les 5000 lignes dans le main, voici le code du premier interpréteur J (J est un descendant d'APL). C'est du C écrit en 1989, par Arthur Whitney (aujourd'hui patron de Kx systems)

C'est un peu déstabilisant pour un moderne, à cause de l'absence de blancs et de retours chariot (je suppose qu'on ne mesurait pas encore la productivité en lignes de code), et parce qu'on n'a pas de fonctions en anglais de cuisine dont les noms sont plus long que le code qu'elles contiennent. Mais c'est extrèmement bien fait.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
typedef char C;typedef long I;
typedef struct a{I t,r,d[3],p[2];}*A;
#define P printf
#define R return
#define V1(f) A f(w)A w;
#define V2(f) A f(a,w)A a,w;
#define DO(n,x) {I i=0,_n=(n);for(;i<_n;++i){x;}}
I *ma(n){R(I*)malloc(n*4);}mv(d,s,n)I *d,*s;{DO(n,d[i]=s[i]);}
tr(r,d)I *d;{I z=1;DO(r,z=z*d[i]);R z;}
A ga(t,r,d)I *d;{A z=(A)ma(5+tr(r,d));z->t=t,z->r=r,mv(z->d,d,r);
 R z;}
V1(iota){I n=*w->p;A z=ga(0,1,&n);DO(n,z->p[i]=i);R z;}
V2(plus){I r=w->r,*d=w->d,n=tr(r,d);A z=ga(0,r,d);
 DO(n,z->p[i]=a->p[i]+w->p[i]);R z;}
V2(from){I r=w->r-1,*d=w->d+1,n=tr(r,d);
 A z=ga(w->t,r,d);mv(z->p,w->p+(n**a->p),n);R z;}
V1(box){A z=ga(1,0,0);*z->p=(I)w;R z;}
V2(cat){I an=tr(a->r,a->d),wn=tr(w->r,w->d),n=an+wn;
 A z=ga(w->t,1,&n);mv(z->p,a->p,an);mv(z->p+an,w->p,wn);R z;}
V2(find){}
V2(rsh){I r=a->r?*a->d:1,n=tr(r,a->p),wn=tr(w->r,w->d);
 A z=ga(w->t,r,a->p);mv(z->p,w->p,wn=n>wn?wn:n);
 if(n-=wn)mv(z->p+wn,z->p,n);R z;}
V1(sha){A z=ga(0,1,&w->r);mv(z->p,w->d,w->r);R z;}
V1(id){R w;}V1(size){A z=ga(0,0,0);*z->p=w->r?*w->d:1;R z;}
pi(i){P("%d ",i);}nl(){P("\n");}
pr(w)A w;{I r=w->r,*d=w->d,n=tr(r,d);DO(r,pi(d[i]));nl();
 if(w->t)DO(n,P("< ");pr(w->p[i]))else DO(n,pi(w->p[i]));nl();}

C vt[]="+{~<#,";
A(*vd[])()={0,plus,from,find,0,rsh,cat},
 (*vm[])()={0,id,size,iota,box,sha,0};
I st[26]; qp(a){R  a>='a'&&a<='z';}qv(a){R a<'a';}
A ex(e)I *e;{I a=*e;
 if(qp(a)){if(e[1]=='=')R st[a-'a']=ex(e+2);a= st[ a-'a'];}
 R qv(a)?(*vm[a])(ex(e+1)):e[1]?(*vd[e[1]])(a,ex(e+2)):(A)a;}
noun(c){A z;if(c<'0'||c>'9')R 0;z=ga(0,0,0);*z->p=c-'0';R z;}
verb(c){I i=0;for(;vt[i];)if(vt[i++]==c)R i;R 0;}
I *wd(s)C *s;{I a,n=strlen(s),*e=ma(n+1);C c;
 DO(n,e[i]=(a=noun(c=s[i]))?a:(a=verb(c))?a:c);e[n]=0;R e;}

main(){C s[99];while(gets(s))pr(ex(wd(s)));}
Comme quoi, c'est pas parce que c'est hallucinant que c'est mauvais, ni parce que c'est clair que c'est correct...

http://www.jsoftware.com/jwiki/Essays/Incunabulum

Francois
fcharton est déconnecté   Envoyer un message privé Réponse avec citation 51
Vieux 02/03/2013, 20h15   #115
Médinoc
Expert Confirmé Sénior
 
Avatar de Médinoc
 
Homme
Développeur informatique
Inscription : septembre 2005
Messages : 22 387
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 29
Localisation : France

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : septembre 2005
Messages : 22 387
Points : 32 028
Points : 32 028
Envoyer un message via MSN à Médinoc
Ça parait bizarre quand même de programmer comme ça si on ne cherche pas à concourir pour l'IOCCC....

PS: Ça m'a aussi l'air mauvais, ça utilise gets et semble allouer de la mémoire sans jamais la libérer.
__________________
SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

"Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
Apparently everyone.
-- Raymond Chen.
Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.
Médinoc est déconnecté   Envoyer un message privé Réponse avec citation 21
Vieux 02/03/2013, 21h35   #116
fcharton
Membre Expert
 
Homme
Inscription : avril 2009
Messages : 1 359
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 48
Localisation : France

Informations forums :
Inscription : avril 2009
Messages : 1 359
Points : 2 044
Points : 2 044
Citation:
Envoyé par Médinoc Voir le message
PS: Ça m'a aussi l'air mauvais, ça utilise gets et semble allouer de la mémoire sans jamais la libérer.
Ah oui? Alors c'est sur que ça ne doit pas être bon, alors...

La lune... le doigt...

Francois
fcharton est déconnecté   Envoyer un message privé Réponse avec citation 22
Vieux 04/03/2013, 23h13   #117
v4np13
Membre confirmé
 
Avatar de v4np13
 
Homme
Analyste/développeur Java EE
Inscription : janvier 2005
Messages : 369
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 26
Localisation : Belgique

Informations professionnelles :
Activité : Analyste/développeur Java EE

Informations forums :
Inscription : janvier 2005
Messages : 369
Points : 218
Points : 218
Le code d'un collègue en java :

Code java :
1
2
3
4
5
6
7
try{
   ...
} catch (Exception e){
   StringWriter sw = new StringWriter();
   e.printStackTrace(new PrintWriter(sw));
   log.error(sw.toString());
}

Quand j'ai vu ça..

C'est quand même pas compliqué de faire :
Code java :
1
2
3
4
5
try{
   ...
} catch (Exception e){
   log.error(e.getMessage(), e);
}

Pourquoi toujours vouloir réinventer la roue ???? Pourquoi ?????
__________________
Utilisez les balises "Code" (alt+c).
Nous avons répondu à votre question? Pensez au tag

Le "lol" est aux boulets ce que le ";" est aux programmeurs
v4np13 est déconnecté   Envoyer un message privé Réponse avec citation 01
Vieux 08/03/2013, 10h39   #118
Jiheme44
Membre du Club
 
Homme Jean Michel
Ingénieur intégration
Inscription : décembre 2012
Messages : 25
Détails du profil
Informations personnelles :
Nom : Homme Jean Michel
Localisation : France

Informations professionnelles :
Activité : Ingénieur intégration

Informations forums :
Inscription : décembre 2012
Messages : 25
Points : 45
Points : 45
utiliser la sortie d'erreur (STDERR) pour écrire des messages dans le log 'normal' via les redirections (appel de perl à partir de ksh), est ce logique ?

peso, je trouve ça hallucinant. En tout cas, ce n'est pas ma façon de penser.
Jiheme44 est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 19/03/2013, 21h58   #119
nfluch
Membre expérimenté
 
Homme
Inscription : décembre 2011
Messages : 230
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : décembre 2011
Messages : 230
Points : 519
Points : 519
Citation:
Envoyé par v4np13 Voir le message
Le code d'un collègue en java :

Code java :
1
2
3
4
5
6
7
try{
   ...
} catch (Exception e){
   StringWriter sw = new StringWriter();
   e.printStackTrace(new PrintWriter(sw));
   log.error(sw.toString());
}

Quand j'ai vu ça..

C'est quand même pas compliqué de faire :
Code java :
1
2
3
4
5
try{
   ...
} catch (Exception e){
   log.error(e.getMessage(), e);
}

Pourquoi toujours vouloir réinventer la roue ???? Pourquoi ?????
je fais pas de java mais je suppose que ça doit imprimer tout le stacktrace et non juste le dernier message comme avec getMessage() ?
__________________
membre du collectif KassKooeye ;
http://soundcloud.com/thekasskooeyeexperience
et découvrez la BO du film "Beeing Michael Jackson" de Karl Zéro composée par Laurent Levesque :
http://soundcloud.com/laurent-levesque/tracks

"Vous avez entièrement raison mais c'est complètement faux" Guy Mamou-Mani président du Syntec

faire en sorte d'apporter la lumière
nfluch est actuellement connecté   Envoyer un message privé Réponse avec citation 10
Vieux 19/03/2013, 23h08   #120
Médinoc
Expert Confirmé Sénior
 
Avatar de Médinoc
 
Homme
Développeur informatique
Inscription : septembre 2005
Messages : 22 387
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 29
Localisation : France

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : septembre 2005
Messages : 22 387
Points : 32 028
Points : 32 028
Envoyer un message via MSN à Médinoc
Si c'est log4net/log4j, passer l'exception en second paramètre loggue l'exception complète si la lib est correctement configurée.
__________________
SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

"Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
Apparently everyone.
-- Raymond Chen.
Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.
Médinoc est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 20h02.


 
 
 
 
Partenaires

Hébergement Web