/dpt/ - Daily Programmmmming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

hackage.haskell.org/package/mtl
youtube.com/watch?v=SW-BU6keEUw
pastebin.com/ta3Thtad
pastebin.com/8LU2uZYu
discord.gg/xt7bx2g
discord.gg/4TuhPhr
twitter.com/NSFWRedditImage

Dijkstra was a fucking hack.

rewriting the haskell kernel in linux

Stallman was right.
Gap buffer >> Ropes
Atom was right
Piece table >> Ropes

t. butthurt /sci/ poster

How does one manage a large project without it becoming spaghetti code central? Any books on the subject worth reading?

Design patterns

Design by introspection

referential transparency
pure, lawful abstractions
compositional APIs and semantics
prevent invalid states by construction

I think that quote had more truth to it back in Dijkstra's time when things like Fortran were your only choice for HLLs and computers were slow enough that you still had to understand how to implement algorithms efficiently. Now that we're so focused on producing software as quickly as possible no matter how messy it is or how slowly it runs, I think the reverse is probably more true.

Just change the definition of the word spaghetti.

// Write the function strindex(s,t) which returns the position of the rightmost
// occurrence of t in s , or -1 if there is none.

int strindex(char *s, char t)
{
int position = 0;

while(s[position] != '\0') // find array size, store in position
++position;
while(s[position] != t) { // if t doesn't exist, return -1
--position;
if(position == -1)
break;
}
return position;
}

i solved this by first computing array size and then running backwards. does this perform better than

int strindex(char *s, chart t)
{
int position = -1;

for(size_t index = 0; s[index] != '\0'; ++index)
if(s[index] == t)
position = index; // store last position t was found
return position;
}

?

fuck i don't know what i'd doing in python
whats wrong with this bitch

No globally accessible state, minimize state accessible by code that does not need it.

...

Heck I know, even after all of those years.
People who do earn big buck though.

Julia is the best Lisp around.

Not even a lisp, let alone close. Go away shill.

Sorry boys but if you can't handle mtl style then you can't pair program with me.

>mtl style
Your what?

hackage.haskell.org/package/mtl

youtube.com/watch?v=SW-BU6keEUw

what do you suggest?

I'm having troubles with this exerciser from the c language primer
pastebin.com/ta3Thtad
The programs prints the correct result for kelvin but fahr comes out as zero

I think I'll pass on pair programming with you, not really in the mood for hearing about abstracting abstractions.

Rewrite it in Rust to make use of zero-overhead abstractions.

>/*I'm unsure if calling a fuction like this is right*/
It's not.

t. full-stack front-end developer

>Rewrite it in Rust

Functions don't return more than one value.
Try rewriting temp into, say, tempFahr and tempKelv and returning each to outf and outk.

wrong, ruby is.

It has pretty much everything I'd ever want from a Lisp though, and it definitely feels like one when you do anything more than fizzbuzz with it.

>zero cost abstractions

So use it if it's the right language for you. It's not the right language for me, and it's not enough of a lisp to replace a lisp for me.

Can't we just write it in shell or something?

Going to rewrite the Linux kernel in pure Rust.

You'll note that I explicitly wrote zero-overhead abstractions, not zero-cost abstractions.

I'd rather use Pharo if I went down that route. But I'd rather have high execution speeds, multimethods, and proper lisp macros.

The book was ambiguous about it and I think it said I must use one function but if functions can't return more than one value I'll re do it with you
thank you all

whats the best framework to build gui with using python? qt?

I really just looking for something simple for my scripts.

PyQT is the most mature and polished option afaik.

Based.

don't forget monadlogic and listt

>c language
>doesn't even know how to call a function
C doesn't do tuple unpacking. You're think of Python. Or C++

Use the fucking 2nd one. But both run times are going to be O(cn) anyway.

Not him, but what's better to learn? Python or C++?

>>doesn't even know how to call a function
>tuple unpacking
There was no syntax error in his code and you don't know his intention. Maybe he just felt like using the comma operator.

Both

Python is better to learn. C++ is better for speed

Learn c++ first then python, it'll teach you much better coding practices. Later you'll most likely use python for most shit unless you're doing some heavy oop or gaymer application, but your knowledge of c or c++ will get you writing better code

other way around

False

Debating whether to dig this old voxel engine project out and do something with it, like get rid of this single-pass stencil shadow volume code using geometry shaders and replace it with a 2-pass version using transform feedback to generate the shadow geometry. I have working shadow map code which is fast but I don't like em, and working with orthographic for the lightsource camera is a pain in the arse (but I may have my matrix multiplications in the wrong order)

True

0

Tralse

CRUD lego has nothing to do with CS.

you can write quick fizzbuzz scripts in python

and c++ is actually worth learning

0==""

I redid the program to have separated functions for fahrenheit and kelvin but now farenheit only returns zeros and kelvin only returns its own value like there had not been any input.
pastebin.com/8LU2uZYu
pls I'm just a brainlet
Comma operator?

file = open('input.txt', 'r')
list = []
for line in file:
list.append(line.rstrip().split(' '))
n = int(list[0][0])
matrix = [[0 for x in range(n)] for y in range(n)]
for i in range(1, len(list)):
a = int(list[i][0])
b = int(list[i][1])
matrix[a - 1][b - 1] += 1
matrix[b - 1][a - 1] += 1
for i in range(0, len(matrix)):
sum = 0
for j in range(0, len(matrix[i])):
sum += matrix[i][j]
print("Node %d has a degree of %d" % (i + 1, sum))


Can a pythonista help me pythonize this code? I'm a python newb.

Yea but I'm not going to be doing your hw for you

...

>hw
>christmas break

>Comma operator?
It's something most people don't use in C and you shouldn't concern yourself with it while learning.

It's just evaluates all expressions seperated by a comma and returns the value of the last evaluated expression.

For example
b = (a = 1, 3);

After that a=1, b=3. You sometimes see macros that do things like:

return (errno = ENOMEM, ret_val);

If you need more than a single variable in a for loop
for (i = 0, j = 0; ...

So when you did
fahr, kelvin = temp(exfahr, exkel);

It basically comes out to evaluate expression (fahr) which is has undefined value(doesn't matter because it's discarded) and then evaluate expression (kelvin = temp(...)).

Don't worry about the comma operator, it's best if you just keep learning C and ignore everything I said.

I'm doing some memory leak analysis on my program, and I'm having a little trouble understanding what I'm finding. I've find two memory leaks, but currently I'm not testing those features so the malloc's are never called. My program is meant to read books in .txt format, so the input files are opened and kept open throughout execution, and the books can be realtively big (several megabytes).

How do open files affect the heap size? Are they involved at all or is it totally abstracted by Linux, so I don't have to worry about it?

alright user, thanks

>worrying about memory leaks
>in the year of our lord, RAII, 2018
ISHYGDDT

Okay so I'm learning C++ and there's nothing you can do to stop me.

But what's the best way to "code"? Been using vim though I'm more comfortable with emacs 2bh also downloaded qt with qt creator... But like the whole thing, how do I develop applications? Debugging and other shit like that. I have zero experience with anything more than picking around on the command line while programming, except with lisp in emacs/slime.

Last time I worked on a large project it was in pseudo fortran 77 and the development environment was literally the command line, fortran, and shit like grep and diff lmao it was atrocious spaghetti mess too.

This is C, not C++

Your fault for writing it in an unsafe deprecated language to begin with

import Data.Map(alter,mapWithKey)
import Text.Printf(printf)
u=alter(Just .maybe 1(+1))
main=()u a .u b) .words)mempty .tail .lines=

*virtually 0 calories

k

in that gif K looks like a bit of a trans-X-ual

>hey, can I hold this gun?
>sure, just be careful that it has no trigger and just randomly shoots at times and it won't even be your fault
>hey man i just shot myself in the foot. Do you have any tips on how not to shoot myself in the foot?
>you can use this gun that actually has protections
>LOL DO I LOOK LIKE SOME SORT OF DORK TO YOU?

Programming is hard because you dipship CSlets ignored Church for a fucking century. And you keep doing your shit in a procedural and imperative style.

Then mathematicians came, raped you with Monads and FRP and you are still butthurt.

I write C. Need C help?

Monads are cool, true. It would be nice if Racket could get its dependent typing finished so I could have Monads/Dependent types/DSL/Meta-programming all wrapped into one.

>Monads and FRP
>not linear types and sequent calculus

>Racket
leave

Racket right now isn't that good, but Haskell and other Functional PLs lack Macros and all that good stuff. Once It's type system improves it could be a nice balance between Haskell and LISP

Template Haskell is fine for most þings

>not dependent types and term erasure

Apples and oranges, whereas monads are BTFO by linear types and FRP is BTFO by sequent calculus.

>monads are BTFO by linear types
blatantly incorrect

Sorry, I should say linear types and algebraic effects.

not that user but look at my issue here

>linear types and algebraic effects
at least that's possibly arguable, but you'll have to pry mtl from my cold dead hands

your formula for fahrenheit is wrong

temperature in fahrenheit = temperature in celsius * 9/5 + 32

We got a discord now discord.gg/xt7bx2g
Bring your shit

get tae fuck

>now
We've had one
discord.gg/4TuhPhr

I'm putting LED strips on a snowboard and am working out how to translate an accelerometer reading into non-trash patterns.

>spent the whole day trying to configure emacs
>kind of get the hang of it
>try to use it for python because i'll take a course in college
>can't elpy to work at all
>mfw
I didn't think I would be such a brainlet that I wouldn't be able to get python environments to work

Alright but why aren't my functions returning the proper results?

It's your scanf, change the format to "%lf". %f is floats, %lf for doubles.

Also
>double main()
main always returns an int.

Should I learn Haskell, or Scala as my first functional language? I have experience with C, and Python, so i want to branch out to functional languages.

Now it works, thank you so much

Just go with haskell. It'll bust your balls but you will learn some neat stuff.