/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

github.com/ii8/guira
tiobe.com/tiobe-index/
gitbook.com/book/cheddar/docs/details
dlang.org/spec/version.html#staticif
dlang.org/mixin.html
github.com/robpike/filter
johndcook.com/blog/2012/01/09/holographic-source-code/
twitter.com/ID_AA_Carmack/status/753745532619665408
sandimetz.com/blog/2016/1/20/the-wrong-abstraction
twitter.com/SFWRedditImages

Hime is the best OP

Messing with scala, its actually pretty good

Are you using it as a better Java or a worse Haskell?

What are some programming searches that give you unexpected predictive results?

Both desu haha tho its much much much better java.

github.com/ii8/guira

rate my program /dpt/

C++ is a beautiful multi-paradigm language

8th for Go is best language

kys

>Groovy, Coffeescript, F#, Less, D, Rust, Ruby, Clojure, Elixir, Sass, Typescript, etc.
Why.
Do these languages seriously have something that absolutely no other language has? Why do they exist?

Gotcha. Like I said, this part of the data is most likely going to change at a glacial pace, but I think I'll just keep trying to understand data binding just so it's one less thing I have to worry about.

>Call of duty, Battlefield, Arma, Overwatch
Why.
Do these games seriously have something that absolutely no other game has? Why do they even exist?

kill yourself

tiobe.com/tiobe-index/

almost no one even uses them, they're just hipster fag memes

Also a valid question, though i guess those games still have some sort of """story""" so once you've played one you could be compelled to play another. But yeah, why indeed.

I was badly trying to illustrate a point which is now lost to me

Rust does, but yes, some of these seem totally unnecessary, just like pic related

gitbook.com/book/cheddar/docs/details

Seriously what is the point??? what should I drop the safety of a well established language for?

it doesn't take much effort to make a shitlang, people make them for the learning experience or they hope it will get them rich if people start using it

Were did the damn pic go?

like malbolge

Oh man I hate print being anything besides a goddamn function SO. MUCH.

that's not working, it did once, adding two numbers together, but not any more. o t

D's supposed to be a more modern replacement for C++. One thing it has got going over other languages is its metaprogramming capabilities, with mixins, static if, template constraints.

> static if

why do you need a hack like this if you have metaprogramming

How the hell is that a hack?

Let's say I wanted to write a forum software.
Would I leave my CGI script at the root of the website and have all URL queries, such as Sup Forumsthread/52676882 be tokenized within the CGI script?

Or am I going about this all wrong?

is D metaprogramming handled at compile-time?

Lisp has proper metaprogramming and you don't need a "static if", you just evaluate an if-expression (or any other kind of expression) at compile-time.

e.g.
;; dumb example
(defmacro macro-fib (n)
;; whoa, static-if!
(if (< n 2)
n
`(+ (macro-fib ,(- n 2))
(macro-fibs ,(- n 1)))))

(mac-fibs 8)

;; expands to

(+ (+ (+ (+ 0 1) (+ 1 (+ 0 1))) (+ (+ 1 (+ 0 1)) (+ (+ 0 1) (+ 1 (+ 0 1)))))
(+ (+ (+ 1 (+ 0 1)) (+ (+ 0 1) (+ 1 (+ 0 1))))
(+ (+ (+ 0 1) (+ 1 (+ 0 1)))
(+ (+ 1 (+ 0 1)) (+ (+ 0 1) (+ 1 (+ 0 1)))))))

Dark C++ show me the dark metaprogramming

any opengl or graphics bros out there. Trying to make a model viewer for a particular file format but for some reason I cant calculate the final position of the vertices properly. I know what the final position is, but it doesnt make sense given the weights and bone matrices.

Not him but D's static if is something like pre-processor directives in C and C++ to control compile time conditions. If you're looking for something equalivent to your code then you can use a mixin to generate a chunk of string and have it interpreted as an actual piece of code. Unless I misunderstand what you're discussing here because I've not followed the discussion.

Yes, it's for compile-time
Like a better C/C++ preprocessor
dlang.org/spec/version.html#staticif

More on the mixins if you want to see that
dlang.org/mixin.html

Go is the worst language if you use it I hope you like writing the same code over and over again because it doesn't allow for literally any kind of abstraction, it's almost like it was designed for people who aren't capable of using a normal programming language.

just saying that needing a special 'static-if' makes it seem like you've got a hamstringed metaprogramming system.

That reminds me a few threads ago someone mentioned the Zebra Puzzle and I looked up solutions on Rosetta Code, both Go and C were pretty damn disgusting compared to other solutions.

>hamstringed
hamstrung

>try in the browser
>weeb shit
>nothing works

pottery

#include
#include

void remove_spaces (char* restrict str_trimmed, const char* restrict str_untrimmed)
{
while (*str_untrimmed != '\0')
{
if(isalpha(*str_untrimmed))
{
*str_trimmed = tolower(*str_untrimmed);
str_trimmed++;
}
str_untrimmed++;
}
*str_trimmed = '\0';
}

int main()
{
char str_untrimmed[] = "A Toyota! Race fast, safe car! A Toyota!";
char str_trimmed[sizeof(str_untrimmed)];
int x, y, size;
x = y = size = 0;

remove_spaces(str_trimmed, str_untrimmed);


while (str_trimmed[size] != '\0'){
size++;
}

if (size % 2 != 0){

int unevenHalf = (size - 1) / 2;

for (x, y = size - 1; x = unevenHalf; x++, y--){
if (str_trimmed[x] != str_trimmed[y]){
printf("%s is not a palindrome. \n", str_untrimmed);
break;
}
if (x == unevenHalf){
printf("%s is a palindrome. \n", str_untrimmed);
}
}

}
else{

int evenHalf = size / 2;

for (x, y = size - 1; x < evenHalf, y > evenHalf; x++, y--){
if (str_trimmed[x] != str_trimmed[y]){
printf("%s is not a palindrome. \n", str_untrimmed);
break;
}
if (x == evenHalf){
printf("%s is a palindrome. \n", str_untrimmed);
}
}
}

return 0;
}


What should I try next?

C has an excuse in that it was designed multiple decades ago, before we knew any better.

;; no recursion
(defun print-nodes-cps (tree)
(labels ((func (node cont)
(if (node-p node)
(with-slots (val left right) node
(print val)
(lambda () (func left
(lambda () (func right cont)))))
(progn (print node) cont))))
(let ((cont (func tree (lambda ()))))
(loop while cont do
(setf cont (funcall cont))))))

CL-USER> (print-nodes-cps
(make-node :val :a
:left (make-node :val :b :left :c :right :d)
:right :e))

:A
:B
:C
:D
:E
NIL

By the way, I'm not saying you're incapable if you use it, but you should know that it's an insult to your intelligence. You might be okay with that.

>google
i swear google, microsoft and apple are fucking shit at programming and language/api design

True, I guess my point is that Go was designed, among others, by Rob Pike, and the solution does not look any better, as if they disregarded all the research and decided to create a language that does not improve nothing aside from providing green threads OOTB.

It works lad.

try typing in a query

It's fine though?

ctrl+meta+x will print it to the minibuffer/echo area

// check if string is palindrome
int isStrPalindrome(char *str)
{
int i,j;
for (i = 0, j = strlen(str) - 1; i < j; i++, j--)
if (str[i] != str[j])
return 0;
return 1;
}

...

Rob Pike on go:

>The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt.

Wow, Google sure has a lot of faith in its developers, you know, the company that only hires the best and brightest.

It only does one year on the website because otherwise people might write queries that fill their ram with dates.

It also does only days on the website. not hours and minutes.

try
> (month (or mar jul dec) (day fri))
> (week (eq (mod n 3) 0))

utherly overcomplicated

good idea, should have used a while loop instead
skiping ' ', '!', ','
because of "A Toyota! Race fast, safe car! A Toyota!"

>So, the language that we give them has to be easy for them to understand and easy to adopt
this isn't just useful for junior devs, though.
in fact, most devs aren't researchers, and the current languages at the front of research aren't yet particularly useful for anything practical (and their communities make the exact mistake that go is attempting to prevent its junior devs from making: premature and excessive abstraction).

go is terrible shit
github.com/robpike/filter

>the company that only hires the best and brightest
that's a meme, they're not looking for the best and brightest people, they're looking for normies who will fit in with their company culture

when you guys have an idea for a program, or software to write, or even tackling one of the many programming challenges that get posted on here daily, how do you handle implementation? I mean, how do you decide what data structures to use, what algorithms will be useful, what patterns could come into play, etc...

is it something you should know in the planning / idea / design phase? or is it something that you think of as you are coding it?

I'm always worried that I'll try one of these challenges, and I'll end up getting it to work, but in a really hacked together, inefficient sort of way. Am I really learning anything by doing that?

"company culture" is the biggest cancer meme

your provided link is confirming my argument.
a statically typed language that provides the tools for easily implementing map/filter/reduce also provides the tools for people to quickly go batshit with abstraction (especially with types).
go makes it hard to abstract a lot.
this means more code duplication, but also more explicitness and less premature abstraction.
i'd argue that overall it's nicer for maintainers to read more explicit code (as they don't have to learn layers on top of layers of abstraction for every single thing and every single dev working on the project), but more annoying for devs to write the code.
haskell is one of the most powerful of the more popular statically typed languages, and it suffers from extreme amounts of premature abstraction.
go certainly isn't as fun to write as haskell, lisp or even python, but i'd argue that maintaining a go is quite a bit easier.

I just finished the Rust tutorial. I haven't used it yet, but it looks much better designed than Go. My biggest problem with Go is the boiler plate error handling. The Rust Result type looks much more interesting.

>they're looking for normies who will fit in with their company culture

uh oh...somebody failed the interview

no i don't think they even if they're hiring devs where i live, i just read it on stackoverflow

>I'm literally retarded but I think I'll be ok

and i wouldn't even want to work for google, maybe at some cooler place like the VR dept at valve and only if i got a fat ass salary, otherwise i'd just stick to my own shit

...

installing MIt-Scheme.
The installation went smoothly
but When I type mit-scheme into the terminal I come across this error
mit-scheme: can't find a readable default option --band.
searched for file all.com in these directories:
/usr/local/lib/mit-scheme-x86-84 [/code
I'm not really sure what to do to rectify this error. Can someone please help.

> more code is easier to maintain

Disliking boilerplate code makes me retarded?

your reading comprehension skills are pretty bad, user

There really is no difference between an option type and returning two variables.

Both are effective replacements for exceptions everywhere.

>make a different but equivalent syntax for exceptions
>call it an effective replacement

It's hard to test the cause of the error in Go. You either have to use sentinel errors or wrap the errors in your own container. It feels like error codes in C, which are bad for general use.

they're not equivalent to exceptions, neither of them
only once you introduce monadic control flow to option types they become similar to exceptions, and even then, in the case of monadic option types they're still different from most exception implementations in the regard that they're actually explicit at compile time
it's debatable whether monadic control flow is a good thing in imperative languages, as it usually hides some sort of information that might be important for the reader.

nope, just saying that code duplication goes against maintainability, as does improper or insufficient abstraction.

trying to improve maintainability by not allowing abstraction is extremely retarded, for so many reasons that i'm not even sure where to begin.

>/dpt/ tells me that webdev is babby shit
>go into webdev
>within 1 year, working with streaming replication on data clusters, optimizing hive jobs and working out tricky release strategies
you lied /dpt/, I never asked for this

in both rust and go, if you want errors to both carry a context and be distinguishable in regards to their nature, you need to define an error type that contains that context.
in go you use a type assertion switch to unwrap the error into its concrete context type at runtime, while rust allows you to do this at compile time via pattern matching.
that's the only difference.
as go has no generics (which yields the advantages and disadvantages i mentioned at ) pattern matching wouldn't make much sense either.
both implementations (and exceptions as well) have a hard time when hand crafted context should get added at every layer, effectively resulting in a chain of errors, with each layer still being identifiable.

if you really believe that every dev should strive to achieve maximum DRYness then i feel sorry for your coworkers.
sometimes, duplication is better than abstraction.
this is a well known fact.
pushing a principle to its limits won't get you anywhere.
some opinions on this by other people to back up my argument:
johndcook.com/blog/2012/01/09/holographic-source-code/
twitter.com/ID_AA_Carmack/status/753745532619665408
sandimetz.com/blog/2016/1/20/the-wrong-abstraction

there are varying difficulty levels in web dev, but all this large-scale data transfer stuff just seems boring to me

i want to call a python script in my terminal, to do something to a couple files

how do i apply this script to every file, except .png images?

something like
python override.py *.jpg *.jpeg ??

python override.py *.jpg *.jpeg ^*.png

i'm not advocating removing all redundancy from your code, that's improper abstraction as well (unless you're code golfing)

ITT: go babbies defend their language giving them carpal tunnel

>muh html

>muh lambdas

alright, the general statement
>code duplication goes against maintainability
made it seem like you were.

go doesn't *prevent* abstraction, it just makes some kinds of abstraction harder, trying to push people more towards the optimum from the other side of the spectrum.
if people still persist on prematurely abstracting, even with those limitations, then the result will be incredibly ugly.
i haven't seen any cases in go projects where this was an actual issue, though.
people don't abstract that much and many people have found that to be more readable.

by the way, C attempts that in some ways as well, but fails in other regards with this approach, so there are still more opportunities to fuck things up (macros, for instance).

buttmad carpaltunnelfag detected

>if people still persist on prematurely abstracting, even with those limitations, then the result will be incredibly ugly.

Languages can't prevent "premature abstraction", they either allow certain abstractions or do not (or only in a ad-hoc interpretive manner).

Go does not allow certain abstractions even whey they are determined to not be premature.

Code duplication DOES go against maintainability. I should never have to repeat myself to the compiler.

There is no such thing as premature abstraction. The more abstract your code, the easier it is to reason about. I can tell you what hurr :: forall a b. a -> b -> a does, but not what durr :: Int -> String -> Int does. Go does indeed prevent this sort of abstraction.

>it just makes some kinds of abstraction harder
Not him, but the lack of generics prevents you from reusing your data structures.

>I'm always worried that I'll try one of these challenges, and I'll end up getting it to work, but in a really hacked together, inefficient sort of way. Am I really learning anything by doing that?

Well yeah I think so. When I do these it's usually pretty ugly. Hacky and inefficient is what learning looks like. It could, be that you're trying to find a workaround using only what you already know, but ideally it should be difficult enough that you have to learn at last one new thing to make it work. The next step is to clean it up or look at how others have solved it.

If your program is super clean and perfect first try, it's probably because you did something you're already really comfortable with and therefore learned nothing. Rolling btw.

I've been working on CS50 Problem Set 1 and my code for the greedy script where you are supposed to find whats the least amount of change you could give back to someone has been giving me weird results like putting in .41 gives you 3 when it should be 4. I've tried a lot, but I can't get it to work

#include
#include
#include

int main(void)
{
// variables
int coins = 0;
float owed;
float quarters = 0.25;
float dime = 0.1;
float nickle = 0.05;
float penny = 0.01;

// Get change
printf("How much change is owed?\n");
owed = GetFloat ();

// Math
while (owed >= quarters)
{
owed = owed - quarters;
coins++;
}
while (owed >= dime)
{
owed = owed - dime;
coins++;
}
while (owed >= nickle)
{
owed = owed - nickle;
coins++;
}
while (owed >= penny)
{
owed = owed - penny;
coins++;
}

// Print the number of coins needed
printf("%i\n", coins);
}

It has built in data structures that are generic. (YES, THE LANGUAGE HAS GENERICS, BUT YOU'RE NOT ALLOWED TO USE THEM ARRRGRARBL) I hope you never need one that they didn't include!

If it helps, I believe something is wrong when using pennies, but I can't figure it out

>float
use integers

i guess i'll agree with you on that.
there are some areas, especially in regards to types, where it's a lot easier to go overboard with abstraction than say through functions alone, and you don't notice as quickly, though.
iirc reputable fp people like erik meijer have started doubting the benefits of generics as well.
that being said, go made the argument about duplication and explicitness over abstraction more popular again (i know that sicp mentions it as well), so that's a good thing.
stuff like gofmt and other parts of the tooling are also pretty awesome, and i hope other new languages adopt some ideas from that.
the same goes for the gc.
build speed is also a good thing, in addition to the entire argument about abstraction.

>I hope you never need one that they didn't include!
Yeah, who cares about binary search trees when you can just use hash maps :^)

>currency
>floats

Erik is just butthurt because he didn't get his way regarding Foldable/Traversable being added to the prelude. "It makes teaching Haskell harder!" Use a different prelude then, dumbass.

Generics are useful for a lot more than just containers, especially when paired with typeclasses.

>The more abstract your code, the easier it is to reason about
would you say the same about abstract factory factories in java, or is that somehow a special exception to your magical and absolute rule?
what about c++, where most users use different subsets of the language, resulting in a mess when many people work together?
in fact, what about haskell, which suffers from the same problem but at a way greater scale? the last time i checked different people were handling errors in 10 different ways, and that's just error handling!
i don't think i've talked to a haskeller irl before that wasn't complaining about working with the code of other people that use a completly different set of abstraction than them.
maybe you're the first one?

>he doesn't know that currency floats

top pleb

Yes, I would. If something takes an abstract factory, then in a perfect world you know it doesn't depend on any details of concrete implementations. Unfortunately Java allows you to circumvent its generics with instanceof and reflection.

>mit-scheme is looking for all.com file in the wrong place
>can use .emacs file to change this
>.emacs file is nowhere to be found
welp

>Yes, I would
i rest my case then