Programming thread

>pyTorch
There's your problem!
(Only half-shitposting: most of my more frustrating programming escapades recently have been trying to get Python/Java to play nice with Machine Learning stuff.)

I dunno, what specific errors are you getting? (Or is it just not recognising that you've got CUDA configured?)

I run in Python
import torch
torch.cuda.is_available()

and get "False".

CUDA is installed but I really don't know how to check if it's working, never used it or installed it before today.

I would have posted this in the "No stupid questions thread" but this seemed like a better thread.
 
I run in Python


and get "False".

CUDA is installed but I really don't know how to check if it's working, never used it or installed it before today.

I would have posted this in the "No stupid questions thread" but this seemed like a better thread.
Would you be able to verify that CUDA's working by running the sample programs (detailed here?)

Otherwise, it seems like a lot of people have documented issues with pyTorch being finicky about the version of CUDA that it wants to recognise (e.g. the discussions here and here). So another thing you could check is to try reinstalling the pyTorch modules but forcing your specific version of CUDA, e.g. if you're using 9.2 you'd pip3 it with
Bash:
pip3 install torch==1.3.1+cu92 torchvision==0.4.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html
(i.e. note the +cu92 bit.)

EDIT: Glad you got it working! :heart-full:
 
>pyTorch
There's your problem!
(Only half-shitposting: most of my more frustrating programming escapades recently have been trying to get Python/Java to play nice with Machine Learning stuff.)

I dunno, what specific errors are you getting? (Or is it just not recognising that you've got CUDA configured?)

FIXED IT!

My mistake was checking if CUDA was available or not. I should have checked the device name that CUDA wasn't available on. Doing that made torch tell me that the display driver was too old. What? It's true, I don't update drivers too often so I went into the Nvidia control panel to check my driver version. It wasn't there. The fucking CUDA installer seems to have uninstalled my display driver and returned it to some basic window compatibility driver!
That explains why scrolling pages were suddenly so choppy after installing it.
 
I agree with you about plain C, but what about C++?
C++ has changed a lot over the years. More traditional C++ programming has much of the same problems as C. And of course there's the old C++ FQA if you want to read some pretty accurate criticisms of past versions of C++ (by someone with a *lot* of time on their hands).

People trying to be more modern usually end up copying a lot of data instead of using new/delete. They try for RAII stuff that ends up getting copied back and forth in a tight loop everytime they call some function.

At least that's what I saw people doing last time I dealt with C++, which has been awhile. Lol I can't imagine the crazy bugs people will get stuck with with the lambda expressions they added to C++.
Besides, other than Rust, I can't think of any language remotely as fast as C/C++.
Hmm, Forth might be competitive. Forth is really fascinating.

I'm a big fan of functional programming (been fucking around with Ocaml recently) for my personal projects. SML is an older, less popular relative of Ocaml, and it's a GC'd language that managed to outperform C++ in a pretty good benchmark (a 3d raytracer). It's a pretty interesting read.

But yeah, a language in common use? Probably isn't one. But raw speed is rarely the cost-sensitive aspect. It's almost always human costs. It costs more money to pay for developers to write less abstract programs (C/C++ is lower level than other languages, so refactoring takes longer and more brainpower) and to debug those programs.

If you really do need speed in a particular part of your program (and it's rare that you can successfully eyeball it, you really should be benchmarking), then you should first try writing the fast parts in C and linking them into your higher level language as a library.
Though you likely have several times my programming experience so I'm not going to pretend I know more than you.
I program professionally, so I approach these issues from a different perspective. I approach them from the perspective of getting something done while expending less resources. And the most costly resource is my time.

Now if you're working on something for fun, you can use whatever language you want. It can be enjoyable to get down in the nitty-gritty.
 
This discussion has gone way too technical - this is not stackoverflow, faggots; Here are my tips for succeeding in IT, tried and tested:
1) Don't be afraid to lie on your CV, fake it until you make it, worst thing, that can happen is that you do not get the job - tried and tested by yours truly, worked for me when I moved from support monkey to dev, I've now worked on several multi-million projects successfully.
2)DO NOT call yourself a programmer if you have above the average ability AND some experience - you're a "developer". "Programmer" is essentially someone. who places text boxes on the screen as directed by his betters, "Developers" and "Architects" are deciding if this textbox is needed in the first place and command the premium salary over the lowly "programmer".
This brings up a question I'd like to throw to the wider audience - when do you get to call yourself a Senior Developer on your CV / Linkdin?
But yeah, a language in common use? Probably isn't one. But raw speed is rarely the cost-sensitive aspect. It's almost always human costs. It costs more money to pay for developers to write less abstract programs (C/C++ is lower level than other languages, so refactoring takes longer and more brainpower) and to debug those programs.
You can always use Golang and hate life. It's depressing to use.
 
idk guys, personally, I like C/C++, although it's a bit of pain to debug C.

But C has this amazing quality that after programming for a while in C every other language feels like playing Lego, while being patted on the head by a patient IDE. (maybe it doesn't hold true for them fancy functional programming languages but I am a simple gorilla, so I wouldn't know)

The reality is that lots of software was built in C and if one has any ambition to make things more secure, he/she needs to learn this mf inside out.
 
The reality is that lots of software was built in C and if one has any ambition to make things more secure, he/she needs to learn this mf inside out.
Security bugs in C software flow one way: from writing the software to using the software. No knowledge of C changes running the software.

Any piece of software can be immediately made more secure by writing it in a memory safe language. No knowledge of C is necessary.
 
  • Agree
Reactions: hauser
You can always use Golang and hate life. It's depressing to use.

what's depressing about it? I heard about it, as it is often mentioned side by side with rust (and D, sometimes), but never looked into it. though it has gained rapid traction compared to rust and D, so presumably it must be doing something right.
 
I'm a big fan of functional programming (been fucking around with Ocaml recently) for my personal projects. SML is an older, less popular relative of Ocaml, and it's a GC'd language that managed to outperform C++ in a pretty good benchmark (a 3d raytracer). It's a pretty interesting read.
If you want to find out what still sets Ocaml and SML apart in the world of typed functional programming, look into its module system, which, out of every approach to modular programming I have used, is hands down the best (assuming you care about static type-safety).
 
Security bugs in C software flow one way: from writing the software to using the software. No knowledge of C changes running the software.

Any piece of software can be immediately made more secure by writing it in a memory safe language. No knowledge of C is necessary.

OK then. Good luck with rewriting all operating systems and drivers! Also don't forget to rewrite Apache HTTP server and Nginx!
 
  • Like
Reactions: Strange Looking Dog
The WinForms portion of Mono is plagued with show stopping bugs, and is basically unmaintained. I regularly use a bunch of WinForms based mono applications on Linux and they're constantly crashing just due to minor interactions with the window manager. I have to baby them by basically never resizing their windows, and avoiding touching the super key. Seriously.

The devs just shrug when bug reports come in, saying no one is working on that code.

Examples: Mesen, KeePassX, CKAN, they all have the exact same crashing bugs. Fortunately I moved to KeePassXC but I still use Mesen and CKAN.
Check out WinUI.
 
  • Informative
Reactions: Strange Looking Dog
what's depressing about it? I heard about it, as it is often mentioned side by side with rust (and D, sometimes), but never looked into it. though it has gained rapid traction compared to rust and D, so presumably it must be doing something right.
You know the saying "if you make something idiot proof, someone will make a better idiot"?
Go feels as idiot proof as a padded room. It's mind numbing to write in. It was written by very intelligent people who think (and are probably right) that others aren't as smart as they are and shouldn't be given shotguns to blow their own faces off with.
Or maybe I'm just a Smug Lisp Weenie
 
If you want to find out what still sets Ocaml and SML apart in the world of typed functional programming, look into its module system, which, out of every approach to modular programming I have used, is hands down the best (assuming you care about static type-safety).
Oh totally. Their module/type systems are top notch. Shit like functors.

Ocaml also has first class modules which are kind of hinky in theory, but once in awhile I find them essential. Usually when implementing something that needs like plugin support. ie you can pick which implementation you want to use.
OK then. Good luck with rewriting all operating systems and drivers! Also don't forget to rewrite Apache HTTP server and Nginx!
You said that knowing C is important because everything is written in it. But that's untrue. You can use apache and nginx and the linux kernel without knowing C. Not knowing C doesn't affect your ability to use them securely.

Furthermore, my second point was that when you're writing new software, you can always make better software by writing it in memory safe languages.

Heh, and actually, while most of my mundane stuff runs behind nginx, I'm looking at unikernels for my more experimental stuff. Like, virtually all common web facing languages implement their own http server. And with unikernels, they aim to do what you're saying: reimplement the whole kernel and drivers and low level code as well, specifically in a memory safe language.

The reason this is feasible is because for the past 10 years (at least), we've been running all our servers as virtualized servers. One computer with like 16 cores that presents virtualized hardware to 16 OS instances. They don't have to deal with 500 different network cards (and thus 500 different drivers). They just deal with the same generic virtualized version.

And this is a much more reasonable environment to program against.

I mean, sure, you might need to deal with C sometimes and it might be useful to know. idk
You know the saying "if you make something idiot proof, someone will make a better idiot"?
Go feels as idiot proof as a padded room. It's mind numbing to write in. It was written by very intelligent people who think (and are probably right) that others aren't as smart as they are and shouldn't be given shotguns to blow their own faces off with.
Or maybe I'm just a Smug Lisp Weenie
I really like how it approaches error handling. Javascript's use of exceptions makes me want to tear my hair out.

Otherwise it's generally fine for things I'd want type safety for. (I'd prefer other languages, but if my boss requests Go over Javascript, I'm happy.)
 
Oh totally. Their module/type systems are top notch. Shit like functors.
It's always cool when people implement Category Theory concepts. If you're ever curious there are two Clojure libraries which have also done that: Cats (geddit?) and fluokitten (starting to think felines are a theme here).
Otherwise it's generally fine for things I'd want type safety for. (I'd prefer other languages, but if my boss requests Go over Javascript, I'm happy.)
Seems like a pretty obvious choice between the two. I won't deny the retarded little gopher can go, or that the language isn't pleasant, in the way pastel colors are. I might have even enjoyed it had I found it years ago, but as to where I am now, it just sucks ass to write in. I can die of the sheer boredom. At least C has the excitement of the chance you fucked yourself royally.
 
Oh totally. Their module/type systems are top notch. Shit like functors.

Ocaml also has first class modules which are kind of hinky in theory, but once in awhile I find them essential. Usually when implementing something that needs like plugin support. ie you can pick which implementation you want to use.
I'd be interested in hearing more of your needs here. I'd think you could do near enough everything you want of a plugin architecture with ordinary modules. What you couldn't do is have modules computed at runtime and hotloaded, but I'm not sure if first-class modules can do that anyway (though I am currently using them in exactly this way, hotloading new implementations into a TCP server from the toplevel).

The theory is straightforward though, and I suspect was an obvious extension once Ocaml got GADTs, which cover much of the same bases in the underlying type-theory.

It's always cool when people implement Category Theory concepts.
It's not category theory in this case. "Functor" is badly overloaded in programming. Prolog always used it to refer to the head symbol in a structured term, which happens to be the closest usage to Carnap's, who originally coined the term. C++ programmers use "functor" to refer to objects which implement the "()" operator. Ocaml and SML use "functor" to refer to functions of modules.

Haskell uses "functor" closest to the category theory sense, in a way which mostly pisses off working category theorists, because Haskell isn't category theory. Haskell's functors are a massively narrowed idea of functors, being only those from the category Hask to itself. And beligerent Standard MLers who are serious about category theory will further point out that Hask isn't even a fucking category.

All of this stuff is fairly labelled autistic, and I think we need to spend more time explaining why it's cool to implement concepts from category theory, aside from scaring away idiots:

Go feels as idiot proof as a padded room. It's mind numbing to write in. It was written by very intelligent people who think (and are probably right) that others aren't as smart as they are and shouldn't be given shotguns to blow their own faces off with.
Y'know who Rob Pike had in mind for his target market of idiots? Fucking Googlers.

"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."

The software industry was fucked decades ago. It's long been idiocracy.
 
"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."

is that an actual quote? jesus fucking christ.
 
I'd be interested in hearing more of your needs here. I'd think you could do near enough everything you want of a plugin architecture with ordinary modules. What you couldn't do is have modules computed at runtime and hotloaded, but I'm not sure if first-class modules can do that anyway (though I am currently using them in exactly this way, hotloading new implementations into a TCP server from the toplevel).

The theory is straightforward though, and I suspect was an obvious extension once Ocaml got GADTs, which cover much of the same bases in the underlying type-theory.
Code:
open Core

module Let_syntax = struct

  let bind _ _ = failwith "debug finish"

end

type payload = string

module type PROTOCOL = sig
    type conn
    val open_connection : string -> (conn, Error.t) Lwt_result.t
    val pull            : conn -> (payload, Error.t) Lwt_result.t
    val push            : conn -> payload -> (unit, Error.t) Lwt_result.t
    val close           : conn -> (unit, Error.t) Lwt_result.t
  end

module RTMP : PROTOCOL = struct

    (* ... etc *)

end

module HLS : PROTOCOL = struct

    (* ... etc *)

end

module MPEGDASH : PROTOCOL = struct

    (* ... etc *)

end

let protocols = [
  "rtmp",      (module RTMP : PROTOCOL)
 ;"hls",       (module HLS : PROTOCOL)
 ;"mpeg-dash", (module MPEGDASH : PROTOCOL)
]

let stream (src_protocol, src_addr) (dst_protocol, dst_addr) =
  let (module Src_protocol) = List.Assoc.find_exn protocols ~equal:(=) src_protocol in
  let (module Dst_protocol) = List.Assoc.find_exn protocols ~equal:(=) dst_protocol in

  let%bind src = Src_protocol.open_connection src_addr in
  let%bind dst = Dst_protocol.open_connection dst_addr in

  let rec iter () =
    (* I should probably do something more complicated to close the other
       connection in the case of any errors... but this is good enough for
       this example *)
    let%bind payload = Src_protocol.pull src in
    let%bind ()      = Dst_protocol.push dst payload in
    iter ()
  in

  iter ()
Something like this.
 
Code:
let protocols = [
  "rtmp",      (module RTMP : PROTOCOL)
 ;"hls",       (module HLS : PROTOCOL)
 ;"mpeg-dash", (module MPEGDASH : PROTOCOL)
]
Since there are only nine combinations, you could make stream a functor of its source and destination protocols, and then define nine stream functions in terms of the Stream functor, each with the appropriate one-liner. Better would be to find a way to get the choice into your build configuration, if protocol choice is possible to know before runtime. But if you want to stick with the more dynamic approach, you could replace your protocol module with a record type:

Code:
type conn =
  { pull : unit -> (payload, Error.t) Lwt_result.t
  ; push : payload -> (unit, Error.t) Lwt_result.t
  ; close : unit -> (unit, Error.t) Lwt_result.t }

val open_connection : string -> (conn, Error.t) Lwt_result.t

You implement "open_connection" by having it return records with the appropriate functions. If you want to keep the existing modules, that's just:

Code:
let open_connection prot str =
  match prot with
  | "rtmp" ->
      let open RTMP in
      let%bind conn = open_connection str in
      let pull () = pull conn in
      let push = push conn in
      let close () = close conn in
      Lwt_result.return {pull; push; close} )
 
Back