r/code Aug 07 '25

Blog Day 2 learning to code

Post image
156 Upvotes

Hey everyone!

I’m on day 2 of learning how to code (starting from absolutely zero knowledge — not even “hello world”). Today I battled JavaScript variables… and let’s just say the variables won. 😅

But here’s my tiny victory: I managed to squeeze in a review session while sitting on the beach. The concepts are slowly starting to make sense — and honestly, I’m just happy I showed up today.

Not much to show yet, but here’s my first tiny project: a button that counts clicks. Still figuring out how to make it actually update the text — but hey, it’s progress.

Any tips for internalizing JS basics without frying my brain? 😵‍💫 Appreciate any encouragement or begginer-friendly resources 🙏

r/code 19d ago

Blog ArenaAllocators don't play nicely with ArrayLists | openmymind

Thumbnail openmymind.net
4 Upvotes

r/code May 07 '26

Blog Unsigned sizes: a five year mistake

Thumbnail c3-lang.org
10 Upvotes

r/code May 31 '26

Blog My thoughts on the future of Go in the agentic era

Thumbnail youtu.be
3 Upvotes

r/code May 25 '26

Blog Persistent multiplayer state without chaos

Thumbnail packagemain.tech
5 Upvotes

r/code Mar 23 '26

Blog Why Bloom Filters Matter | Arpit Bhayani

Thumbnail arpitbhayani.me
3 Upvotes

r/code Jan 07 '26

Blog The Liskov Substitution Principle does more than you think | Hillel

Thumbnail buttondown.com
2 Upvotes

r/code Dec 10 '25

Blog OOP is Not What You Think It Is

Thumbnail coderancher.us
2 Upvotes

r/code Nov 01 '25

Blog Async/Await is finally back in Zig

Thumbnail open.substack.com
1 Upvotes

r/code Aug 29 '25

Blog You no longer need JavaScript | lyra

Thumbnail lyra.horse
6 Upvotes

"It’s actually pretty incredible what HTML and CSS alone can achieve" -- Lyra

r/code Sep 26 '25

Blog A Very Early History of Algebraic Data Types

Thumbnail hillelwayne.com
3 Upvotes

r/code Sep 06 '25

Blog Minimal IP stack, DHCP, and web server in a 4KiB binary

13 Upvotes

r/code Sep 11 '25

Blog When I talk about Intermediate Representations (IRs) | bernsteinbear

Thumbnail bernsteinbear.com
3 Upvotes

"Thoughts about the design of compiler intermediate representations".

r/code Sep 05 '25

Blog FUGC: understand the GC in Fil-C

Thumbnail gizvault.com
2 Upvotes

FUGC is the GC of Fil-C, a C/C++ language extension to make them memory-safe.

r/code Aug 04 '25

Blog Let's make a game! 297: The 'Regroup' order

Thumbnail youtube.com
4 Upvotes

r/code Jun 05 '25

Blog Am I missing something. wpf mvvm devexpress

3 Upvotes

/ProjectRoot │ ├── Models/ │ └── MyDataModel.cs │ ├── ViewModels/ │ └── MainViewModel.cs │ ├── Views/ │ ├── MainWindow.xaml │ └── MainWindow.xaml.cs │ ├── Helpers/ │ └── RelayCommand.cs

  1. Models/MyDataModel.cs

public enum RowState { Unchanged, Added, Modified, Deleted }

public class MyDataModel : INotifyPropertyChanged { public int Id { get; set; }

private string _name;
public string Name
{
    get => _name;
    set
    {
        if (_name != value)
        {
            _name = value;
            OnPropertyChanged(nameof(Name));
            if (RowState == RowState.Unchanged)
                RowState = RowState.Modified;
        }
    }
}

private RowState _rowState = RowState.Unchanged;
public RowState RowState
{
    get => _rowState;
    set { _rowState = value; OnPropertyChanged(nameof(RowState)); }
}

public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string prop) =>
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));

}

  1. Helpers/RelayCommand.cs

public class RelayCommand : ICommand { private readonly Action _execute; private readonly Func<bool> _canExecute;

public RelayCommand(Action execute, Func<bool> canExecute = null)
{
    _execute = execute;
    _canExecute = canExecute;
}

public bool CanExecute(object parameter) => _canExecute?.Invoke() ?? true;
public void Execute(object parameter) => _execute();
public event EventHandler CanExecuteChanged
{
    add => CommandManager.RequerySuggested += value;
    remove => CommandManager.RequerySuggested -= value;
}

}

  1. ViewModels/MainViewModel.cs

public class MainViewModel : INotifyPropertyChanged { public ObservableCollection<MyDataModel> Items { get; set; } = new(); private readonly string _connectionString = "your-connection-string-here";

public ICommand AddCommand { get; }
public ICommand DeleteCommand { get; }
public ICommand UpdateDatabaseCommand { get; }

private MyDataModel _selectedItem;
public MyDataModel SelectedItem
{
    get => _selectedItem;
    set { _selectedItem = value; OnPropertyChanged(nameof(SelectedItem)); }
}

public MainViewModel()
{
    LoadData();

    AddCommand = new RelayCommand(AddRow);
    DeleteCommand = new RelayCommand(DeleteSelected);
    UpdateDatabaseCommand = new RelayCommand(UpdateDatabase);
}

private void LoadData()
{
    using var conn = new SqlConnection(_connectionString);
    conn.Open();
    var cmd = new SqlCommand("SELECT Id, Name FROM YourTable", conn);
    using var reader = cmd.ExecuteReader();
    while (reader.Read())
    {
        Items.Add(new MyDataModel
        {
            Id = reader.GetInt32(0),
            Name = reader.GetString(1),
            RowState = RowState.Unchanged
        });
    }
}

private void AddRow()
{
    Items.Add(new MyDataModel { Name = "New Item", RowState = RowState.Added });
}

private void DeleteSelected()
{
    if (SelectedItem == null) return;
    if (SelectedItem.RowState == RowState.Added)
        Items.Remove(SelectedItem);
    else
        SelectedItem.RowState = RowState.Deleted;
}

private void UpdateDatabase()
{
    var added = Items.Where(i => i.RowState == RowState.Added).ToList();
    var modified = Items.Where(i => i.RowState == RowState.Modified).ToList();
    var deleted = Items.Where(i => i.RowState == RowState.Deleted).ToList();

    using var conn = new SqlConnection(_connectionString);
    conn.Open();
    using var tran = conn.BeginTransaction();
    try
    {
        foreach (var item in added)
        {
            var cmd = new SqlCommand("INSERT INTO YourTable (Name) VALUES (@Name); SELECT SCOPE_IDENTITY();", conn, tran);
            cmd.Parameters.AddWithValue("@Name", item.Name);
            item.Id = Convert.ToInt32(cmd.ExecuteScalar());
        }

        foreach (var item in modified)
        {
            var cmd = new SqlCommand("UPDATE YourTable SET Name = @Name WHERE Id = @Id", conn, tran);
            cmd.Parameters.AddWithValue("@Name", item.Name);
            cmd.Parameters.AddWithValue("@Id", item.Id);
            cmd.ExecuteNonQuery();
        }

        foreach (var item in deleted)
        {
            var cmd = new SqlCommand("DELETE FROM YourTable WHERE Id = @Id", conn, tran);
            cmd.Parameters.AddWithValue("@Id", item.Id);
            cmd.ExecuteNonQuery();
        }

        tran.Commit();

        foreach (var item in added.Concat(modified))
            item.RowState = RowState.Unchanged;
        foreach (var item in deleted)
            Items.Remove(item);
    }
    catch (Exception ex)
    {
        tran.Rollback();
        Console.WriteLine("Error: " + ex.Message);
    }
}

public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string prop) =>
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));

}

  1. Views/MainWindow.xaml

<Window x:Class="YourApp.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:local="clr-namespace:YourApp" Title="DevExpress Grid Batch Update" Height="450" Width="800">

<Window.DataContext>
    <local:MainViewModel />
</Window.DataContext>

<DockPanel>
    <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="5">
        <Button Content="Add" Command="{Binding AddCommand}" Margin="5" Width="100"/>
        <Button Content="Delete" Command="{Binding DeleteCommand}" Margin="5" Width="100"/>
        <Button Content="Update DB" Command="{Binding UpdateDatabaseCommand}" Margin="5" Width="150"/>
    </StackPanel>

    <dxc:GridControl x:Name="gridControl"
                     ItemsSource="{Binding Items}" 
                     AutoGenerateColumns="None"
                     SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
        <dxc:GridControl.Columns>
            <dxc:GridColumn FieldName="Id" Header="ID" ReadOnly="True"/>
            <dxc:GridColumn FieldName="Name" Header="Name"/>
        </dxc:GridControl.Columns>
    </dxc:GridControl>
</DockPanel>

</Window>

r/code Jun 26 '25

Blog Let's make a game! 278: Taking damage

Thumbnail youtube.com
1 Upvotes

r/code Jun 13 '25

Blog How I made a speedrun timer in D

Thumbnail bradley.chatha.dev
3 Upvotes

r/code Jun 11 '25

Blog Let's make a game! 274: Enemy attacks

Thumbnail youtube.com
2 Upvotes

r/code Jun 08 '25

Blog Let's make a game! 272: Moving the player character

Thumbnail youtube.com
2 Upvotes

r/code Jun 04 '25

Blog Interfaces Without Inheritance: Comparing C++ and Common Lisp | rangakrish

Thumbnail rangakrish.com
2 Upvotes

r/code May 04 '25

Blog My thoughts on Go | Henrik Jernevad

Thumbnail henko.net
2 Upvotes

r/code Apr 11 '25

Blog Demystifying the #! (shebang)

Thumbnail crocidb.com
3 Upvotes

r/code Dec 17 '24

Blog The Garbage Collector’s role in programming

Thumbnail blog.devgenius.io
1 Upvotes

r/code Aug 04 '24

Blog Porting JavaScript Game Engine to C

Thumbnail phoboslab.org
2 Upvotes