r/MachineLearning • • Jul 03 '17

Discussion [D] Why can't you guys comment your fucking code?

Seriously.

I spent the last few years doing web app development. Dug into DL a couple months ago. Supposedly, compared to the post-post-post-docs doing AI stuff, JavaScript developers should be inbred peasants. But every project these peasants release, even a fucking library that colorizes CLI output, has a catchy name, extensive docs, shitloads of comments, fuckton of tests, semantic versioning, changelog, and, oh my god, better variable names than ctx_h or lang_hs or fuck_you_for_trying_to_understand.

The concepts and ideas behind DL, GANs, LSTMs, CNNs, whatever – it's clear, it's simple, it's intuitive. The slog is to go through the jargon (that keeps changing beneath your feet - what's the point of using fancy words if you can't keep them consistent?), the unnecessary equations, trying to squeeze meaning from bullshit language used in papers, figuring out the super important steps, preprocessing, hyperparameters optimization that the authors, oops, failed to mention.

Sorry for singling out, but look at this - what the fuck? If a developer anywhere else at Facebook would get this code for a review they would throw up.

  • Do you intentionally try to obfuscate your papers? Is pseudo-code a fucking premium? Can you at least try to give some intuition before showering the reader with equations?

  • How the fuck do you dare to release a paper without source code?

  • Why the fuck do you never ever add comments to you code?

  • When naming things, are you charged by the character? Do you get a bonus for acronyms?

  • Do you realize that OpenAI having needed to release a "baseline" TRPO implementation is a fucking disgrace to your profession?

  • Jesus christ, who decided to name a tensor concatenation function cat?

1.7k Upvotes

471 comments sorted by

View all comments

36

u/darkconfidantislife Jul 03 '17

Sure, sure, if you'd be willing to compensate my time for writing good code, like Facebook does (as you mentioned in your question), then I'd be happy to.

Otherwise, stfu and enjoy the free code I gave you.

24

u/syedashrafulla Jul 03 '17

Readable, good code is for others to read. That other is, usually most importantly, you in a few months. Academics working on their own code waste a lot of time trying to find root causes due to poorly written code. If graduate students would have a Review Friday where another student reviewed their code over the last week (via quid pro quo with another graduate student), I think total research velocity would increase a significant amount.

Source: me and my abhorrent code during my way-too-long PhD

5

u/throwawaycompiler Jul 03 '17

It has been continuously repeated to me throughout my studies that one should comment their code well (and structure it well). But I have looked at code from well-praised people at my job that are just absolutely horrendous in terms of readability. I hardly understand what it does, and there are hardly any comments, and it blows my mind that everyone else on the team is ok with this.

I've come to believe that being able to read any type of code and understand it should be emphasized a lot more than writing nice code. It seems to me that companies are looking for people who can learn quickly rather than write things nicely for people.

3

u/syedashrafulla Jul 04 '17 edited Jul 06 '17

This is a good take, but I will challenge a couple of points.

there are hardly any comments, and it blows my mind that everyone else on the team is ok with this.

My challenge to this is I was taught that comments are to be used only when the design isn't code-evident. If variables and functions are named well, then comments are generally sparse. The tradeoff is that naming variables & functions eloquently is the hardest part of programming.

I can lob this criticism at the OP too, but I suspect the OP is disappointed in the lack of function docstrings.

I've come to believe that being able to read any type of code and understand it should be emphasized a lot more than writing nice code.

My challenge to this is you can't have one without the other. Being able to read varying code choices requires being able to write good code. The only way to write good code is to read many styles of code.

→ More replies (1)

22

u/didntfinishhighschoo Jul 03 '17

Such piss-poor approach to life. I keep forgetting that for most people, their job is just their job, even if they’re in an interesting and important field, all that matters are the sticks and carrots the bosses lay out to them.

30

u/Jorrissss Jul 03 '17

their job is just their job,

I think the part you're not emphasizing or appreciating is that their job is just their job and without compensation they aren't necessarily interested in making more readable code for the public. A person can have a tremendous amount of pride or love for their work, but not give a shit about you.

6

u/east_lisp_junk Jul 04 '17

I think the part you're not emphasizing or appreciating is that their job is just their job and without compensation they aren't necessarily interested in making more readable code for the public.

I think the part OP is really missing is that there is absolutely no shortage of work to do. The decision here is not about whether to go put some extra hours in so that there's time to clean up research artifacts for general public consumption. Those extra hours are getting put in, no matter what. The decision is whether the extra hours go towards chasing another research result, or updating the curriculum for some course you're teaching, or serving on some committee for your department, or trying to really give detailed feedback on some students' homework, or writing another grant proposal so that you'll have the resources to get more research done, or making something they've already written more accessible, or giving a more thorough read to some papers they're reviewing, or....

2

u/Jorrissss Jul 04 '17

I think the part OP is really missing is that there is absolutely no shortage of work to do.

I agree, that is certainly more significant than the part I mentioned. There's always a ton to do, and every moment spent documenting code is time not spent on an interesting problem.

8

u/didntfinishhighschoo Jul 03 '17

This is a practical field. Your tools and execution are multipliers of your ideas.

Look, I get that compared to other parts of the academia, DL is moving at a blazing speed. But compared to other parts of the industry - it's like going back in time for me, it feels like doing development in the nineties. Look at the ecosystem and the infrastructure and tools and culture available for web developers and operations people.

34

u/WormRabbit Jul 03 '17

It's not "a practical field", it is an academic study. The point of academic studies isn't to produce practical tools, but to invent new ideas and test approaches. Thus churning out 10 papers with piss poor code and numerous tests is strongly preferrable to a single well-written code example which may not even prove that useful.

→ More replies (9)

5

u/nuclearpowered Jul 03 '17

On the same maturity timescale dl development now could be compared to web dev in the 90s. Have had colleagues make the same analogy.

→ More replies (1)

13

u/darkconfidantislife Jul 04 '17

That's a false assumption, I care deeply about my research field, that's why I stick to it and don't go work at some hedge fund for way more money.

Here's the thing though, I want to work on interesting problems, I literally have a backlist of 100+ ideas I want to try out. That takes time. Why would I spend time on making my code look pretty for others and slow that down even more, when I could instead move onto trying out a new idea?

That being said, if people ask politely, I will help them out.

→ More replies (2)

37

u/commisaro Jul 03 '17

Or maybe we'd prefer to spend our time working on those interesting and important problems, rather than doing the boring drudge work of fixing up code we wrote for problems we already solved? But I look forward to the clear, well-documented and commented code you will release along with your own state-of-the art algorithms for currently unsolved problems.

14

u/Mr-Yellow Jul 03 '17

boring drudge work

It's simply good coding habits. Nothing hard about getting things right the first time.

Of course it's extra work if you don't bother following good practice from the start.

1

u/didntfinishhighschoo Jul 03 '17

I bet the guys in the eighties you reinvent and republish from thought the same thing.

13

u/TankorSmash Jul 04 '17

He's got a point man. I advocate great code as much as the next guy but you're here shitting on someone else's code without so much as a pull request to back your claims up.

You're literally just calling out some other devs to make yourself feel better. It would take some real effort but make the pull request with those variable names and try to comment some stuff out and help people instead of being a dick for no constructive reason.

→ More replies (1)

2

u/Lampshader Jul 04 '17

Hey OP, maybe you can come work for me? I won't pay you, but it's an interesting and important field.

3

u/[deleted] Jul 03 '17

Yeah - but if you get scooped and don't get publications then you won't be in the interesting and important field for long.

It sucks, but don't hate the player hate the game...

4

u/evilish Jul 03 '17

Holy shit mate. We'll put, and I completely agree with you.

As a JavaScript developer who has dug into learning DL this year. I'm amazed at how hard DL authors make it.

@Authors, if you don't feel like providing decent documentation? Fine. Don't feel like commenting your code? Fine.

But for the love of all shiny. At the very least, come up with decently named methods, variables, etc. Something that makes your code, a little more self-documenting.

If nothing else, when you come back to look at your code sometime in the future. It'll be much easier to grok what's going on.

2

u/crazylikeajellyfish Jul 03 '17

Remember that these people are also trying to hit deadlines, they can't do everything. Part of why JS tooling quality is so high is that it's a lot of open source passion projects where engineers have the leeway to Do The Right Thing. These Facebook devs probably cut corners because they were in a rush, not because they're lazy.

4

u/Mr-Yellow Jul 03 '17

Don't buy this for a second.

No amount of rushing will cause a person to write unclean or undocumented code. It's always part of the game.

Except when a part of the industry decides it's too hard for some reason and never gets into good coding habits.

6

u/didntfinishhighschoo Jul 03 '17

The deadlines in the industry are fiercer. We write code in weekly sprints that no one outside the company will see. Nothing goes live without a code review from two people, automated checks, mandatory documentation, etc.

9

u/crazylikeajellyfish Jul 03 '17

Nobody outside the company will see it, but plenty of people within the company will have to work it once you're gone. Again, deployed industry code is responding to a very different set of requirements than a research group. You really think any of that code will get used in an actual Facebook product?

→ More replies (4)
→ More replies (1)
→ More replies (1)