programming

311 readers
1 users here now

  1. Post about programming, interesting repos, learning to program, etc. Let's try to keep free software posts in the c/libre comm unless the post is about the programming/is to the repo.

  2. Do not doxx yourself by posting a repo that is yours and in any way leads to your personally identifying information. Use reports if necessary to alert mods to a potential doxxing.

  3. Be kind, keep struggle sessions focused on the topic of programming.

founded 2 years ago
MODERATORS
101
102
103
104
105
106
107
108
109
110
1
Intro - Operating System in 1,000 Lines (operating-system-in-1000-lines.vercel.app)
submitted 2 years ago by git@hexbear.net to c/programming@hexbear.net
111
112
113
1
submitted 2 years ago* (last edited 2 years ago) by zongor@hexbear.net to c/programming@hexbear.net
 
 

Hello all, i'm trying to figure out a language syntax and I keep going in circles, maybe some opinions from other devs may help.

For a given programming language what is the most efficient & cleanest way of describing a variable, type, etc?

Here is a list of ones I have considered. (psudocode)

C style (structs and return type prefix), pros: simple, really succinct, cons: annoying lexing because return type is ambiguous.

struct Vec3 {
  f32 v[3];
}
struct Player {
  char *username;
  Vec3 pos;
  Color appearance;
}
Player[] login(Player p, char *password) {
...
}
Player me("me", Vec3(0.0,0.0,0.0), Color(255, 0, 0));
login(me, password);

Rust style (function prefix, arrow return type), pros: separation of data and implementation makes composition easier. Cons: not very intuitive for learners.

struct Player {
  username: str,
  pos: Vec3,
  appearance: Color,
}
impl Player {
  fn login(self, pass: str) -> Vec<Player> {
  ...
  }
}
let me: Player = Player {username="me", ...
me.login(password);

Typescript style (similar to rust but without arrows, also OOP). pros: simple, easy to understand. cons: OOP can cause problems

class Player {
  username: string;
  pos: Vec3;
  appearance: Color;
  constructor(username: string, pos: Vec3, appearance: Color) {
    this.username = username;
    ...
  }
  login(password: string):Player[] {
  ...
  }
}
let me: Player = Player(...
me.login(password);

Fortran style (types below definition). Pros: clear whats going on? (maybe too used to fortran weirdness). Cons: extremely verbose.

type player
  string :: username
  real(kind=32), dimension(3) :: pos
  integer(kind=8), dimension(3) :: appearance
contains
  procedure :: login
end type player

player function init_player(username, position, appearance) result(this)
      string :: username
      real(kind=32), dimension(3) :: position
      integer(kind=8), dimension(3) :: appearance

      this%username = username
      this%position = position
      this%appearance = appearance
end function

function login(this, password) result(players)
  class(player) :: this
  string :: password
  player, dimension(:), allocateable :: players
  ...
end function
...
player :: me
me = Player("me" ...
me%login(password)

Go style, types after like rust/typescript but no :, interfaces instead of OOP, prefix types on the left of functions. Slices also backwards. Pros: simple, cons: syntax is backwards and weird, implementing a tupe would be annoying.

type Player {
  username string
  position Vec3
  appearance Color
}
func (p Player) login(password string) []Player {
...
}
me := Player("me" ...
me.login(...

Let me know what you think, thanks all!

114
115
116
 
 

Idk how many of you had to/have to write highly concurrent code in languages but I saw "Race Condition" today and panic'd

@Enjoyer_of_Games@hexbear.net @Speaker@hexbear.net @gay_king_prince_charles@hexbear.net @iByteABit@hexbear.net @PaX@hexbear.net

117
118
 
 

Spent day 16 trying to get elixir working with emacs. Hope you all are doing well with the current problem.

17 looks fun, its building a 3 bit VM. Maybe Ill start skipping around instead of going in order.

@Enjoyer_of_Games@hexbear.net @Speaker@hexbear.net @gay_king_prince_charles@hexbear.net @iByteABit@hexbear.net @PaX@hexbear.net

119
1
submitted 2 years ago* (last edited 2 years ago) by KnilAdlez@hexbear.net to c/programming@hexbear.net
 
 

I recently had to deal with debugging chatgpt code, and though it was written clearly, it just seemed so ugly and hard to read to me. So I started to think about what I like and what I don't like when reading code. My personal guidelines for beautiful code are:

  • space out code into functionally similar chunks. That way it's easy for my eyes to separate the steps of the code. (Often this is code that is only used once, so there is no need to put it in it's own function)
  • comments are for clarity, and too many make clarity worse.
  • similarly, doc comments in 2024 need to be completely rethought. I already have the actual documentation open on my screen most likely, no need to put the same information in your code. (yes, I know that java and others generate documentation from doc comments, and I don't like it)
  • functions should be ordered by order of execution. Reading down the code should be like reading a book, telling the story of the code's execution. For an OOP language this should pretty well line up with layers of abstraction as well.
  • python should be wiped from the face of the earth.
  • self-documenting code (which is to say code with very long variable names) is bad practice. Once again, the code should be able to be read like a book, you wouldn't name the protagonist of Lord of the Rings 'Ring_barer_to_mordor_hobbit' just name variables something memorable and useful and move on.
  • of course, the opposite, variables just named something meaningless like 'a' should only be used in the most limited of scopes. Loops, lambda functions, etc.
  • There should be consideration for how the code flows on the screen
  • curly brackets in C-like languages should always have their own line, with the exception of the start of functions and short if/else statements.

I don't know, these are just things that I have noticed I like to see in code. This could be the ravings of a lunatic as well.

spoilera tab is 2 spaces

120
1
Advent of Code 2024 Day 15 (adventofcode.com)
submitted 2 years ago* (last edited 2 years ago) by zongor@hexbear.net to c/programming@hexbear.net
121
122
 
 

Hey all sorry I haven't posted in a bit, lifes gotten a bit hectic but im back to posting, hopefully daily. Heres a thread for the last few days, haven't been able to look at them at all but might switch from Elixir to something I know like Go just to make it a bit easier.

@Enjoyer_of_Games@hexbear.net @Speaker@hexbear.net @gay_king_prince_charles@hexbear.net @iByteABit@hexbear.net @PaX@hexbear.net

123
 
 

Its antenna time. Maybe its just a me thing but the input reminds me a lot of Rogue/Angband?

@Enjoyer_of_Games@hexbear.net @Speaker@hexbear.net @gay_king_prince_charles@hexbear.net @iByteABit@hexbear.net

124
 
 

Time to fix the rope bridge. Hope everyone has had time to do this, I got sidetracked and now am super behind.

@Enjoyer_of_Games@hexbear.net @Speaker@hexbear.net @gay_king_prince_charles@hexbear.net @iByteABit@hexbear.net

125
 
 
view more: ‹ prev next ›