logs archiveBotHelp.net / Freenode / #2f30 / 2015 / September / 24 / 1
Evil_Bob
cant remember where it was from, i think reddit, but interesting i think: https://www.newscientist.com/article/mg22329764.000-the-ai-boss-that-deploys-hong-kongs-subway-engineers#.VG3BGjSUfSs/
AI wins \o/ :P
"AIs like Chuns do face a problem. His team spent months finding the most efficient algorithm for designing schedules. It settled on a genetic algorithm, which pits many solutions to the same problem against each other to find the best one. But the people that had to carry out the scheduled work took a while to get used to the idea, as they didnt like not knowing why they were doing certain things."
stateless
https://lkml.org/lkml/2015/9/3/428
hahaha
he is totally right though
FRIGN
stateless: yes, we should also check if we have arrays as args in our projects
I remember on case in a project
stateless
FRIGN, I never use this idiom but we should check yes
FRIGN
but I remember that I fixed that.
stateless
-Wsizeof-array-argument
build with that
k0ga
my boss asked me yesterday about this
stateless
on a recent enough gcc
it will warn if you use sizeof() on an array argument in a func definition
k0ga
'why this functions is storing the result in this temporal matrix passed as argumernt?'
...
stateless
hahahaha
k0ga
and it was even worse, because the argument 'matrix' was a VLA matrix
stateless
i have gcc 4.8.2 here and it doesn't support that option so i can't test it
k0ga, ...
k0ga
yes
:'(
f(int x, int y, int m[x][y])
stateless
in any case, heavy use of arrays and arithmetic on arrays as opposed to using pointers is clumsy and only really applicable in certain type of programs (like a linear algebra package)
in general even if they are not present as arguments in func definitions
i.e. most new C coders will prefer arrays to pointers because they don't know how to use pointers properly
so you see sh*t like for (i = 0; buf[i]; i++)
or even worse for (i = 0; i < LEN(buf); i++) etc.
instead of for (p = buf; *p; p++) { ... }
but that's a trivial example
k0ga
yeah
this is true
for (bp = buf; bp < &buf[size]; ++bp) -> it is beatiful :)
or ever better
stateless
yeah if it is not null terminated
k0ga
for (bp = buf; *bp; ++bp)
stateless
I don't like ++bp however
i prefer bp++
I only use ++bp when it makes a difference
k0ga
stateless: this is stilistic, you get used to it
stateless
yes I know
just saying
k0ga
I do because in some very old compilers it was a difference
an I got used to it
stateless
it reminds me of C++ where people might use ++foo to avoid extra memory allocations because they know the implementation details of the ++ operator and how they overloaded it
:P
k0ga
hahahahhaah
stateless
:P
k0ga
uhmmm, maybe for this reason I will change, I don't want to have anything in common with c++ ppl
xD
stateless
hahaha
k0ga, btw ur last example is the same as my last example
:P
just realized
well apart from the naming
k0ga
yes
I use p, q and bp
depend
stateless
I use p/q for strings
k0ga
and s an t for strings
stateless
well I use p and q for random sh*t sometimes
why t?
k0ga
tradition
stateless
I use d and s for dst/src too
sometimes
k0ga
I think it comes from anciant unix code
stateless
I've also used s and e for start/end
depends
k0ga
yeah
the important thing is the context
stateless
yes
k0ga, a global pointer called s
in a 10k sloc program
done
:P
k0ga
I liked a lot the article of Pike about C programming
stateless
yeah it was good
http://doc.cat-v.org/bell_labs/pikestyle
Consider: When you have a pointer to an object, it is a name for exactly that object and no other. That sounds trivial, but look at the following two expressions:
np
k0ga
it should be taught in the universities
stateless
that's a good argument :)
node[i]
The first points to a node, the second evaluates to (say) the same node. But the second form is an expression; it is not so simple. To interpret it, we must know what node is, what i is, and that i and node are related by the (probably unspecified) rules of the surrounding program.
Nothing about the expression in isolation can show that i is a valid index of node, let alone the index of the element we want.
If i and j and k are all indices into the node array, it's very easy to slip up, and the compiler cannot help. It's particularly easy to make mistakes when passing things to subroutines: a pointer is a single thing; an array and an index must be believed to belong together in the receiving subroutine.
wisdom :P
k0ga
http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
stateless
yeah I think Ken thompson mentioned this
as one of his favourite pieces of code
k0ga
it is very good
stateless
k0ga, yes the good thing with pointers is that they are normally either incremented or decremented by 1
as opposed to sh*t like s[size - i + 1] crap
:P
(whic is wrong, just waiting for someone to spot it)
:P
k0ga
yeah
I remember a code that was using a flat array to implement 2 dimension array, and it was doing the addition of the 4 neighboors
the code was something like:
« prev 1 2 3 next »