/dpt/ - Daily Programming Thread

Previous thread: What are you working on Jow Forums?

Attached: code_master.png (1164x1738, 2.17M)

Other urls found in this thread:

pastebin.com/BvmT0Bpj
libsdl.org/download-2.0.php
code.fb.com/core-data/open-sourcing-haxl-a-library-for-haskell/
interactivepython.org/courselib/static/thinkcspy/index.html
twitter.com/NSFWRedditImage

Haskell is basically the minimum viable static language today

No, at the time there was a lot of money in lisp (like defense contracts kind of money) and, if I remember correctly they wanted Common Lisp to be as close to their particular flavors of lisp as possible.

Attached: 1536011816318.png (1600x874, 125K)

Is this programming?

pastebin.com/BvmT0Bpj

Sorry for the pastebin, Jow Forums won't let me post code tags

i want to nakadashi iori

Attached: police.jpg (848x480, 47K)

Background radiation can flip bits in memory and fuck up computations, but what about computations in the middle of being run? Registers at each stage of a pipeline?

the fuck?

I'm getting undefined references when trying to link SDL2 with mingw. Any tips?

i want to nakadashi kohina

i want to gokkun your mom

In c lets say i want a recursive function like.

void funct0(int a, int b, void (**fPtr)(int a, int b, void (**fPtr)())) {
fPtr[0](a, b, &fPtr[1]);
}


Is there no way to explicitly tell the compiler that **fPtr() params are these params presently being parsed over.
Its not like i can write it out myself, it would go on forever.

>romaji

Attached: wutface.png (112x112, 17K)

Learn about include and library arguments

-IC:/path/to/sdl2/include
-:LC:/path/to/sdl2/libs

Go here libsdl.org/download-2.0.php

Download the development libraries

Also download the runtime dll, and put it in the same folder as where you will run your exe.

Is python necessary?
Is C necessary?

no and no

Are you necessary?

I made a script to read all the lines in a python file (could be fairly easily adapted for other languages as well) and output the number of lines in the file.
I have 3 if statements here. It kinda irks me. Is there a better way to do this?
import sys

if len(sys.argv) != 2:
print("We take one argument and one argument only.")
sys.exit(0)

f = open(sys.argv[1])

# Make a couter for the lines and read them
lc = 0
with open(sys.argv[1]) as f:
for line in f:
if line == '\n':
continue
if line[0] == '#':
continue
# If the line begins with a tab or a space, loop thru the characters in the line and see if it's a comment
i = 0
if line[i] == ' ' or line[i] == '\t':
if line[i + 1] == '#':
continue
i = i + 1
lc = lc + 1
print(lc)

I'm a branlet n00blord who's learning python, no bully pls

>python
get ready for bully

pls no ;_;
It's expected tho because it's not C.

I think I figured out my problem. I'm trying to use a 32-bit only compiler to build a 64-bit binary.

no and yes

You can clean it up with str.startswith and str.strip

Hi, guys. I learned JavaScript and get a job. Now it's time to learn a real language in a free time. Should i pick Rust, Dart or oCaml? O maybe something else?

C would warrant bully too

Agda

I'm developing a bot with microsoft bot framework and I need to open a url in a new tab at certain point, Neither Response.Write or Response.Redirect works, what should I do?

Wanna something used in real world apps so not considering Haskell and others like it.

Haskell is used in real world apps.

I seen only one haskell app (something like WSIWYG editor for lAtEx). And read in some reasonMl manual that oCaml is like haskell but allow side effects and can be used in real world apps.

kek

Fuck yeah, we did it. I don't know why, but your post made me realize I was using the wrong architecture on accident. Thanks user

Couldn't you do this with grep -vE "^\s*(#|$)" | wc -l?

>oCaml is like haskell but allow side effects and can be used in real world apps
wow, that's almost completely wrong

I think he trying to learn more about python, not make the simplest line counter in existence.

no but me mommy and daddy love me and i wanna make them happy!

Attached: 1534558487041.png (308x300, 28K)

Good call. Should have checked if python had strip functions. Didn't even need the str.startswith
# Make a couter for the lines and read them
lc = 0
with open(sys.argv[1]) as f:
for line in f:
# Strip the line and check it
line = line.lstrip('\t')
line = line.lstrip(' ')
if line == '\n' or line[0] == '#':
continue
lc = lc + 1
print(lc)


That's much cleaner

Certainly but I figured that making it in python would be a good way to learn a little more about it, a la

the funny thing is you mentioned rust as a candidate. haskell's commercial/real world usage far outweighs rust's, and probably outweighs ocaml's (as much as inria love shilling it).

>python
puts ARGF.readlines.reject { |l| l =~ /^\s*#/ }.length

Attached: here it comes.jpg (824x412, 98K)

This was mine

strip with no arguments strips whitespace

lc = 0

with open(sys.argv[1]) as f:
lines = f.read().splitlines()

for line in lines:
l = line.strip()
if l.startswith('#') or not l:
continue
lc += 1

Firefox css engine is written in Rust. Facebook messenger (OMG how many users) is written in oCaml.

Why would someone want to learn more about Python?

Because they want a job. Pairing a scripting language with C++ gets you a job

if someone wants to get into machine learning

>Python
>scripting language
I'm not seeing it

>machine learning
a meme which I've heard is saturated at this point

It it better to learn FP in an OOP language that I'm familiar with, or to learn a FP language?

Learn an FP language. Trying to do FP in an OOP language will cause you to miss the point.

Is Haskell the best or?

What if it was called expression oriented programming instead of functional programming

Attached: 1535926333377.jpg (912x1009, 143K)

it's a fairly solid choice

OOPsies still wouldn't understand it and they'd desperately try to claim that expressions are objects

facebook use haskell to filter spam (OMG how many users)

they also use it for other internal things as you can see here code.fb.com/core-data/open-sourcing-haxl-a-library-for-haskell/

other companies using haskell include AT&T, Google, IMVU, Intel (they even developed their own compiler), Microsoft, NVIDIA (for in-house stuff)

Oh cool. That's good to know.
So the 'or not l' works because carriage return also counts as whitespace right? therefore line.strip() strips that too and leaves l as null?

It's easy, I'm a brainlet, I heard it's used for a lot of security-related stuff, and I need a scripting language that's not JS.

You can have objects in expression oriented programming thought

How does Haskell or Lisp get accepted by managers as the language for a project? There's a Raytheon project that uses Lisp for a missile defense system. How do you get a manager to sign off on that?

I personally like Scala. But Haskell is fine too. Also in 2018 you can go with ReasonML if you want to get into hype train.

speaking from secondhand experience (a friend at one of the big three console gaming giants) the best way is to take something that already exists and make it faster or better in the language you want to switch to, in this case, rewriting an internal tool in haskell

they don't seem to care much about consistency or obscurity, but it might be different at much smaller companies.

his point is that first class functions are often represented as objects in OOP languages, but there's no hard requirement that a function be an object.
All you need is to be able to pass around a function like any other variable.

my point is that OOPsies will stretch the definition of OOP until it's meaningless, as long as they don't ever have to learn anything else

>expression oriented programming
This is literally how I would describe what I do in C#.

What about declarative programming

What an inaccurate description.

OOP is a meaningless term. OOP is defined as things you don't like if you want to feel smug, and OOP is defined as dubious claims of code organization by people who also want to feel smug. Fuck you, fuck people who love OOP, fuck people who hate OOP. I'm so tired of seeing these stupid opinions that frame context only to the point of pigeonholing people into a strawman mindset so you can feel smug.

Don't even fucking consider replying to me without a smug anime girl.

Attached: anal beads.gif (500x281, 994K)

t. OOPset OOPsie

Huh?

C# is yet another statement-oriented language

Attached: bglisp.jpg (500x225, 42K)

FP and OOP are both okay as long as you're using the one that makes sense for your use case.

The problem is that people use FPLs because it makes them feel special, and end up writing horseshit code because the paradigm doesn't make sense for the project.

Attached: DcpBzVlVMAEpvYv.jpg (265x265, 13K)

>FP and OOP are both okay
reminder that PL centrists are fucking cowards

Do we need a /dpt/ version of this?

Attached: d0a.png (640x480, 14K)

I doubt that the people it would be aimed at would understand it.

based bill

I agree. OOP never makes sense for any use case, so you should always use FP.

I've been writing stuff in Javascript for about 2.5-3 years. I just got a job that uses Python. I learned over about a week or so but still am not familiar with a few of the OOP concepts.

They aren't really training me or even giving me anything to do right now so I guess that means they want me to learn it myself. Would CS50 (Hardvard) be a good way to learn more python skills, or is it all babby stuff like "this is how to write a for loop"

If not what is a good course to take?

Is it autistic to name the services built into my embedded OS after anime girls

PL is another way of saying "I don't know how to use the advanced capabilities of my lang"
t. C dev

I have never seen this before but it's really fucking funny
Is not giving a fuck better than being a "centrist?" I still vote but I don't really know why anymore.

Try learn python the hard way. There's a "try learn python the hard way for free" link near the bottom under the payment stuff to buy the book. His presentation is a little rough and it's not for everyone, but it's the best straightforward no-bs intro to Python I know of and you can skip forward to whatever you want to see code examples of various concepts. OOP in Python is weird.

book's outdated. Written when Python 2 was still popular.
Also the author is well known to be full of shit.

use this instead:
interactivepython.org/courselib/static/thinkcspy/index.html

I hope you understand that I don't take anything C devs write seriously.

A little outdated, sure, but that doesn't make it any less of a decent resource. Plus, iirc, most enterprise Python is still Python 2. At least in my experience.

nah, in my experience enterprise Python is "yo write this new internal tool that we're gonna throw away almost immediately after you make it, so just get back to us quick"
And since Python 2 is going to lose support in a year, there's no reason for anyone to be making new Python 2 shit anytime soon.

Ok. I'll check that out. There's no way it's weirder than OOP in Javascript (which some would say is technically not OOP due to prototypical inheritance)

if you're too much of a brainlet to make anything remotely sophisticated in C, that's fine with me

Depends on his needs I guess. We have Python 2 tools that'll be in service probably past the loss of support date until I get around to replacing them. Yeah, new material should be in Python 3.

My C days are behind me. (I used to work in it.) I prefer using a language with a bit more intelligence these days. I doubt you're capable of using anything other than C, though.

My job uses Python 2 and Django 1.

in that case you may want to look into using Python 3 with the Six library; it's intended to be used to write code that will work in either Python 2 or Python 3.

No sense in wasting time locking yourself into poorly designed fossil shit.

>don't use java, use c#
>don't use python 2, use python 3
>don't use javascript, use typescript
>don't use , use

>inb4 user tells us all to use his shitty gold plated thing

Attached: 1479888584459.png (1500x1015, 1.25M)

I use C, C++, and Python at work, so those are the langs I'm most familiar with, but I also have around a thousand hours' experience each on Java and Kotlin.

C++ can be a massive pain in the ass for embedded stuff, primarily because of the fact that you have to turn off a decent chunk of the lang's features to make it remotely suitable for embedded (e.g. RTTI and exceptions).

Python is a necessary evil- the syntax is broken and it's disgustingly slow, but it's brutally simple to throw shit together in Python so it's nice for stuff where speed doesn't matter (e.g. I have a python script that deploys binaries to some PLCs then talks to them over Modbus TCP to run tests).

Is $80k/year a good lowball for a remote software engineering job? I live in a low cost of living area so I don't care as much about salary. The company is based in SF.

Attached: 1535784903542.jpg (800x670, 55K)

Someone asks you to make a command line utility that lists the lines in alphabetical order from one file that don't exist in another file. Can your language do it more elegantly than this?
import System.Environment
import Data.Function
import Data.List

main = do
args

Why mapM_ and not traverse_?

How much of a pain would be to create a video player from complete scratch in C, without using any external libraries? My autism is kicking in, making me think like an impostor for using external libraries/APIs for projects.

Attached: autism.png (1280x720, 976K)

Only because I didn't want to import Data.Foldable as well. I guess I could have done it without Data.Function either but I just feel like `on` gives it so many style points

Depends how many formats you want to handle.

I want to start basic, and just handle mp4(First project of this kind).

* Your "lc" declaration could be moved lower.
* You can invert the condition and replace "continue" with the increment.
* You really only need ".lstrip()", but I wouldn't hold that against you.

I didn't test this, but it should work:
lines = pathlib.Path(sys.argv[1]).read_text().splitlines()

print(len(line for line in lines if line and not line.lstrip().startswith("#")))


cloc

#!/usr/bin/ruby
if ARGV[1]
puts (IO.readlines(ARGV[0]) - IO.readlines(ARGV[1]) ).sort
else
puts "usage: #{__FILE__} file1 file2"
end

¯\_(ツ)_/¯