/dpt/ - Daily Programming Thread

Special FRACTRAN edition.

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

youtube.com/watch?v=EvtkPpZVaU
youtube.com/watch?v=EvtkPpZVaU8
jacobmartins.com/2016/03/07/practical-golang-using-websockets/
godoc.org/github.com/gorilla/websocket
twitter.com/NSFWRedditGif

is the cost of golang GC worth it for a less pozzed community than rust has?

Python is the best programming language for 99% of all real life use cases.

why doesn't this work?

(define (length list)
(fold 1 + list))

Neither of the two languages are ready to be put into production yet. Both are too annoying to use as hobby languages. Quite frankly they're both worthless, but golang has a better shot at becoming good.

t. someone who doesn't know shit about how the world works.

and the other 1% of programming tasks are: implementing python.

what should I use for web apps in production though? NOT PHP. I don't want ruby or any script stuff either desu.

youtube.com/watch?v=EvtkPpZVaU

Write a program RIGHT NOW that has two parallel threads battling for control over a variable.
Thread 1 increments it, then waits a given number of seconds.
Thread 2 decrements it, then waits a given number of seconds.
The program terminates after a given time.

GO!

video gone.

who /kodes with karlie/?

Probably C#, Java, nodejs or something like that unfortunately. I'd prefer golang but the chance of running into a situation where you get stucked because of language limitations is just too high.

X=0
function incr() {
sleep 1
X=($X + 1)
incr
}
function decr() {
sleep 1
X=($X - 1)
decr
}
incr &
decr &
sleep 60
echo $X
exit

youtube.com/watch?v=EvtkPpZVaU8

>You know immediately what the code is doing
No I don't.
If anything I would assume that it's checking whether the two variables point to the same object, using the == as an iterative comparative is pretty fucking obtuse.

> Copied from the last thread
Anybody have any experience with serverside chat programs? I originally went with XMPP, but it really is an outdated piece of shit. Most of the use cases aren't valid for modern chat applications.

I'm sick of reading/wrestling with the stupid XMPP protcol so I'm going to go ahead and write my own.

I'm torn between using Node.js and Python on the serverside. Is that a bad idea? I really don't care about scalability and overall performance as the chat app is going to have a very small user base.

IRC is way simpler.

Whats the deal with the Golang hype?

func thread(chNum chan

People are actually giving it two seconds of time to play around with and finding that it's pleasant to work in, but it's underdeveloped as hell in terms of packages so people used to import disease are too confused to do anything

yeah but IRC has even less featues than XMPP. I need to implement chat history, static roster, static group chat, and a bunch of other features that really are specific to my situation.

BUT MUHH GENERICSS

>used a channel instead of passing a variable reference
I'm a fucking idiot

It has a garbage package system. And I wouldn't call it pleasant with all the if err != nil stuff.

write your own IRC server

The package system is stupid (relying on github? seriously?), setting up the environment is the worst experience I have ever fucking had with any language I've ever even heard of, and if you're not careful the if err != nil does get really out of hand.
But once you get used to handling errors in tiny chunks instead of giant, wrapped try/catch/finally blocks it's got some advantages.

you can also just ignore errors if you're feeling ballsy by using _ in place of err, unlike say Java or C# that will yell at you if you try and do unsafe behaviors.

>preferring "no micro-aggressions" to gay technology
>comparing two languages which are nothing alike outside of their tokenizers
How about you just get back to Sup Forums and stop programming entirely.

Why go through all the headache of implementing a shitty standard when I can just write something up quick to work?

why can't women program, Sup Forums?

Why do anything at all? Why not just import irc in a python script thats 4 lines long and call yourself a programmer?

>relying on github? seriously

It doesn't rely on any particular website.

>setting up the environment is the worst experience I have ever fucking had with any language I've ever even heard of,

Setting an environment variable in .bashrc is the worst experience you've ever had?

>C#, Java
>stucked because of language limitations
Did you get dropped on your head as a baby? If you can't work around a language's limitations, you might be actually retarded. Node.js is a good choice over Go though. Same speed, less autism.

Why can't heterosexuals program.*
ftfy

>Setting an environment variable in .bashrc is the worst experience you've ever had?
I'm referring to the completely insane Gopath system, where all your projects have to be stored and developed inside that bizarre hierarchy, lest you don't want it to compile or run if you try and split it apart into packages.

>smol pterodactyl
>the same dipshit that got fired from nintendo over gaymurg8 whining
Women.

I'm talking about why implement the standard at all? If it doesn't have defined protocols for the features I want/need then it's pretty useless, correct?

At that point it's more worth my time to just write my own protocol.

I didnt actually read your prior posts. If you're going to write a protocol then the language doesnt really matter, but both Javascript and Python are cancerous trash, especially for network based work, and you should avoid them if you can.

Ah. I never break anything out to be used as a standalone package so I'm usually content to just have a folder of source files wherever and run go build.

Another poster suggested I use Go, but I see a lack of support for a lot of the web-based protocols (no standard websocket implementation).

What do you suggest?

>fired from nintendo over gaymurg8
It's better than that, user. Back then it was found that she was moonlighting as a hooker, and Nintendo, a company that markets to children, for some reason decided they didn't want a literal whore working PR for them.

I've ended up just lumping every separate file under the main package.
I also hate that packages are meant to be totally reusable chunks of code, instead of letting me separate and organize code within a specific project.

Go lacks a lot of official implementations of stuff, but the ease of its threading and its fairly robust HTTP package make it a decent choice.
jacobmartins.com/2016/03/07/practical-golang-using-websockets/

But if not that, Java, C#, C++ are all great choices with very well developed websocket libraries. C if you're feeling ballsy.

If you're gonna use go I'd implement it over H titty pees.

Why does it need to be part of the standard library?

It doesn't have to be, but it would be a plus. Standard library usually means continued support, nice docs, gradual improvements, etc.

>static roster
>static group chat
what do you mean by these
you can implement chat history in ircv3 using the server-time extension and clients that support it will automagically work

The current favored implementation is part of a fairly longstanding collection of web programming packages in go, and has the blessing of the golang devs who haven't yet moved their version from experimental status into the standard library of the language.

godoc.org/github.com/gorilla/websocket

I think it has all those qualities you mentioned.

It's basically C for webdev/servers with a GC

@60947445
>MUHH

what's the difference in semantics in OOP languages between these two expressions?
foo.doOp();

and
doOp(foo)

if doOp is a virtual function then that leads to a dynamic resolution at runtime.

which dialect is this

require 'fiber'
require 'gosu'
module GRPG
class Scene
def initialize
@fiber = Fiber.new {loop {update}}
end
def update
Fiber.yield
end
def resume
@fiber.resume
end
def draw; end
def done?; end
def bring_out; end
def bring_in(data); end
end
class Overlay < Scene; end
class Transition < Overlay
def coming_back?; end
end
@scenes = []
def scene
@scenes.last
end
def open_scene(scene_class)
@scenes.push(scene_class.new)
end
def close_scene
@scenes.pop
end
def change_scene(scene_class, transition_class = nil)
bring_over = scene.bring_out
if transition_class
open_scene(transition_class)
current_transition = scene
Fiber.yield until scene.coming_back?
end
close_scene
close_scene if transition_class
open_scene(scene_class)
if transition_class
@scenes.push(current_transition)
Fiber.yield until current_transition.done?
end
scene.bring_in(bring_over)
end
def done?
@scenes.empty?
end
def update
scene.resume
close_scene if scene.done?
exit if done?
end
def draw
to_draw = []
@scenes.reverse_each do |drawing|
to_draw.push(drawing)
break unless drawing.kind_of?(Overlay)
end
to_draw.reverse_each(&:draw)
end
def start_game(title, scene_class)
open_scene(scene_class)
(Class.new(Gosu::Window) do
def initialize(title)
super 640, 480
caption = title
end
def update
GRPG.update
end
def draw
GRPG.draw
end
end).new(title).show
end
end

...

you should put another Fiber.yield in the loop after the call to update so you don't have to conclude every Scene#update override with Fiber.yield

I have this in my program

printf("Range of unsigned int is 0 to %d \n", UINT_MAX);

The result I get is

Range of unsigned int is 0 to -1

That doesn't make sense. Why is this happening?

thx breh

ARRRRGGHH F-FIRST FOR F-FORTRAN

%u

Also you forgot to prefix every method name in GRPG with "self"

shit thx muh dude
is this better?
require 'fiber'
require 'gosu'
module GRPG
class Scene
def initialize
@fiber = Fiber.new {loop {update; Fiber.yield}}
end
def resume
@fiber.resume
end
def update; end
def draw; end
def done?; end
def bring_out; end
def bring_in(data); end
end
class Overlay < Scene; end
class Transition < Overlay
def coming_back?; end
end
@scenes = []
def self.scene
@scenes.last
end
def self.open_scene(scene_class)
@scenes.push(scene_class.new)
end
def self.reopen_scene(existing_scene)
@scenes.push(existing_scene)
end
def self.close_scene
@scenes.pop
end
def self.change_scene(scene_class, transition_class = nil)
bring_over = scene.bring_out
if transition_class
open_scene(transition_class)
current_transition = scene
Fiber.yield until current_transition.coming_back?
end
close_scene
close_scene if transition_class
open_scene(scene_class)
if transition_class
reopen_scene(current_transition)
Fiber.yield until current_transition.done?
end
scene.bring_in(bring_over)
end
def self.done?
@scenes.empty?
end
def self.update
scene.resume
close_scene if scene.done?
exit if done?
end
def self.draw
to_draw = []
@scenes.reverse_each do |drawing|
to_draw.push(drawing)
break unless drawing.kind_of?(Overlay)
end
to_draw.reverse_each(&:draw)
end
class GameInstance < Gosu::Window
def initialize(title)
super 640, 480
caption = title
end
def update
GRPG.update
end
def draw
GRPG.draw
end
end
def self.start_game(title, scene_class)
open_scene(scene_class)
GameInstance.new(title).show
end
end

Thanks. Follow up question why would this work then?

printf("Range of unsigned char is 0 to %d \n", UCHAR_MAX);

I get

Range of unsigned char is 0 to 255

yo computer fuked up my nig

what do you guys do when you're bored? Vidya isn't cutting it.

An int is wider than a char. Yes the %d indicates a signed value, but specifically it indicates a signed int, and the largest unsigned char can easily fit in a signed int without overflow.

read

%hhd will interpret the arg as a signed char and print -1.

write tracker music

regardless this won't do what you want

It's basically hipsters migrating from Python. The idea behind go is to create a language that is even more basic than C. And since the biggest issue so companies like Google is that you cannot find 30000 competent programmers (in an environment where 100 other companies are trying to do the same), they think it's a great idea how to make morons productive. Kinda like Python, really. Of course it has its mandatory fuckups like any hipster language, but nobody cares because it's used by morons (i.e. same people who see no issue with server-side javascript).

urethral sounding

Anal masturbation.

Currently doing my exercise for implementing a Binary Tree in Java.

Writing the logic for deleting a Node surely was interesting...

But while I was writing it I really would have liked to have C++ References in Java.

But because I didn't had that and didn't want to work out some hacky over complicated way over reflection I just put the two child nodes into an array and worked with the indices.

class Bar:
bars = 0
def __init__(self):
Bar.bars += 1
self.id = Bar.bars
print "Created object #%d of class Bar." % self.id
def doOp(self):
print "Object #%d is doing something." % self.id

def doOp(Foo):
print "Object #%d is doing something." % Foo.id

try:
Foo.doOp()
except Exception as e:
print e
try:
doOp(Foo)
except Exception as e:
print e

Foo = Bar()

try:
Foo.doOp()
except Exception as e:
print e
try:
doOp(Foo)
except Exception as e:
print e


No practical difference, but:
If Foo doesn't exist, then the doOp() functions still exist (in Python, everything is an object, including functions). Foo.doOp(), however, does not even exist until Foo does. So depending on what you want to do and how you like to handle errors, you might prefer one or the other. Foo.doOp() would be preferable if you're trying to stick to OOP.

C++ references are shit. Either use pointers or use values.

fixed, the transition class's fiber was hogging the fdsorgaeh
i moved the scene switching code to the transition class's update method so that even though it hogs the hndgtnfhsg it won't be a probelm

explain

You can probably break this up into two procedures.

But only a retard who can't understand languages other than C would do that.

They are literally invisible state changes.

References, except rvalue references as parameters and const references as parameters, do nothing but harm readability

Why? From my understanding references are worked out by the compiler to pointers anyway. They are just easier to use while coding because you don't have to constantly de-reference them

vector stuff;

for (T t; cin>>t; stuff.push_back(t));
or
for (T t; cin>>t; ) stuff.push_back(t);

Is there any actual difference?

Why don't you disassemble them and find out for yourself?

>uses ruby
>is a dumb frogposter
why am i not surprised

>posts in /dpt/
>is a dumb animeposter
why am i not surprised

How do they harm readability? What state do they change? You aren't explaining any of your reasoning.

>posts in /dpt/
why am i not surprised

>not suprised
why am i posting

>posts
why am i not surprised

How do i start to lear python?

By reading a book. Try Automate the Boring Stuff with Python.

Learn Lisp. Then write a big read macro so Lisp can parse Python.

Reminder that this is still true

>complains about anime on a mongolian wood carving website

Go has both good performance and fast development though.

In managed languages like C# and Java, is avoiding unnecessary branching still important like it is in compiled languages?
Like in C if you can help it you should avoid branching because it's much slower when compiled, but C# and Java run in virtual environments so I don't know if they have the same performance hit

Nope, it has neither.

It can never have good performance as long as it has a GC. It can never have good performance as long as it has a cripplingly limited and restrictive type system.

>I don't want to actually look up benchmarks or read anything, so I'll just say garbage collection is inherently bad

Value semantics should coincide with value syntax. Reference semantics should coincide with reference syntax.
y.mutate(); // Will this cause side effects elsewhere in the program? Who knows until you check the declaration of y.

doThing(x); // In plain C, I know this won't modify my x. You don't know that in C++ until you check the declaration of doThing.
doOtherThing(&x) // In plain C, the implication is that x will be modified. C++ should have stuck to this.

Reference semantics are dangerous and should be marked clearly with reference syntax. Obscuring action at a distance so you can save a few characters explicitly dereferencing is brain damaged and cancerous.

How many languages should top programmers know?

What are you talking about, garage collection IS inherently bad. What would you even do it for. Think about all the people who don't even have a place to live and you're just sitting on your ass fucking accumulating garages. You know, when you can only drive one fucking car at a time. Jesus christ.