/dpt/ - Daily Programming Thread

What are you working on?

Old thread:

Other urls found in this thread:

tiledbattle.com
github.com/wooorm/alex
syntaxdb.com/
github.com/wooorm/retext-equality/blob/master/rules.md
github.com/wooorm/retext-profanities/blob/master/rules.md
en.wikibooks.org/wiki/Haskell
twitter.com/NSFWRedditVideo

first for java

...

They got rid of CD/DVD. they are coming for our guns.

Reminder that syntax highlighting is for kids and faggots

Thank you for using an anime image
Thank you for using an anime image

...

I'm working on efficient TCP socket handling, SOCKS handling, and better Tor integration in my decentralized TV project. Audio playback is working pretty OK now, and basic encryption has been implemented (via OpenSSL). I know I shouldn't hand-roll encryption, but I'm thinking about creating a hand-written RSA function set just to make it easier to decode (not without a fair amount of warnings though).

I also made an IRC channel (#basictv on Freenode) for it, hoping I can get away from shilling it on Sup Forums.

Trying to learn Anglican as an alternative probabilistic programming language to PyMC which I do not find so intuitive.

>that gook name
not interested.

did somebody say anglican

Starting java - anyone know why this code is crashing? It's a program that counts vowels from a string

if you enter a string with vowels it throws:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at charplay.Charplay.getVowels(Charplay.java:28)
at charplay.Charplay.main(Charplay.java:11)


public static char[] getVowels(String word){
char[] foundV = {};
char[] Vowels = {'a', 'e', 'i', 'o', 'u'};
char[] arg = word.toCharArray();

for (int i = 0; i < arg.length; i++){
if (Vowels[0] == arg[i]){
foundV[i] += arg[i];
}else if (Vowels[1] == arg[i]){
foundV[i] += arg[i];
}else if (Vowels[2] == arg[i]){
foundV[i] += arg[i];
}else if (Vowels[3] == arg[i]){
foundV[i] += arg[i];
}else if (Vowels[4] == arg[i]){
foundV[i] += arg[i];
}
}
return foundV;
}

foundV[i] doesn't exist

do this:
foundV = { 0, 0, 0, 0, 0 };


and then do an outer for loop rather than Vowels[0], Vowels[1], Vowels[2]...

Use a fucking switch!

It crashes because it's Java.

You mean a loop.

I mean a switch in a loop.

>char[] Vowels = {'a', 'e', 'i', 'o', 'u'};
>Vowels[0]
>Vowels[1]
>Vowels[2]
>Vowels[3]
>Vowels[4]

...

for(int i = 0; i < arg.length; i++) {
for(int j=0; j < Vowels.length; j++) {
if(Vowels[j] == arg[i]) {
// ...
}
}
}

What's your problem with frog posting?

if i wanted to create a random number in c, let's say, between 5 and 25 how could i do it?

kill yourself before the genie kills you

(random() % 20) + 5

y tho

(rand() % (high - low)) + low

Anyone here ever actually used call/cc?

Modulo bias.

thanks

it's saying high is undeclared

yes, it's off by like 20 in 2 billion

Nice bait but you're 30 seconds too late

it was always giving me the same number, is it fine to add #include and [srand(time(NULL));] or is there a better way

thats the only way

call srand once with a seed
if you use the same seed you get the same ouput

false

there's no other way

>it's literally impossible to do anything other than time

Developing this game
tiledbattle.com

true

Call me noob and whatnot
but please
can someone give me a really good reason why I should make ANYTHING private in my code?

!true

I'm not working on a project, but I'm working on learning how to program. I'm only a few days in so far, but it's been a fun ride; maybe I can stop being an impoverished burger flipper and be a code monkey instead...

My current plan: I'm doing the Python-based EDx 6.00.1x MIT course January-March, then following up with the 6.00.2x course March-May. I'm passively watching the 1986 MIT SICP lectures (finished 3B) with the intent to more intensely visit the lectures/book later this year when I'm more experienced; I also plan to go through K&R at an undefined timeframe. I'm going to try things like Project Euler and attempt to solve at least the basic problems in multiple languages (at this point, it would be Scheme/Racket and Python and, after K&R, C). I assume this will give me enough of a level of mixed practical and theoretical knowledge to learn whatever I need to learn for whatever I end up working with.

Any suggestions I should look into or pitfalls I should avoid? Any other preferred sites like Euler where I can semi-gameify/measure actual progress via challenges/projects? What other auxiliary concepts/tools should I learn?

If you are working with pajeets, its the only way to stop them fucking your shit up.

Otherwise it's basically a meme for shitty programmers with Alzheimers.

is c# different enough from java to call it "learning a new language"?
skimming through a tutorial and barely seeing any difference

Preventing name collisions in derived classes.

it's meant for software that has many developers working on it
so no, it's not your concern

sorry but what? explain please
how do you spaghetti up your code so hard, that names in different classes collide, just because the attributes or functions are not private?

succ 'D'

when is it time to swallow your pride and ask a colleague for help

just had an idea for something that would make it easier for storing and translating data structures in a universal format across languages. like you could download an array file from the internet, include an import in your program, and then load it in your program

JSON?

...

If you can enforce invariants some other way then no, not really. I guess if you wanted to hide implementation so you could change it without any problems in the rest of the code base, but usually you do that with polymorphism and not encapsulation (which are somewhat two sides of the same coin).

XML?

nobody ever studied Haskell to land a job

Well most objects have an external and internal API. For instance a rotating implementation of a queue has extra fields and methods for managing the queue, but these are implementation details that are abstracted from users of the queue structure (where you only care about enqueue, dequeue, empty?). Publicly exposing these details makes it so that subclasses of the queue have to work around the functionality that they want abstracted anyways, which can become problematic for naming as an example

What's the best programming tip you can give to someone?

>subclassing ever

leave /dpt/

Premature abstraction will kill your motivation

Logic setup for 22 relays and 7 transistors controlled by a raspi. Never really worked with python before but its pretty quick to pick up.

Don't

Is Jethro Tull good programming music?

...

...

Also, access modifiers are compile time guarantees like type systems that can statically enforce preconditions maintained in other methods of the class. Yes, you CAN program without a static type system (it should be no suprise that dynamically typed languages usually dont have access modifiers), but in those cases you can't rely as well on the computer to verify that you haven't fucked up in your program (which you inevitably will).

Yes, subclassing is cancer but when you allow subclassing to be a main feature of your design, you also should maintain some form of encapsulation (without necessarily going all out with redundant getters are setters)

I have a function which I'm using to invert an array:

unsigned * invertKey (unsigned * keyPointer)
{
unsigned key[5], inverseKey[5];

for (unsigned counter = 0; counter < 5; counter++)
key[counter] = *(keyPointer + counter);

for (unsigned counter = 0; counter < 5; counter++)
inverseKey[key[counter]-1] = counter;

return inverseKey;
}

Problem is, the array returned immediately goes out of bounds. I store it in a new array asap:

unsigned key[5] = {3, 5, 4, 1, 2};
unsigned * unPoint = invertKey(key);
unsigned inverseKey[5];
for (unsigned counter = 0; counter < 5; counter++)
inverseKey[counter] = *(unPoint + counter)+1;

It's worked fine so far, but it is plausible that the array values could become corrupted?

what am I doing wrong? I know it has got to do with the pointers but I don't understand why

Adding --csv argument to gawk.

>std::string*
for what purpose

Avoid namespace pollution in header files

What exactly is "C with classes"-style C++? What is done differently?

struct with function pointers

I think he means why a pointer to a string.

what?

i dont get what you sayin

They don't use the actually useful features like templates or lambdas.

Sorry for my dumb question, but can someone explain what my professor is asking me to do here? He's not responding to my emails and I'm confused for what he's asking. Is he saying he wants a program that puts a set of numbers into an array but instead of an array it's a linked list? This isn't something I've read about yet but this is already fucking me up.

C++ how it was meant to be used

badly

the error I get is that the constructor arguments dont match

It's a linked list using nodes allocated from an array.

you are passing "local" and "true" as values, not pointers

You're passing local as a pointer, but giving the value. Either change the function signature to the Event constructor to take a reference (&), const reference( const&) or take desc, t, and local by value (no warts) .

Who owns the data once you pass it in? Event? Or is it just going to hold a reference to the data?

Seriously don't ever write std::string* ever again.
Do this:
struct Foo {
std::string str;
Foo (std::string s);
};

Foo::Foo (std::string s)
: str(std::move(s))
{
}

This takes the memory for the string passed as an argument (s) and moves it into the field str, so that the variable s now holds an empty string and therefore doesnt need to be cleaned up.

Usage:
int main ()
{
// this makes a heap allocated string and passes in the constructor, so that foo1.str is "hello"
Foo foo1("hello");

// creates heap allocated string m
std::string m = "world";

// this copies the string m into a new space on the heap, and sends that to the constructor where it will be stored as foo2.str
Foo foo2(m);

// This is similar to the above, but does not copy m, instead moving it into the constructor such that foo3.str will be the old value of string m, and our variable m will be set to the empty string. This is useful when we know we aren't using m anymore, as it avoids unnecessarily heap allocations
Foo foo3(std::move(m));
}

>yfw this
github.com/wooorm/alex

>cripple to 'a person with a limp'
Holy moly

WHY IS THIS SHIT SO SMALL

print('Hello world!', file=myFile)

how to I get this to print to the console AND myFile?

syntaxdb.com/
This looks cool

def tee (out, str):
print(str)
print(str, file=pout)

wow

github.com/wooorm/retext-equality/blob/master/rules.md
github.com/wooorm/retext-profanities/blob/master/rules.md

It doesn't have a CoC...
Oh wait, the whole thing reeks of SJW.

Complete programming noob here, often get stumped at the getting libraries to work phase of programming. Really want to make a simulation of a card game (similar to poker) which language would be simplest to do this with? On windows.

Haskell

>and therefore doesnt need to be cleaned up.
explain to me why C++ calls destructors on things that have been moved

Started learning go. What am I in for?

>insensitive, inconsiderate
>using "him" is insensitive
wo0t

Libraries on windows is a bitch.
DrRacket has a graphics lib suited for absolute beginners and it works fine on windowz.
If you're trying to use C++ I suggest you step away from the keyboard

fuck off

Download Haskell Platform and go through this en.wikibooks.org/wiki/Haskell

Do a console (text based) version first

Python? I don't know if that shit works on Windows though.

If it's a simulation you probably don't need a GUI. Just go with python.

It does, sempai.