/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1548642826925.jpg (826x610, 60K)

Other urls found in this thread:

fstarlang.github.io/lowstar/html/Introduction.html#the-essence-of-low
youtube.com/watch?v=KkMDCCdjyW8
developers.google.com/speed/webp/faq#why_should_i_use_animated_webp
twitter.com/NSFWRedditGif

nth for Nim!

Idris is excellent!

bth for Butts

Attached: F60ED993-D5D5-4DB3-B564-B86CD6A135F0.jpg (640x392, 52K)

third for COBOL

imagine being 6th

Statically typed Lua when?

When indexing starts at zero.

probably never.
Everyone just uses it with C, so it'll probably never get its own Crystal.

whats the point?

I like Lua's coroutine model. I'm also really bad with dynamically typed languages. Too used to the compiler helping me. I mean I'd prefer to use Haskell or Idris but the library support for making games just doesn't seem to be there.

Imagine being too retarded to use LUA.

There are patterns you can use to imitate the behaviour of coroutines like behaviour trees
lol at the idea of making a game with Haskell

I need a safe language that has manual memory management.

Haskells actually not bad for games these days. Decent amount of resources and libraries now.
Idris is a bit more rough because you'll have to either update Edwin's SDL bindings or do it yourself from scratch.

fstarlang.github.io/lowstar/html/Introduction.html#the-essence-of-low

Imagine thinking Lua is an acronym.

I came up with a similar language with a similar name. That’s it. This is a simulation. Fuck everything.

I do like how Idris is comfy enough that we can refer to people involved in it by their first names alone

Well Edwin's the creator, and the only other semi-prominent person using it is Brian Mckenna, but he's more a haskell and for whatever reason, JS ,guy. But yeah i love obscure/smaller langs because they usually have a smaller, more comfier community anyhow.

>i love obscure/smaller langs because they usually have a smaller, more comfier community

Attached: 0cbpdjii3pa11.png (645x729, 105K)

Wow, Brian's still involved in JS after the promises fiasco?

Not sure, I wish he'd move on to Elm since it seems incredibly perfect for him.

based and rumpfpilled

Attached: Satania128.jpg (634x634, 55K)

Are all the unironic C shills pajeets? I saw a poo flag shilling C on Jow Forums

Best show

Please do not use an anime image next time. Thank you.

Kill yourself.

Die

Fuck off.

Where do you think you are?

Attached: 1547894850039.jpg (1625x1219, 252K)

making a game in C
not allowed to use any libraries (it's a project for class, with 4 peers)
watch me write my own data structures and explode the project in memory bugs

>not allowed to use any libraries
Is it text based? Trying to make something graphical without libraries would be stupidly hard.

Okay that's not strictly true
We are allowed fmod for audio and a school-specific light wrapper around openGL

package main;

import java.util.Scanner;

public class Chargen {
public static void chargen() {
Scanner genderScan = new Scanner(System.in);
int sex;
System.out.println("What is your sex, adventurer?");
System.out.println("1. Male");
System.out.println("2. Female");
if(genderScan.hasNextInt()) {
sex = genderScan.nextInt();
System.out.println(sex);
genderScan.close();
}
}
}

I must be retarded or something. I'm working on a text game in Java to see what I can do with it, but the scanner here isn't detecting a next line, so it doesn't allow an input to be given for sex. What am I doing wrong? Almost this exact same code is working fine for a calculator app I made.

gender is a social construct

You are the stupid person on this entire website, and I include the entirety of /tv/ in that statement.

do you know what an if statement does

I just want to fix it buddy, I haven't used Java in a very, very long time.

hi dear.
I want to change the background color in matplotlib when the "signal" I am plotting obeys a certain condition.
For example, plotting a sin wave, I want to change the background color when the sine is positive.
Jumping straight at my keyboard I came up with this mess.
It works, but it's ugly AF.
Any idea how to clean this up?
import matplotlib.pyplot as plt
import numpy as np

plt.figure()
t = np.linspace(0,15,1000)
s = np.sin(t)

mask = np.zeros_like(s)
mask[s > 0] = 1
transition = []

for k in range(1, len(mask)):
prev_mask = mask[k-1]
curr_mask = mask[k]
if (curr_mask != prev_mask): # when mask changes value
transition.append(k)
transition.append(len(mask)-1)

# at every mask transition, if mask is positive, then change the background
for k in range(len(transition)-1):
if (mask[transition[k]] > 0):
plt.axvspan(t[transition[k]], t[transition[k+1]], facecolor='b', alpha=0.3)

plt.plot(t, s)

plt.show()

Attached: 1547157149342.jpg (498x535, 66K)

Any of you have the distinct displeasure of having to work with GRPC and python? I have a simple client and server based on the demo code on their site. Client requests are super fast but server responses are incredibly fucking slow. And this is just a simple test with a protobuf that look like

rpc GetShit(stream RequestMessage) returns (stream ReplyMessage) {}

RequestMessage {
int32 x=1;
int32 y=2;
bytes z=3;
}

ReplyMessage {
repeated bytes bbb=1;
}


The client request grpc takes like 1ms, but the response takes more like 100ms. I'm not doing any work that should take time, just populating the responses with default values.

I have no idea how to profile GRPC or python in general (I've never worked with python before). Anyone know why its so slow in one direction only?

Attached: goodvibes.gif (534x329, 257K)

Well I'm sure I managed to fuck that up somehow because, as I said, I must be retarded or something, but what I'm expecting from this is the following: under the condition that there is an integer input for the scanner on the next line, sex will be set to equal that input. I'm just trying to get that to work and then I'll build this into what I actually need it to do from there, the print command after that is to test that it took the input correctly. What's my problem?

what happens if it reaches that if statement and there isn't any input yet?
i don't think your human users have the reaction time to type out their answer in the millionth of a second between when you prompt for input and when execution reaches that if

Nothing happens then, the program concludes, and the problem here is that that's exactly what's happening. If I don't make sure this only runs if there's an input available though, it gets an exception. In what little experience with Java I have, nextInt allows the user to give their input on the next line instead of trying to detect before it's inputted. That's what it does with the near identical code on my calculator, but for some reason it tries to take the input before it's typed in this scenario. That's the problem I'm asking for help with.

>Scanner
evryteim

Attached: filter scanner pls.jpg (403x448, 64K)

>just trying to find a quick knapsack implementation to benchmark
>first 3 implementation i try, including the one from princeton's cs site, miss edge cases and fail
the fuck

>tfw learning to use unit tests
so much better than printing the result of a function...

wait until you learn about property-based testing (ie. quickcheck)

Learning Clojure by making a bunch of functions I think will be helpful in my day-to-day as an EE.

I'm trying to write tests for a function I wrote, called "lowest multiple", but I'm having trouble with the macro I wrote, `expect-eq`. I'm quoting everything, but it seems like nothing I do will allow me to write the test cases using a shorthand.

Here's the code:


(defn get-next-lowest-multiple [num factor]
(let [remainder (rem num factor)]
(- num remainder)
))
;;; Test.clj
(require 'elec)
(require 'clojure.test)


(defmacro expect-eq [lhs rhs]
'(clojure.test/is (= 'lhs 'rhs)))

(clojure.test/deftest lowest-multiple
(println (get-next-lowest-multiple -3 3))
(expect-eq (get-next-lowest-multiple -3 3) -3))


On a small sidenote, I've been really enjoying Clojure. I've tried picking up other Lisps in the past, but Clojure seems to be the first one that just sort of "clicks", you know? The best part about it is that, even if there isn't a standard Clojure function about it, there's probably a Java function that does the same thing, and calling those is really easy.
What's your favorite lisp, g?

Attached: Screen Shot 2019-02-01 at 10.49.43 PM.png (2258x1020, 280K)

Serious question
How can I learn to hack in LaTeX? Like make complicated programs

I'm not sure I understand your question.

LaTeX is mostly used as a document formatting tool. Yes, it's Turing Complete (meaning it *can* be used as a programming language), but you *really* shouldn't "make complicated programs" in it; there are much better alternatives out there.

Are you referring to other scripting languages like Python and Ruby?

Attached: [Reaction] owo.gif (228x164, 260K)

No . Latex. I can't program in anything else. I've tried . I just don't get programming

>he can program, but only in LaTeX

Attached: laughinganimegirls.jpg (1280x720, 79K)

then go shitpost in /sci/ with your gaytex

Attached: 1549082384817.png (429x608, 28K)

Well, assuming you're not shitposting, have you tried taking an intro to programming course?

Here's a link I always refer people to:
youtube.com/watch?v=KkMDCCdjyW8

if white, set green, turn counter-clockwise
else if green, set turqoise, turn clockwise
else if turqoise, set orange, turn clockwise
else if orange, set white, turn counter-clockwise

Attached: file.png (729x729, 176K)

nice

if it works move on user

I like clean stuff and the script I wrote doesn't feel like so.

cause that's not how you quote. But you're close. What you want in front of lhs and rhs is an "unquote", that's what it's called. But in order for unquotes to work, you need to quasiquote to start with. That means a backtick (`) rather than a normal quote (')
Clojure 1.10.0
user=> (def lhs 'test1)
#'user/lhs
user=> (def rhs 'test2)
#'user/rhs
user=> '(clojure.test/is (= 'lhs 'rhs)) ; no workee
(clojure.test/is (= (quote lhs) (quote rhs)))
user=> `(clojure.test/is (= ~lhs ~rhs)) ; fixed
(clojure.test/is (clojure.core/= test1 test2))

I'm trying to web scrape www.bloomberg.com/ but the site notices that I'm a robot and gives me bad response.
Tips?

spoof the same user-agent string as your web browser. maybe copy the cookies as well

Not sure what you're talking about, I'm pretty new at this.
Using Python with Beautiful Soup and Requests.

Nevermind, I just realized what you meant.

I wanna build an ETL toolset in Elixir. I think for example the GenStage would be a beutiful base for an ETL trabsformation pipeline.

Sadly my skills with elixir are subpar. I read a course in Erlang at college, but they are only remotely similar.

The reason why most programs are made in java/c++/c#/python is because its so much easier to get started and get stuff done. Especially in python. I wish there was python for beam, with a little pattern matching, guards, OTP etc. That would be great.

that actually makes sense.

>post deprecated jpg, not modern webm
>technology board

Attached: laugh2.webm (1280x720, 364K)

now i have your webm and you have a shitty jpg

Honestly fuck webms.
GIFs need to come back.

Oh okay. Guess I better read a Clojure book to really understand what I'm doing, then. Thank you, though!

>fuck webms
why?

they never left

Unfortunate, really.

why? gif is obsolete technology now.

Attached: webmtroll.webm (1000x414, 2.99M)

Nice try google shill

I mean you don't even need webm for this. WebP has very nice compression compared to .gifs.
developers.google.com/speed/webp/faq#why_should_i_use_animated_webp

Obviously video is even better but sadly not every platform supports vp8 or vp9

is there some concise name for a string that contains only one character but may be arbitrarily long?

What is it with Go, Jow Forums?

Is it too easy to write? Is the standard library too good? Everyone and their mother creates their own libraries for everything.

I'm writing my own command line library, my own configuration library and my own logging library right now.

Dear god. It just works too.

First good thing I've ever heard said about Go.

How do I into cute emotes?

>only two choices for gender
reported

It's not good.

Imagine mountains, oceans of poorly written libraries doing the exact same thing with slightly different names and slightly different API's.
Released under the same GPL/MIT licenses, with the same build:passing badges, with the same other kinds of badges and a fucking go logo, which is almost always a modification of that fucking retarded gopher.

I really like Go but dear god they've created a monster.

Hello /dpt/, I have zero programming experience, but I'm interested in learning. I already have a good tech-unrelated job 'n' sheit, so it's purely out of personal interest.
It it crazy to start with Haskell? It seems to have a reputation for being an advanced language, but I like the concepts behind it. Plus, it just looks nice.

Haskell has a reputation for being academic rather than practical.
If you're just learning for shits and giggles then you might enjoy it.

>It seems to have a reputation for being an advanced language
I wouldn't say advanced: just different. Haskell is purely functional, which makes it extremely different from other mainstream languages in use.
>Plus, it just looks nice
The is true for simple programs, but Haskell is just as good at generating complete clusterfucks as everything else.

Haskell is very principled and born in academia. But littered with sins just for the sake of practicality.
So it's not a bad choice. The learning curve might be steep because most resources out there are aimed at people who already know how to program. I think the purple book starts from zero. The community is rather small and very helpful, so don't hesitate to join a discord/irc/slack/forum and ask questions if you're lost despite following the book.

Attached: 1539519160672.png (1000x1500, 1.18M)

I actually learned Haskell as my first language like 12 years ago and it worked out really well.

im pretty excited now,
i finally manged to get my C cli program compiled as a .dll to use inside of a C# wpf application
and i tested it and my exported functions work!

as for why im using c# is cause i have an interview next week at a place where they use c# and .net
so i thought i would quickly code some c# gui shit to put on my github to show off
also i might make a personal website in .net depending on how hard/easy that is

Attached: f5ed8b61442b291ce583d3c44bb9a4c7.jpg (500x398, 42K)

so i have a function that fills a char array passed to it like
in c++ if i have array like
char test[5000]; but then only save say 10 characters into it with strcpy, does it still take up 5000 chars of space in ram?

if you have the variable defined as "char test[5000]" in your source file then yes it does, it uses static memory allocated to it at compile time

yes

if that is an issue you'll want a dynamic array. They call them 'vectors' in C++ because the committee never studied mathematics, I guess.

not the guy who asked the question, but cant you malloc a char pointer?

Sure but malloc isn't idiomatic in C.

yes, 5000 chars of virtual memory are allocated. If we want to be really autistic, we can notice that 5000B is bigger than a page on x86, and since Linux uses optimistic memory mapping, maybe we get lucky and part of the array is never put in physical memory. But that's autistic.

what should the function output for the following input

nums1 = [10, 100, 1000, 10000]
nums2 = [1]

i'm guessing 100? in which case the rule seems to be merge nums1 and nums2, and then take median

Attached: file.png (1196x1064, 124K)

yes you can tell that from the first example they give

[2] would be the median of nums1 even if nums2 were empty so it's a bad example

well the problem is that is have to supply a char array to a function which fills it and i don't know how big it's going to be each time so i have to have to make it huge. kind of sucks.

It needs to run in log time so merging won't work
I'd try to apply some form of binary search

why not just use a char** as a parameter

ah good call