« first day (1491 days earlier)      last day (3475 days later) » 

12:10 PM
so, I was working on a simple thing, for which I needed to remove all of the undefined items in an array. I tried using .map, which was my first instinct:
function removeUndefined(array){

    array.map(function(item, index){

        if(item === undefined) array.splice(index, 1);
    });

    return array
}
that works fine, in most cases
< [1, 2, 3, undefined]
> [1, 2, 3]
< [1, undefined, 2, undefined, 3]
> [1, 2, 3]
but:
< [1, undefined, undefined, 2, 3]
> [1, undefined, 2, 3]
could anyone explain to me why does that happen?
 
tip: inspect each iteration with the debugger
 
whenever I get some consecutive undefined, it always rips one
 
on the third iteration, it would refer to 2 and not the second undefined
 
@AwalGarg what? it skips it? How?
@AwalGarg exactly, why is that?
 
@towc You're mutating the array as you're iterating it
 
12:16 PM
@Zirak ew
 
@Zirak how is that a problem?
 
The indexes will be all wrong
Think again about what you're trying to do
@BartekBanachewicz Don't just tell the solution!
 
@towc that is the entire problem! You spliced the second elem, on the next iteration, the index would be 2, but the item at index 2 would not be undefined, but the 2.
 
It needs to be coaxed out, these things are fun to find
 
12:17 PM
@towc The implementation doesn't check that something has been removed/inserted during the loop
 
I thought he's been here enough to assume he might just forgot or something
 
Though they could, think about how much slower it would be
 
Anyway @towc, you have an array, and you want to weed out certain items of said array
 
ooohhh! wait, I think I found the solution
probably not the best one
 
@towc show us
 
12:19 PM
Give the array methods list a gander
 
my problem is that I am changing the array while iterating, right?
 
~_~
 
so, just have another empty array before the iteration of the first one
 
Both that and using the wrong abstraction
 
12:20 PM
then map through the first one, and if the item isn't undefined, push it to the other array, and in the end return the second array
 
map is a function which transforms every item in an array into something else. You don't want to transform, you want to weed out.
 
@towc you want to filter! so use Array.prototype.filter!!!
 
@towc You're not mapping anything there, you're just iterating
 
@Zirak oh... I thought that map meant iterate
 
see that's why teaching imperative programming ends badly
@towc no. map means transform
 
12:21 PM
let me look at the list
 
Iterating is a side effect, it's not the goal
 
map :: (a -> b) -> [a] -> [b]
~
 
ok, I think I got it
array.filter(function(item){return item!==undefined})
 
jsh.zirak.me/1u89d //@Zirak jsh!!! ;p
@towc damnit!
 
@towc claps
 
12:23 PM
yay!
this felt awkward
 
but... I used jsh! So mine is better, no?
 
btw, if you want to weed out all non-truthy values, you can use this: .filter(Boolean)
 
if JS had sections you could write it as array.filter( !== undefined )
but Zirak's solution is better in most cases.
 
@BartekBanachewicz Scala has something like that, right? I've seen it somewhere and kinda fell in love
 
@Zirak return array.filter(true)?
 
12:24 PM
@BartekBanachewicz array.filter(Boolean)
@Zirak yes, scala uses _, array.filter(_!==undefined)
 
@towc true isn't a function, so not sure where you're going with that
 
@Zirak scala uses this _ thing, and Haskell simply allows you to write it as I did
 
it returns TypeError: true is not a function
 
I meant the function `Boolean`:
!!> [0, 1, null, '', 4].filter(Boolean)
 
@Zirak oh! You meant the Boolean function! I thought a Boolean value
ok
 
12:26 PM
@Zirak [1,4]
 
!!>typeof Boolean
 
@AwalGarg "function"
 
:: a -> Boolean
:P
 
@BartekBanachewicz sections are only for infix operators iirc.
 
@BenjaminGruenbaum operators are only infix :)
 
12:26 PM
@Zirak I could put any constructor instead of Boolean there, right?
 
I spent half an hour one day memorizing that all constructors like Array, String etc. are functions...
 
you can write filter (`equal` x) though
 
@towc You could put any function
 
for some reason, that always slipped through my mind :/
 
cool!
 
12:27 PM
which is of course equivalent to filter (flip equal $ x)
 
Yeah, I think JS could have been nicer if everything was a function, we've had infix notation, and everything was an expression
 
ok, back to my little project
 
and so, the functional seed has been planted
@BenjaminGruenbaum nah, instead we get class
 
eh, ES5 is painful to write functional code in
function(){} is a sad joke
 
@BartekBanachewicz especially since it's 2014 and even Java has better function notation now.
 
12:28 PM
yep.
 
Fun fact, PHP only recently got function(){} expression notation.
 
but I would miss space application and currying anyway
 
JS functions are still pretty versatile and powerful, it's mostly the syntax.
Currying is trivial to do in JS. I'm not sure curry by default is something I like.
 
I love it.
It's so natural.
 
Then again you don't really understand stuff like >>= so there's that :P
 
12:30 PM
lol stop turning that against me
 
Sorry, couldn't resist :P
in Lounge<C++>, 2 days ago, by R. Martinho Fernandes
@BartekBanachewicz ITT Bartek humiliates himself by openly admitting lack of understanding of fundamental Haskell principles.
 
I don't know, I have a love hate relationship with currying.
 
actNTimes op n m = foldl (>>=) (return m) (replicate n op)

addRandomCities = actNTimes addRandomCity

addRandomCity m = do
@BenjaminGruenbaum ^. Try removing currying and point-free
 
@BartekBanachewicz Some years ago, rlemon said he once pooped on a slide. Benjamin never forgot.
 
12:31 PM
!!slidepoop
 
@BartekBanachewicz That didn't make much sense. Use the !!/help command to learn more.
 
I feel that whenever I code "too" functionally I'm sacrificing readability.
!!slidepoop
 
Mar 13 '13 at 1:40, by rlemon
(Random Fact, when rlemon was 13 he pooped on a slide. he isn't proud of it, but he felt it was time to confess. I'm sorry slide.)
 
@BartekBanachewicz how would that look in scala?
 
@BenjaminGruenbaum no idea :V
 
12:32 PM
How would that look in JS? (You can use ES6 syntax)
Fun fact, I've written this sort of code in JS (for promises) like 50 times for promise questions - people never get sequential chaining in a loop right.
It's actions.reduce((p,c) => p.then(c), P.resolve()), with (actions) => at the start if you want it as a function.
I'd really enjoy being able to define operators though.
 
function actNTimes (op, n, m) {
    for (var i = 0; i < n; ++i)
        m = op(m);
    return m;
}

function addRandomCities(n, m) {
    return actNTimes(addRandomCity, n, m);
}

function addRandomCity(m) {
    // do actual stuff on m
}
@BenjaminGruenbaum here.
of course this strips the monad, but it's not necessary in JS
 
@BartekBanachewicz that's not the same since >>= is much stronger than just m = op(m) but yeah.
 
39 secs ago, by Bartek Banachewicz
of course this strips the monad, but it's not necessary in JS
:P
 
!!apocalypse
 
12:36 PM
this image always makes me lol
 
anyway passing m every time is meh
I'd rather put that in State if I had to do that
I thought about it here, but eventually settled on >>=
 
The problem is you find that sort of code elegant and beautiful :P
 
@AwalGarg jeez wth with this guy?
 
We share that problem, but I wouldn't push it to production :P
 
I injected an angular service to another service
 app.service('getSelectedModule', function () {

     this.getId = function (id) {
          return id;
         }

 });


app.service('myService', function ($http, getSelectedModule) {

console.log(getSelectedModule);

    var getExamSelectedId = {
        'goExam': 'goExam',
            'moduleId': 7
    };

    return {
        getData: function () {
            return $http({
                method: "GET",
                url: 'php/index.php',
                params: getExamSelectedId
            });
 
12:39 PM
@BenjaminGruenbaum it looks dangerous because it's short, but it has way more guarantees that the JS equivalent
and I suppose you wouldn't object putting that js to production :P
 
@BartekBanachewicz but it's not obvious at first sight what it does.
I wouldn't write JS that way to begin with.
 
@dievardump The most lifeless person ever
 
Go ahead and say it's obvious to you at first sight what it does, I dare you
 
But in the console.log(getSelectedModule); it show only the function ? any idea ? @BenjaminGruenbaum
 
@BenjaminGruenbaum the helper? not necessarily. addRandomCities? quite so.
I think the helpers are typically less readable because they are very generic
very generic code carries very little information about its purpose in one particular place
 
12:41 PM
@underscore read the Angular docs on services.
 
only real use of it gives it a meaning
 
@BartekBanachewicz It's "clever code"
 
well, call it however you want; it removes duplication.
I suppose your point is that most people wouldn't even notice the duplication in the first place
 
Wow, 80 views on that rebecca black thing
 
that arguably doesn't change the fact it's still there
 
i'm reading it
i couldn't identify the issue here with
 
@underscore Read the "Dependencies" part
it shows an example on how to use a service you just declared as a dependency
With services batchLog and routeTemplateMonitor
If you don't understand reading that code, it's better if you re-do the Angular get-started tutorial
 
O_o
 
!!hang angular
 
12:48 PM
  +---+
  |   |
  |   O
  |
  |
__+__
angular
---------------
 
!!hang idontgetit
 
  +---+
  |   |
  |   O
  |   |
  |
__+__
angular, idontgetit
---------------
 
!!hang a
 
  +---+
  |   |
  |   O
  |   |
  |
__+__
a, angular, idontgetit
-------------a-
 
yay! it works!
3d depth-first-maze
 
12:52 PM
Nice
 
Nice
 
Nietzsche
 
how do you render walls?
 
@BartekBanachewicz just had a function to make cubes, and made a cube for every wall in a maze
THREEjs
webGL
 
12:54 PM
@towc do you remove invisible walls?
 
@BartekBanachewicz I just don't make cubes for those
oh, you mean, walls that I can't see?
 
How do you draw the maze, 3d array?
 
@Jonathan he just said that, no? Also that's a question about storage, not rendering.
 
no. and I have no idea how to achieve that
not like it's a problem. It works quite smoothly
but would be nice to know for other times
 
12:57 PM
@towc here
might find it useful
 
My employer wants to start with WebGL to visualize warehouses next year, can't wait
 
@BartekBanachewicz wish I could understand c++
 
@towc it's really not different in what matters there from js
 
looking slowly at it and with a bit of basic experience I can actually see what the structure is saying, but there are some parts completely missing from my understanding
 
why this angular service return function block ?
 app.service('getSelectedModule', function () {

     return function (id) {
         return id;
     };

 });
 
1:00 PM
void fn(otherFn & something){}
in the first line
void World::_recalcChunk(World::DisplayChunk & c) {
what does that & mean?
 
World::DisplayChunk & is a type
 
ooooh
 
& means "a reference"
 
i used console.log(id); before the return id and it gave me the result what i want ? and after i injected it in another service it gave me the function block ? what i missed here?
 
I thought & had to be attached to something else to be a reference
ok, makes sense now
I probably have to read a lot more of that file to understand just what that function does
maybe some day I'll do it
 
1:17 PM
@underscore look, go to egghead.io and watch the tutorial, it'll be faster than us explaining to you how injection works in Angular and what a service is.
If you still have questions afterwards, let us know.
 
brother i have several services and i successfully injected all those things
without an problem
now i'm going to inject a service to the following service ?
app.service('myService', function ($http, getSelectedModule) {

    var getExamSelectedId = {
        'goExam': 'goExam',
            'moduleId': 7
    };

    return {
        getData: function () {
            return $http({
                method: "GET",
                url: 'php/index.php',
                params: getExamSelectedId
            });
        }
    };
});
Now the problem is when i console.log(getSelectedModule); before the return
 
You have not watched the video or read the tutorial like I've asked you to - I have no intent in helping you debug your code until you do.
 
ok wait
i'll do it right now
 
(Tip: When you type i to denote yourself in English, it's capitalized - so you'd type I)
 
1:29 PM
I'm glad I could help. Angular documentation has actually gotten much better over the past 2 years. You can usually find answers to your questions there - the rule for asking here is: if you're seeking opinions of users on a technique or have a too-specific question - ask here, if you have a technical question: it's probably better to ask on stackoverflow. If you haven't done enough research for SO you need more research to post here anyway :) Happy coding.
Y U .getElementById IN A LOOP?
Seriously, if you're teaching inmates to code, the least you can do it teach them practices that are not horrible.
 
@BenjaminGruenbaum thanks
i have to return object neh
return { }
 
1:44 PM
I really recommend that site, I watched the lectures when I learned it and it really helped me.
1 message moved to Trash can
Just because you're terrible at something doesn't make it "not programming" :)
 
@BenjaminGruenbaum lol someone's butthurt
 
@BartekBanachewicz I'm not too interested in troll messages here to be honest. I don't think the correct way is to shame you more and more like the c++ room does. Honestly I'm still hoping you just stop :)
 
@BenjaminGruenbaum No, of course not. Writing code against frameworks all the time and a particular thinking process does.
@BenjaminGruenbaum It wasn't a troll message.
There's programming using web technologies and there's web programming.
 
@BartekBanachewicz that's an argument I strongly disagree with, you're constantly writing code against frameworks and libraries all the time anyway.
 
The latter is really weird.
@BenjaminGruenbaum yeah, but it's not the same. I've written thousands of LoC of web python code and I don't know python at all.
 
1:48 PM
We're way past the times where some types of programming are more programming, someone making games using scratch or a lego robot do stuff with MINDSTORMS is as much of a programmer as someone using AGENT0 to do AI.
 
yeah well if you look at this that way then yeah
of course 'real' is p much arbitrary here
Okay, let me rephrase
 
@BartekBanachewicz I've written tens if not hundreds of thousands of lines of code using C++ and I read a few books and I don't think I know C++ very well.
 
Web programming is very different from other forms of common programming
 
@BenjaminGruenbaum It's forbidden according to meta meta.stackoverflow.com/q/198392/…
 
Web programming is probably the most common form of programming.
 
1:49 PM
WTH!
 
@BenjaminGruenbaum and incidentally I think this is an argument for my case, not against.
 
After that today probably comes mobile programming, which is very similar to 'web programming'
Most of the software we write uses algorithms written once and its challenges are in design and architecture and yes, also in UI.
 
hm, maybe.
I don't really use non-web frameworks that much, so I don't know if I don't like frameworks in general or web frameworks in particular
 
A good web programmer writing PHP isn't dumber than the a good Haskell developer writing AI. They have very different skillsets though. It took me a lot of time to realize that much - I hope you don't make the mistakes I did and do so.
 
> good programmer
> PHP
pick one
@BenjaminGruenbaum of course it takes different skillsets.
 
1:52 PM
You've got to stop with that non-constructive mindset. There are incredible PHP programmers out there which are probably much better programmers than you or I.
 
you brought PHP up again
 
Fine, s/php/c/
 
seriously if you're a good programmer, why would you use php
it doesn't compute
 
Because you're willing to overlook language ugliness for langue effectiveness.
 
if you're an excellent programmer, you're choosing the technology you work with
 
1:54 PM
PHP is easy to deploy, easy to get maintainers for, cheap, runs most of the web, has a ton of libraries, runs everywhere (even routers), is dead simple and is easy to reason about.
 
anyone choosing php voluntarily is automatically worse in my opinion, yes
I won't even try to hide that
@BenjaminGruenbaum and provides ultimately shitty solutions and code.
 
All I'm saying - that I held that opinion once and I no longer do.
 
@BenjaminGruenbaum is there anyway to reset the the service object when route change ?
 
@BenjaminGruenbaum if you want to be "effective" in terms of writing shitty code fast with teams who work for peanuts, then you don't fit my definition of excellent programmer
you might be an excellent project manager, perhaps.
 
@underscore services are singletons in Angular, you really don't want to use them for a lto of state - services essentially hold global mutable state. It's fine to have a little of it in an app but you want to minimize the amount. If you want to 'reset' it - add a reset function to it and call it when a route change event fires.
@BartekBanachewicz hypothetical scenario, you want a website for a newspaper, what do?
 
1:56 PM
@BenjaminGruenbaum how often updated?
 
You need writers to be able to write articles, you need to easily theme it, add analytics and bootstrap it. You want it to run on cheap servers and you want it to be fast.
@BartekBanachewicz let's say new article every hour, but you don't know how often it'll be in the long run.
 
@BenjaminGruenbaum before I start shooting questions, I'll answer "I'd gather much more detailed requirements"
 
Might be once a month, might be every minute.
 
I'd want detailed reports of traffic and use scenarios
 
That's the requirements - you want to publish news about a sector, you have a writer, he needs a website for news with different categories.
 
1:57 PM
I'd want budget for servers and development
I'd want to know a lot before choosing technology
 
You don't have those in advance. The budget is as low as possible.
 
it's as low as possible everytime
 
Exactly.
 
That means not lower than necessary.
 
Like in real software projects - you don't actually know the requirements very well in advance.
Real software projects change, it might not even be a news website in 5 months - it might be a blog, or even just a bot that posts on twitter. Your initial request however is for a website that does news.
 
1:59 PM
if you want to make it in a lower budget than necessary, you're going to receive shit, and instead of coming to Bartek Corp, you should go to Ben's PHP shop who will do it in half of the price and time
 
If you're going to convince me to use Bartek Corp instead of Ben's PHP shop - you better have some convincing arguments.
 
@BenjaminGruenbaum that's still very underspecified. Granted, I'm not a professional web developer.
 
Would going with Bartek Corp be better in the long run? Would it ever pay the difference?
 

« first day (1491 days earlier)      last day (3475 days later) »