/dpt/ - Daily Programming Thread

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

Attached: hidamari_dpt_waifu2x_traps.png (1618x1308, 1.95M)

Other urls found in this thread:

github.com/mmercedes/ghb
learn-c.org/en/
twitter.com/NSFWRedditImage

hi /dpt/
~

Elm is the only answer as it's an FP specifically made for webshit and only webshit.
Too bad Evan does only major updates and .18-.19 is taking 1.5 years. And the latest is that it's only in alpha-beta

I want to share some code between front-end and back-end, so Elm is not an answer for me.

Well Elm + elixir has been the unofficial "standard" in the community.

You mean a combination of ElixirScript+Elm or what? Because just Elixir+Elm would not let me share any code.

Actually, Elixir(Script) could be good enough for me, but first I need to check whether it will generate performant code for operations on very long arrays.

Attached: wXUz3tp.jpg (619x619, 60K)

>would not let me share any code
well that's not really the point of a front/back duo, if i get your meaning of "code sharing". But Elixir is fun regardless.

>Watch tons of python tutorials to learn
>Still have no idea what I'm doing

Jesus Christo...

So I heard you like recursion...

Attached: haskell.png (1200x847, 15K)

Use a statically typed language.

How bad is C# Random class? I have something like this
public void GenerateFood()
{
Random random = new Random();
int x = random.Next(1, gameGridX);
int y = random.Next(1, gameGridY);
Console.WriteLine($"food({x}, {y})");
if (snakeCartesian.GetWorld()[x, y].Equals(CartesianStates.IS_EMPTY))
{
food = new Circle(x,y, CartesianStates.IS_FOOD);
} else
{
GenerateFood();
}
}

and it gave me a stack overflow error, like wtf? my array is like 50x50

you will learn nothing if you dont have an aim in mind, what are you trying to do? if its a website, try to focus your attention to how you will be achieving that. No one learns a programming language for the sake of learning the programming language.

Re Creating the Random object with the same seed may not be as random as you think.

this is not a problem with the random numbers but a problem with that if statement

Graph drawer in C on windows

Programming challenge for ya, /dpt/

These two guys are giving Hime some trouble! They're watching her every move, she needs to text her friends secretly to come pick her up! Write her a function that allows her to send a secret encoded message to her friends. The function will accept a normal "dummy" message and the secret text to be encoded with it. It will capitalize the letters in the dummy message according to the secret text.

Sample inputs:
>>> secret_message("What road are we positioned on?", "traps")
"whaT RoAd are we PoSitioned on?"

>>> secret_message("Of our software pioneers, stallman is the smartest dude.", "freetard")
"oF ouR softwarE pionEers, sTAllman is the smaRtest Dude."

>>> secret_message("Not enough characters to spell this one.", "gnu")
"not enouGh characters to spell this oNe."

Good luck!

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

>recursion

oh god

...shit.. you are right....if a random function is technically, finally deterministic, how does one goes around this? have a seed that I "randomly" pick manually?
how so? there's only 1 place which are IS_EMPTY at all times.

Attached: tsukumizu.jpg (225x225, 21K)

Have random outside of the function in the class, maybe make it static
Also your indentation and naming is cancer, follow accepted style damn

pass the random to the function

I wrote a CLI utility to backup github gists, and repos you own, contribute to, or star. It's my first dive into golang which has been fun. I can see why its getting popular

github.com/mmercedes/ghb

curious if anyone has thoughts on how to improve this, or if ive wasted my time writing useless crap

also, thoughts on rust vs golang ? I chose go but maybe i should look at rust for a new "side project" programming language

actually the random object might be being created with the same seed every time because its so

>Also your indentation and naming is cancer, follow accepted style damn
how come this is not the accepted style? i literally CTRL + K, CTRL + D all my files (using MVS 2017)

Also, I think it would be more performant if you just take a random number between 1 and X * Y, then use the "Addressing mode" to obtain a
x and y back.

making Random at the class level is also a good idea

The correct way to implement randomness in your case is to

1. create an iterator over all empty coordinates
2. choose a random element from the above list

There is no point in going over already occupied coordinates. It's inefficient and bug-prone.

Go is pretty limited - no generics, much slower, design philosophy from about 30 years ago, GC to match, to

Attached: errnil.jpg (700x720, 82K)

>PascalCase for variable names (unless they're function parameters)
>This lonely else
I'm also pretty sure you don't have to have enums as ALL_CAPS, assuming of course that is an enum and not a constant

here's your answer to your homework assignment you scrub
def encode(dummy, msg):
j = 0
result = ""
for i in dummy:
if i == msg[j]:
result = result + i.upper()
j+=1
else:
result = result + i.lower()
if len(result) != len(dummy):
print("invalid input, forwarding message to NSA")
return ""
return result

>design philosophy from about 30 years ago
care to explain?

is rust any good?

I thought its a lot more efficient to just pick a random number in hope that you wouldn;t pick a place where the player currently is, since it only generates a new food when the player ate the old one. Its like 1% of happening

oops, forgot a conditional check that msg[j] isnt out of bounds, thats what I get for coding in browser

Come now user, what teacher would assign that as a homework assignment? Anyway, here's mine:
import Data.Char

secretMessage' :: String -> String -> String
secretMessage' [] _ = []
secretMessage' (x:xs) []
| elem x ".!?" = [x]
| otherwise = x : secretMessage' xs []
secretMessage' (x:xs) (y:ys)
| x == y = (toUpper x) : (secretMessage' xs ys)
| otherwise = x : (secretMessage' (xs) (y:ys))

secretMessage :: String -> String -> String
secretMessage x y = secretMessage' (fmap toLower x) (fmap toLower y)

What is happening is the RNG is being created with the same seed every time and the same coordinates are being chosen every time. If the coordinates fall on a used space, the program crashes because there is no opportunity for a different coordinate to be chosen. Since this is C#, you're writing a method of a class, so you can create the RNG once and have it as a field. That will solve the problem.

void secret_message(char* msg, char* secret) {
for(; *msg != '\0'; msg++) {
if(*msg == *secret) {
printf("%c", toupper(*msg));
secret++;
} else {
printf("%c", tolower(*msg));
}
}
}

Pike and his followers have this obsession with removing any useful abstractions in the name of "brutal practicality"; and a lot of people sure feel like the language is handicapped because of it.
Rust? I think it's quite nice. It's not very popular around here, because it's a Mozilla project, it's heavily hyped, the community isn't really great at the moment (CoC stuff), and it lacks a lot of support (the ecosystem is immature). I guess it has potential. My 2c.
I still don't see any reason to use Go in particular though, it doesn't really has any killer features.

wait those are homework problems in CompSCI?

I should have done that. My Economics homework is way harder.

never programmed before except in school.. Hated it though.. After work of twelve hours should I read or try to program..I'm low iq though with fifth grade math..

Attached: 1524894328150.jpg (638x792, 61K)

let secret_message str pad =
String.map (fun c -> if (String.contains pad c) then (Char.uppercase c) else c) str
;;


OCaml is power. OCaml is expressiveness. OCaml is safety. OCaml is conciseness. OCaml is the future.

>OCaml is the future
>program doesn't work
...

what in the flying fuck m8.
at least test it before posting jesus christ

Yes it does? It should be Char.lowercase c in the else branch, but that's irrelevant and obvious (especially when the poster himself fucked up his very first example)

D-. Please try to understand the problem before you attempt a solution.

The program works. If you don't like it, then change the specification. OCaml is this powerful, even if you don't want to believe it. I'm sorry that you can't accept that.

>The program works

Maybe, but it doesn't produce the expected output. Check the assignment again.

Maybe it is you who needs to understand my solution before claiming it doesn't work. It's short and elegant. Consider that maybe you don't like it because you're so used to bloated, inexpressive languages.

Woah.... So this.... is the power..... of OCaml.........

(You don't understand the problem. It's not to capitalize every character that's in the secret, it's to capitalize the secret characters sequentially.)

Tried the JSON simple library on a java project, it's comfy, would recommend it.

Attached: absolut.jpg (600x800, 48K)

You need to shift the pad when you use a letter, otherwise you are just finding all the letters in one string that match another.

it uppercases ALL of the letters inside the message that are in the key
example:
"faggot" "fag" -> "FAGGot" where it should have been "FAGgot"

not this shit again

nice dubs

You don't understand, do you? I reread the original post after posting my solution, since there were people claiming it was wrong. And, while I admit that my solution is not "perfect", in the sense that it doesn't perform exactly as described, that's really irrelevant.

Maybe you don't understand this, because you've never had a job in your lives (whether that's due to being incompetent, hard to work with, inexperienced and still in college, etc - it's really irrelevant and I don't care to hear it), but in the real, no one expects software to perform 100% to the specification given. A software specification is an ideal, a goal to work towards even though you'll never reach it. My program produces provably approximately correct outputs - to within a small % of error - making it, for all practical intents and purposes, correct in our real world, non-academic context.

That's the power of OCaml - you don't have to spend a week labouring on a piece of software to get a "good enough" solution. My solution took seconds to write, compared to however long the other ones took, meaning that it's much more efficient to write, even if it does trade some accurateness for that efficiency. And, on top of that, it's easy to reason about, due to being so small and using standard library functions. This is why companies like Jane Street use OCaml in real world settings, even if you literal (figurative) children can't understand it.

>putting this much effort into weak bait

Oh, I get it, you're RPing! That's funny user, but this isn't the thread for that.

I want to make sonic adventure 2 mods.. Like bounce ring..

How do I return the length of an array of objects?

array.length is returning the amount of characters.

List.length

That's how easy using OCaml is.

Go to bed, nick.

Where do you even get the characters from if you're calling length on an array of objects?
Elaborate a bit more.

even JS has array.length
it's not exactly impressive.

in haskell this is just
length

nothing personel, kiddo

python goes even further:
len

"array" is an implementation detail, while "list" is an abstract ideal. OCaml is more conceptually pure than javascript.

These are inexpressive. Length? Len? Of what? On what? List.length is expressive, yet conscise. It's perfect.

Not generic, unlike the superiour IEnumerable.length

This isn't your everyday autism. This is...advanced autism.

Adding features for a C++ POS-Tagger I'm currently on.

Guys one question... I wanted to put the feature extractors into a separate header - I suppose it's bad practice to write the #include to that file in the location where the feature extractors were in the original header?

I would like to write it were the other includes are, but I need access to things that have been defined under the includes block.

noone cares, unless you have to contribute something to the thread get lost

Attached: jebshadenough.jpg (609x324, 36K)

List.length has type 'a list -> int. It IS fully generic and type-safe.

I am contributing to the thread by posting about OCaml.

IeEnumerable doesn't have a length property. Why would it? It is just an enumerable.
You are looking for list and the property Count.

My bad:

I'm a fucking idiot and I forgot an underscore.

It works perfectly fine as intended

if I study math and work hard I will succeed..I will be good..

gonna learn python on code academy..

Attached: dq17.jpg (251x288, 52K)

>I suppose it's bad practice to write the #include to that file in the location where the feature extractors were in the original header?
wat?
I've read that three times and am still confused.

>gonna learn python on code academy..
Why have you chosen to learn python? Are you aware of its pitfalls? There are better, more expressive, languages.

kys

Yeah I'm fucking tired.

Assume I currently have
#include
#include
#include

some_classes_and_code;
some_feature_extractors;
some_other_code;


If I want to put the feature extractors to a seperate header, could I go with

#include
#include
#include

some_classes_and_code;

#include

some_other_code;

- or would that be bad practice?

I'd say it's bad practice because it feels wrong, but I need things defined in the code block above the code I want to extract for the code to work.

Question boils down to "I don't know where the compiler will put the contents of the header file"

>studio.h

I thought I was the only one.

Nah I love this one, it's a classic.

leave already

It would be better practice to make a proper header file for the stuff that some_classes_and_code declares that some_other_code uses, and then split them into separate translation units.

no..I need to make mods..

thought so. Holy crap this will explode into headers, I actually wanted to avoid this but it seems inevitable.

Blame C++ for being one of the only contemporary languages without a module system.

Stop being a neckbeard

Keep in mind that you don't *have* to do it that way, it's just better for compilation times. Which are also already a problem in C++.

Dunno about C++ but there is a VSC plugin for C that auto-generates C headers (everything except the structs) or vice versa.

i wish I transitioned and programmed as a kid.. Now I'm old and dumb..

Is learn-c.org/en/ a good resource for learning c?

Attached: IMG_20180426_124032.jpg (640x640, 141K)

Fuck off.

I know that feel. It is just to late.

t. 21

why..

I'm still far away from the point where there are real problems with compile times, though.

Can't imagine something like this doesn't exist, I'll look into it.

Rude

because you're useless and will never program anything nor contribute to the discussion of programming in any meaningful way
this thread is dedicated to the discussion of programming and the answering of programming related questions
there is absolutely no reason for you to be here and you know it
your posts are bait meant to attract (you)s. that much became clear sometime last thread. you have no other business here than getting our attention so that you feel like a part of the conversation and therefore important
fuck off and leave already

>need to write a somewhat complex script to do something
>Hmm should I put in the 3 extra minutes to write it as a reusable general function?
>nahh when will I ever need to do this again lol
>what about the extra 30 seconds to add basic comments so I can understand wtf this six indexs deep object even is?
>no need I am 160 iq god i dont even read my own instructions

Why the fuck is past Me so fucking retarded.

How to I fix myself?

Convince me to properly re-write this script rather than just barely changing enough stuff so it works for my current needs and passing the buck to future me/\.

Attached: babytalk3-300x300[1].jpg (300x300, 29K)

Hope u get cancer kid

rude desu

i just want the programming threads I read and enjoy to not double as some autist's self help group

I'll be going off to college soon and I want to get ahead a little bit by learning on my own this summer, I did take a Computer Science course in high school where we worked with Visual Basic but the teacher only gave us some problems to work on each day without actually explaining anything so it was completely worthless. Is SICP a good book for a complete beginner?

... but I digress;
Fuck u nigger faggot

Attached: 2E5E99D7-3E4B-4CA9-B6C7-5131D693C5FE.jpg (640x272, 98K)

>he doesn't know about the word-filters

how nu r u?

>Is SICP a good book for a complete beginner?
maybe
might be over your head a bit