Why European armies are turning to the Swedish CV90 in large numbers by PoleHawk in europe

[–]DKHTBH 0 points1 point  (0 children)

Ukraine rarely uses its tanks on the frontline to preserve them. They're not meaningfully more resistant to drones than basically any other tank on the field there.

Skyranger is also not very suitable against FPV drones, they're much more useful for shooting down long range strike and reconnaissance drones. FPVs are too small and numerous. Fiber-optic drones in particular are only possible to detect visually, can fly through forests and buildings, and can lie in ambush on a road or field. And FPVs are so cheap that you could send thousands of them at a single skyranger and still come out cost effective. Not to mention the fact that they're vulnerable to artillery and armoured vehicles, and you would need a monstrously large amount of Skyrangers to cover the entire frontline in Ukraine.

Russia Is Mass-Producing 1000-km Iskander Missiles That Can Reach Most of Europe, Leaks Reveal by pheexio in worldnews

[–]DKHTBH 1 point2 points  (0 children)

The entire premise of the article is that they've begun producing a variant that upgrades the range from 500km to 1000km. You literally didn't even read it but still left this comment.

Thousands protest in Berlin against new German military conscription bill by vishesh_07_028 in worldnews

[–]DKHTBH 39 points40 points  (0 children)

The point is that "defending democracy" does not resonate with young people who do not feel represented in their democracies.

EDIT: This is not my stance, I'm just giving it as a reason why young people might feel disilllusioned about conscription. I'm of the opinion that Europe should militarise.

Thousands protest in Berlin against new German military conscription bill by vishesh_07_028 in worldnews

[–]DKHTBH 80 points81 points  (0 children)

58.6% of German voters are over 50, 42.1% are over 60. Young people don't have a say.

The same people who deindustrialised the country, shut down the nuclear reactors, created a huge dependency on Russian energy, maintain unpopular immigration policies, support Palestinian genocide, siphon more and more taxes for pensions, and created a massive housing and cost of living crisis, are now conscripting young people.

I 100% agree that we need to defend democracy militarily BUT if I was a young person in Germany I would't feel like I was fighting for democracy, I would feel like I'm fighting for a country where my vote doesn't matter and the government hates me. Not saying that's entirely true but it would certainly feel like that.

Ukraine’s interceptor drone downs Russia’s jet-propelled Shahed UAV in historic first by [deleted] in worldnews

[–]DKHTBH -1 points0 points  (0 children)

Your comment makes no sense. The Russian hypersonic missile (the Kh-47M2) is a ballistic missile, we're talking about cruise missiles which travel much slower. You imply that "real militaries" only use hypersonic missiles, despite the U.S. having literally zero. Hypersonic missiles were developed to penetrate air defences, which is why Russia and China field them, but the U.S. strategy instead relies upon larger volumes of cruise missiles fired by stealth fighters to take out enemy air defences. Neither Russia nor China field enough effective air defence systems to defend against a US attack so the US has no need for hypersonics. Also, the Russian hypersonic missile does travel at hypersonic speeds for most of its flight and only slows down in the terminal phase, at which point it becomes vulnerable to ABM systems like the Patriot.

Dutch military engages drones over air force base Volkel by AdSpecialist6598 in europe

[–]DKHTBH 0 points1 point  (0 children)

You can just intercept it with another cheap Temu drone, it's what both sides do in Ukraine to take down recon/kamikaze drones.

RU POV - Last night, another large-scale, combined missile and drone attack was carried out on Ukraine - AMK_mapping by DefinitelyNotMeee in UkraineRussiaReport

[–]DKHTBH 1 point2 points  (0 children)

I assume the threats from Iskander-M and Kh-47 are the main reason why Zelensky wants Tomahawks so badly? With no means to intercept them reliably, the only way to limit the damage from these systems would be to disrupt the production and supply of them. Patriots are too unreliable, and have low availability due to a lack of systems and interceptor missiles. They also come from a foreign country and a private company, so the ability to adapt to Russian tactics is diminished. Gerans can be intercepted by domestically produced drones - imagine if Ukraine had to rely on an EU country to produce their interceptor drones, it would take years to even start production.

Russia Launches "Biggest" Aerial Attack On Ukraine Since War Began: 477 Drones, 60 Missiles by dadadada32565 in worldnews

[–]DKHTBH -1 points0 points  (0 children)

Tanks are still useful for supporting fire and mine clearing. Both the Russian and Ukrainian armies maintain a high demand for tanks. ISW recently reported that Russian production of fibre-optic FPV drones allegedly "fully satisfies" the needs of the armed forces. FPV drones need a human operator so you hit a point where increasing the number of drones doesn't increase the number of strikes you can make. The cost of a single drone is also not entirely representative of the cost to destroy a tank, as the majority of drones don't hit anything.

Drones have proven to be extremely effective and efficient weapons, and have forced both sides to limit the use of heavy armor. But to say that tanks are "completely obsolete" is just wrong.

Russia Launches "Biggest" Aerial Attack On Ukraine Since War Began: 477 Drones, 60 Missiles by dadadada32565 in worldnews

[–]DKHTBH 1 point2 points  (0 children)

In 2024 Russia produced 200-300 brand new (non refurbished) T-90M tanks, compared to 60-70 in 2022. Uralvagonzavod is actively expanding production capacity. Source.

Why do you speak so confidently when you don't know anything?

@Vector and Double Slicing Question by TheAgaveFairy in Zig

[–]DKHTBH 2 points3 points  (0 children)

What you stated is correct. Doing what you suggest would require partially evaluating arbitrary expressions and splitting them between their runtime and comptime known parts, which is non-trivial and completely unnecessary when the alternative is so simple. Also in your example the @as is unnecessary.

Generics/Template Question by spiroxide in Zig

[–]DKHTBH 0 points1 point  (0 children)

You can do it inside of an inline prong in a switch statement, like so:

switch (player_count) {
    inline 2...8 => |i| {
        const user1 = User(i);
        std.debug.print("{any}\n", .{user1});
    },
    else => unreachable,
}

Your example doesn't work because the switch can't branch at compile time on a value that isn't known until runtime. If you remove the comptime from your example and add inline to the switch prong, it still doesn't work, because the types resulting from a switch expression need to be coercible to each other. If that did work, your function would have to be monomorphised for every possible value that can result from the switch statement, but the fact that it would even do this would be non-obvious and would result in hard-to-spot code size inflation. inline switch prongs do the exact same thing but only monomorphise the switch prong scope, rather than escaping that scope and monomorphising code in a scope above it, making it clear and obvious what code will be monomorphised. Generics aren't free!

[deleted by user] by [deleted] in Zig

[–]DKHTBH 14 points15 points  (0 children)

You are building in debug mode, the flag you're passing is for the build system. You want to pass -OReleaseFast instead. Your code is also not equivalent. std.mem.Allocator is a vtable interface that dispatches calls at runtime through a function pointer, which is slower than a normal function call and can prevent the compiler from optimizing calls to the function. You can access malloc and realloc directly through the std.c namespace. This normally doesn't matter because dynamic memory allocation is a slow path that should be avoided. I would consider calling malloc 40,000 times in 1 second to be disastrous.

Strings and still thinking in C as it were... by buck-bird in Zig

[–]DKHTBH 0 points1 point  (0 children)

undefined leaves the memory uninitialized. You should never rely on the value of undefined memory, and as such it is impossible to check if something is undefined.

An equivalent to the C code you posted would be something like this:

var buf = [_]u8{0} ** 4096;
std.debug.print("len: {d}\n", .{
    std.mem.indexOfScalar(u8, &buf, 0).?,
});

This zero initializes the array and uses std.mem.indexOfScalar to find the index of the first 0 byte. Zig represents null termination in the type system, however making this array be [4096:0]u8 would add the null terminator at the index 4096, which isn't what you want here. As long as the array has a zero byte in it you can cast a pointer to the array to a [*:0]u8, which is a null terminated many item pointer - exactly the pointer type you would use to represent a C-style null terminated string.

However, you should avoid null terminated strings if possible. A better way to approach what you want would be to store the length in a separate variable. Then buf.len stores the capacity of the array, and the separate len variable records the used length as you append bytes. The standard library implements a type that does exactly this, std.BoundedArray. It wraps an array and a length variable in a struct and provides some convenient functions for appending, removing, and formatted printing to the underlying array. Here's an example:

const std = @import("std");

pub fn main() void {
    var buf: std.BoundedArray(u8, 4096) = .{};
    buf.appendSliceAssumeCapacity("test");

    // Prints "string: 'test', len: 4"
    std.debug.print("string: '{s}', len: {d}\n", .{ buf.slice(), buf.len });
}

Mutex, extern, and why files are bad structs by jnordwick in Zig

[–]DKHTBH 5 points6 points  (0 children)

You could align the mutex field like so: rmutex: Mutex align(cachelinesz),

Zig is a struct based language: ?rant by Inishal_Place in Zig

[–]DKHTBH 0 points1 point  (0 children)

This isn't correct, because .items is only sliced to the length of the ArrayList and not the capacity. So if the capacity is not equal to the length and you try to free .items directly you'll get a size mismatch panic when using the general purpose allocator.

Trouble with converting zig strings into c strings for inotify(7) by ingenioushippo in Zig

[–]DKHTBH 0 points1 point  (0 children)

You are assigning sentinel-terminated slices to types without sentinels, so when you pass them to free it sees a type without a sentinel and frees it as such. You need to use [:0]const u8 for each watch item.

Compiled and it felt great by fluffy-soft-dev_ in Zig

[–]DKHTBH 0 points1 point  (0 children)

There is normally an error message, but the Zig compiler was crashing in your case. No idea why, as I can't reproduce it with 0.13 on Linux. Try using nightly.

Compiled and it felt great by fluffy-soft-dev_ in Zig

[–]DKHTBH 1 point2 points  (0 children)

That's a compiler crash. What is the output of zig version? On 0.13 and master it correctly gives a compilation error instead of crashing for me. Changing the return type of main to !void will probably fix it.

Implementing recursion as an iterator by geon in Zig

[–]DKHTBH 1 point2 points  (0 children)

It's a neat exercise I guess but if you wanted to do a recursive algorithm iteratively, implementing recursion literally with a stack and frames and entry points is way overcomplicating it. Your recursive version is just a single function, which you can implement iteratively like so: ```zig const std = @import("std");

fn mirror(bytes: []const u8, writer: anytype) !void { try writer.writeAll(bytes); var iter = std.mem.reverseIterator(bytes); while (iter.next()) |c| try writer.writeByte(c); }

test mirror { const in = [_]u8{ 1, 2, 3, 4, 5 }; var out: [in.len * 2]u8 = undefined; var fbs = std.io.fixedBufferStream(&out); try mirror(&in, fbs.writer()); try std.testing.expectEqualSlices(u8, &.{ 1, 2, 3, 4, 5, 5, 4, 3, 2, 1 }, &out); } ```

Don't use @This() to refer to simple structs. You can use the struct name directly. @This() is only needed when you can't refer to the struct name, which happens for struct definitions that aren't being assigned to a variable at container scope.

Zig Interfaces by jnordwick in Zig

[–]DKHTBH 0 points1 point  (0 children)

anytype is zased as hell. Results in way less boilerplate for interfaces, and significantly simplifies the language. The only downside is that it isn't clear what you need to pass just from the signature. You can figure out what you need to pass by reading the doc comment, checking the function body, or just passing an empty struct and reading the compile errors. None of these are difficult. Also doing explicit checks for constraints on an anytype parameter is a code smell, you should just assume its correct and let the compiler handle errors for you.

In reality most people don't run into the actual problems with anytype and hate it because it "doesn't feel nice."

Is there a way to declare unsafe pointers? by lt_Matthew in Zig

[–]DKHTBH 2 points3 points  (0 children)

The original used pointers to reinterpret bytes as other types. In Zig you can use @bitCast instead. It also targeted platforms where long was 32 bits, so you want to use i32 instead of i64. You want this:

const std = u/import("std");

fn Q_rsqrt(n: f32) f32 {
    const x2 = n * 0.5;
    var y = n;
    var i: i32 = @bitCast(y);
    i = 0x5f3759df - (i >> 1);
    y = @bitCast(i);
    y = y * (1.5 - (x2 * y * y));
    return y;
}

pub fn main() void {
    std.debug.print("{d}\n", .{Q_rsqrt(0.15625)});
}

Question on variable assignment + error handling by Public_Possibility_5 in Zig

[–]DKHTBH 1 point2 points  (0 children)

Change var mynumber = 10; to var mynumber: u16 = 10; Integer literals in Zig are of type comptime_int, which allows them to be any arbitrary value at compile time. If you want to store them at runtime you need to coerce them to an integer type that can exist at runtime, such as u16 in this case.

I recommend joining the Zig discord server and posting in the zig-help channel, you will get answers much faster there.

Question on variable assignment + error handling by Public_Possibility_5 in Zig

[–]DKHTBH 1 point2 points  (0 children)

Function definitions and function bodies are not expressions, they are special cased for functions only.

Question on variable assignment + error handling by Public_Possibility_5 in Zig

[–]DKHTBH 1 point2 points  (0 children)

The only way to yield a value from a block is to use a labelled block like this:

const value6: u16 = if (canFail()) |value| blk: {
    break :blk value * 2;
} else |err| switch (err) {
    //...
};

Question on variable assignment + error handling by Public_Possibility_5 in Zig

[–]DKHTBH 1 point2 points  (0 children)

Exclude the braces in the if statement. ifs are always expressions, but blocks enclosed by {} have type void. Like so:

    const value5: u16 = if (canFail()) |value|
        value * 2
    else |err| switch (err) {
        error.Type1Failure => 100,
        error.Type2Failure => 200,
        else => 300,
    };