Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

VikingofRock posted:

Templates cover a lot of the same functionality that you would use traits / interfaces for; just think of the constraints as being implicit from the function that you are writing ("I use the + operator here") instead of explicit ("my arguments implement Addable").

yeah, it's a very different approach. my main worry is ambiguity, it seems like you could easily have two different types that each have a "foo" method with the same input/return types but wildly different semantics. it's like duck typing.

Adbot
ADBOT LOVES YOU

VikingofRock
Aug 24, 2008




CRIP EATIN BREAD posted:

c++11 has traits as part of its stdlib

Not really in the same way that e.g. rust has traits, which is what I was talking about here. C++ traits are more like type tags; in C++ terms I'm talking about concepts.

FlapYoJacks
Feb 12, 2009

DONT THREAD ON ME posted:

yeah, it's a very different approach. my main worry is ambiguity, it seems like you could easily have two different types that each have a "foo" method with the same input/return types but wildly different semantics. it's like duck typing.

You sure can! C langs allow you to easily shoot yourself in the foot, in exchange for low level fuckery and other neat poo poo you can do.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

CRIP EATIN BREAD posted:

c++11 has traits as part of its stdlib

i saw these but it looks like they're for adding type tags to your types so you can do reflection and stuff

VikingofRock
Aug 24, 2008




DONT THREAD ON ME posted:

yeah, it's a very different approach. my main worry is ambiguity, it seems like you could easily have two different types that each have a "foo" method with the same input/return types but wildly different semantics. it's like duck typing.

This is exactly true, but in practice it doesn't really bite you too often.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

ratbert90 posted:

I was taught this about inheritance from my mentor:

Inheritance is cool and good, but can get you into trouble quickly.
If you go more than 2 levels of inheritance, you need to take a good long look at your code and probably refactor it.

yeah i believe that unless you're wrapping some framework class you should generally limit yourself to 1 level of inheritance. but it's one of those things that really depends on whether you're writing library code or not.

DONT THREAD ON ME fucked around with this message at 18:33 on Aug 31, 2018

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

DONT THREAD ON ME posted:

i saw these but it looks like they're for adding type tags to your types so you can do reflection and stuff

idk, boost's entire geometry system has a way of doing things like:

code:
#include <boost/geometry.hpp>

typedef struct my_point {
  double my_x_value;
  double my_y_value;
} my_point;

namespace boost
{
    namespace geometry
    {
        namespace traits
        {
            // indicate my_point is a point
            template<> struct tag<my_point>
            { typedef point_tag type; };

            // indicate that my_point uses double for it's coordinate values 
            template<> struct coordinate_type<my_point>
            { typedef double type; };

            // tag my_point as being in a cartesian coordinate system
            template<> struct coordinate_system<my_point>
            { typedef cs::cartesian type; };

            // indicate my_point has 2 dimensions
            template<> struct dimension<my_point> : boost::mpl::int_<2> {};

            // define getter/setter for the first dimension
            template<>
            struct access<my_point, 0>
            {
                static my_point::double get(my_point const& p)
                {
                    return p.my_x_value;
                }

                static void set(my_point& p, my_point::double const& value)
                {
                    p.my_x_value = value;
                }
            };

            // define getter/setter for the second dimension
            template<>
            struct access<my_point, 1>
            {
                static my_point::double get(my_point const& p)
                {
                    return p.my_y_value;
                }

                static void set(my_point& p, my_point::double const& value)
                {
                    p.my_y_value = value;
                }
            };
        }
    }
} // namespace boost::geometry::traits
the accessors for my_point are resolved statically, and you can now use my_point in any of the boost geometry stuff without defining any extra classes or inheritence

VikingofRock
Aug 24, 2008




CRIP EATIN BREAD posted:

idk, boost's entire geometry system has a way of doing things like:

Jesus, it's their first week of C++! Don't show them boost, you'll scare them!

FlapYoJacks
Feb 12, 2009

DONT THREAD ON ME posted:

yeah i believe that unless you're wrapping some framework class you should generally limit yourself to 1 level of inheritance.

Good man.

I guess I am a outlier in my programming tranining for sure.

I started with C, my first project was board bring-up for a TI processor running on Kernel 2.6.32-17

I was taught by a awesome EE who has been programming mostly in ASM/C/C++ for 30 years and taught me to be incredibly pragmatic.

He instilled on me:

1) Be pragmatic. If your code is clever, it's probably not a good thing.
2) It's all just memory.
3) Stick to conventions.
4) All programming languages are tools. Some better than others. (When discussing mainstream languages, poo poo like Brainfuck not-withstanding)

He's still a good friend to this day.

gonadic io
Feb 16, 2011

>>=

VikingofRock posted:

Also now that I've thought a little more on Go's shallow-copy-on-assignment, I'm a little perturbed by it. It seems to me like that breaks encapsulation a bit too much. For example, if I'm using a Point3D type, I shouldn't worry if internally the x, y, and z coordinates are stored as three separate member floats or as a single vector of three floats. But with shallow copy semantics, all of the sudden those are very different semantically if I pass a Point3D to a function and then mutate one of the coordinates.

Admittedly I've never used Go so it's possible I'm misreading the copy semantics or that there are idioms which mitigate this issue. But as I understand it it seems like a weird choice to me.

It is very easy in all languages like this to accidentally have a reference to a shared object when you thought you had a copy. C#, python, java, go.
My coworkers got bit by it in python just yesterday

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

DONT THREAD ON ME posted:

go was my first introduction to pointers and it's a confusing language to learn them in.

this is why you should stick with C for a while, it’ll beat into you exactly what’s happening under the hood because you have to think about both the language model and the machine model to make it work

also, and I know this sounds like my gimmick, but I unironically suggest doing a Luigi30 and writing a little OS in 68000 assembly using whatever that cool simulator environment was that she used

it’ll teach you an enormous amount about computer architecture, almost as much as taking a class of that title will (having done the emulator 101 thing covers the rest), and it’ll also give you a good idea of what it’s like to do development in a very cleanly designed architecture compared to all the hacked together crap we have to deal with today

gonadic io
Feb 16, 2011

>>=

eschaton posted:

this is why you should stick with C for a while, it’ll beat into you exactly what’s happening under the hood because you have to think about both the language model and the machine model to make it work

c is v good to learn pointers in, but it's for sure not what is happening under the hood at least for modern processors:
C Is Not a Low-level Language

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

eschaton posted:

this is why you should stick with C for a while, it’ll beat into you exactly what’s happening under the hood because you have to think about both the language model and the machine model to make it work

also, and I know this sounds like my gimmick, but I unironically suggest doing a Luigi30 and writing a little OS in 68000 assembly using whatever that cool simulator environment was that she used

it’ll teach you an enormous amount about computer architecture, almost as much as taking a class of that title will (having done the emulator 101 thing covers the rest), and it’ll also give you a good idea of what it’s like to do development in a very cleanly designed architecture compared to all the hacked together crap we have to deal with today

yeah i'm absolutely going to do an OS, I just want to take a little break from assembly after the emulator. so I think i'm gonna do a C++ roguelike and then the OS.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

VikingofRock posted:

Jesus, it's their first week of C++! Don't show them boost, you'll scare them!

boost is where the c++11 traits came from, lol.

in fact a lot of stuff in boost just ends up in the stdlib. pretty sure where the filesystem parts of stdlib came from in c++17.

*checks google*

quote:

The Filesystem library, ISO/IEC TS 18822:2015, provides facilities for performing operations on file systems and their components, such as paths, regular files, and directories.

...

This library is directly based on boost.filesystem, which is currently available on more compilers and platforms than this experimental technical specification.

yep

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

VikingofRock posted:

Jesus, it's their first week of C++! Don't show them boost, you'll scare them!

honestly i'm weirdly prepared for C++. On the one hand, my C and understanding of the low level machine has a long, long way to go. On the other hand, I've spent the last two years wading through Cats/scalaz/Rust so insane metaprogramming, smart pointers, move semantics, etc, are not very scary for me.

DONT THREAD ON ME fucked around with this message at 19:35 on Aug 31, 2018

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

DONT THREAD ON ME posted:

honestly i'm weirdly prepared for C++. On the one hand, my C and understanding of the low level machine has a long, long way to go. On the other hand, I've spent the last two years wading through Cats/ScalaZ/Rust so insane metaprogramming, smart pointers, move semantics, etc, are not very scary for me.

may the lord bless and protect you

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
namaste

comedyblissoption
Mar 15, 2006

DONT THREAD ON ME posted:

yeah, it's a very different approach. my main worry is ambiguity, it seems like you could easily have two different types that each have a "foo" method with the same input/return types but wildly different semantics. it's like duck typing.
this kind of typing in golang based on the structure of a type is called structural typing

as opposed to nominative typing which relies on you naming your types so you avoid the above problem

animist
Aug 28, 2018

Bloody posted:

what the gently caress

(re: why the hell i'm writing a webassembly -> verilog compiler, from a few pages back)

mainly i just want to be able to write my high-level DSP cores in rust. i don't want to actually write a rust / llvm compiler backend tho, i find llvm IR kinda exhausting, so i figure i'll just work with webassembly instead, which rust can target. it's a reasonably lightweight IR format.

more broadly, i think most languages are going to end up with webassembly backends in the near future. all the JVM languages, haskell, and typescript have wasm targets in progress right now, and i figure other people are gonna follow suit, to try to get a slice of that sweet sweet frontend pie. so, i support a bunch of languages pretty easily.

and maybe, in the future, once there's an FPGA on every cpu die, Joe Doesn't Understand Hardware can write his code in TypeScript or whatever, and use my tool to accelerate parts of it on the FPGA.

or, y'know, not. but it's a fun side project.

Xarn
Jun 26, 2015

DONT THREAD ON ME posted:

yeah, it's a very different approach. my main worry is ambiguity, it seems like you could easily have two different types that each have a "foo" method with the same input/return types but wildly different semantics. it's like duck typing.

Yup, that can definitely happen and it hurts to debug. OTOH the "ducktyping" nature of templates also means that different types from libraries that have never heard of each other can both be passed to a template as long as their "foo" method does conceptually the same thing :shrug:


In the end I firmly prefer the fact that I don't need to have things derive from Callable and can instead just provide them with operator().


----edit----
Also a free advice: Use Catch for testing :v:

Xarn fucked around with this message at 13:43 on Sep 1, 2018

Progressive JPEG
Feb 19, 2003

CRIP EATIN BREAD posted:

boost is where the c++11 traits came from, lol.

in fact a lot of stuff in boost just ends up in the stdlib. pretty sure where the filesystem parts of stdlib came from in c++17.

*checks google*


yep

when c++11 finally came out we ended up just renaming a bunch of boost types to their std equivalents. in particular shared_ptr/unique_ptr and the thread/lock types

i like boost asio a fair bit and hope something like that gets into stdlib soon

Progressive JPEG
Feb 19, 2003

DONT THREAD ON ME posted:

honestly i'm weirdly prepared for C++. On the one hand, my C and understanding of the low level machine has a long, long way to go. On the other hand, I've spent the last two years wading through Cats/scalaz/Rust so insane metaprogramming, smart pointers, move semantics, etc, are not very scary for me.

imo:
- don't use exceptions
- mark all destructors virtual
- templates are effectively a preprocessor stage
- use smart pointers everywhere (e.g. unique_ptr for members rather than raw pointers)
- don't bother with c++ streams just use the c printf stuff, unless theres something better in the last 5 years idk

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
how should I do exception handling? I'm most comfortable with Either's and saw someone recommend using them but no idea if that's a good idea or not. I'd rather learn to do what actual real programmers programming C++ do which I'm guessing is exceptions.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
all of the C++ code i've looked at so far would be bad code in other languages.

jony neuemonic
Nov 13, 2009

DONT THREAD ON ME posted:

all of the C++ code i've looked at so far would be bad code in other languages.

don't worry, it's bad code in c++ too :toot:

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.
c++ is tmtowtdi in a static language, lol

akadajet
Sep 14, 2003

DONT THREAD ON ME posted:

all of the C++ code i've looked at so far would be bad code in other languages.

same, but Java

jony neuemonic
Nov 13, 2009

i need to learn a little c++ soon, even though i mostly use unity. so much game dev material has examples in c++ so it’s not really avoidable. the last few pages are extremely relatable.

Bloody
Mar 3, 2013

animist posted:

(re: why the hell i'm writing a webassembly -> verilog compiler, from a few pages back)

mainly i just want to be able to write my high-level DSP cores in rust. i don't want to actually write a rust / llvm compiler backend tho, i find llvm IR kinda exhausting, so i figure i'll just work with webassembly instead, which rust can target. it's a reasonably lightweight IR format.

more broadly, i think most languages are going to end up with webassembly backends in the near future. all the JVM languages, haskell, and typescript have wasm targets in progress right now, and i figure other people are gonna follow suit, to try to get a slice of that sweet sweet frontend pie. so, i support a bunch of languages pretty easily.

and maybe, in the future, once there's an FPGA on every cpu die, Joe Doesn't Understand Hardware can write his code in TypeScript or whatever, and use my tool to accelerate parts of it on the FPGA.

or, y'know, not. but it's a fun side project.

post the github

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

akadajet posted:

same, but Javascript

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





DONT THREAD ON ME posted:

all of the C++ code i've looked at so far would be bad code in other languages.

congrats, you've mastered c++

Sapozhnik
Jan 2, 2005

Nap Ghost
god i really can't imagine actually voluntarily choosing to use c++ in 2018 when literally any other workable option is available

FlapYoJacks
Feb 12, 2009

Progressive JPEG posted:

imo:
- don't bother with c++ streams just use the c printf stuff, unless theres something better in the last 5 years idk

What the gently caress is this horse poo poo?

animist
Aug 28, 2018

Bloody posted:

post the github

https://gitlab.com/kazimuth/brine

pay no attention to all those PDFs stored in git-lfs that I definitely didn't rip from sci-hub

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.
cjs: parsing dates in Go

This might be the stupidest thing I've ever seen in a "standard library" outside of like brainfuck or LOLCODE.

https://pauladamsmith.com/blog/2011/05/go_time.html

quote:

Go takes an interesting approach to parsing strings to time objects, and formatting time objects as strings. Instead of using codes like most languages to represent component parts of a date/time string representation—like %Y for a 4-digit year like “2011” or %b for an abbreviated month name like “Feb”—Go uses a mnemonic device: there is a standard time, which is:

Mon Jan 2 15:04:05 MST 2006 (MST is GMT-0700)

Or put another way:

01/02 03:04:05PM '06 -0700

Instead of having to remember or lookup the traditional formatting codes for functions like strftime, you just count one-two-three-four and each place in the standard time corresponds to a component of a date/time object (the Time type in Go): one for day of the month, two for the month, three for the hour (in 12-hour time), four for the minutes, etc.

The comments on snack overflow pretty much sum it up (https://stackoverflow.com/a/25845327/221648)

quote:

Layout numbers? What? Why? Argh! – Darth Egregious Aug 5 '15 at 15:59

quote:

@Fuser97381 I share your agony... – RickyA Aug 5 '15 at 16:18

quote:

What were they thinking ! ? or smoking ? – Jishnu Prathap Mar 1 '17 at 5:02

quote:

These "layout numbers" are one of the most stupid ideas I've ever seen in my life as a developer. Christ, who ever came up with this idea needs to slap and kick himself in his nuts. – Yehonatan May 16 '17 at 6:40

gonadic io
Feb 16, 2011

>>=
my coworker: the rules don't make much sense but as soon as you learn them all go is really easy

animist
Aug 28, 2018

gonadic io posted:

the rules don't make much sense but as soon as you learn them all programming is really easy

qsvui
Aug 23, 2003
some crazy thing

Progressive JPEG posted:

imo:
- don't use exceptions
- mark all destructors virtual
- templates are effectively a preprocessor stage
- use smart pointers everywhere (e.g. unique_ptr for members rather than raw pointers)
- don't bother with c++ streams just use the c printf stuff, unless theres something better in the last 5 years idk

lol how are you so wrong on every one of these points

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
I agree on point one, C++ exceptions are atrociously bad

Adbot
ADBOT LOVES YOU

fritz
Jul 26, 2003

Progressive JPEG posted:

- don't bother with c++ streams just use the c printf stuff, unless theres something better in the last 5 years idk

https://github.com/gabime/spdlog

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply