[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: IMG_20260529_003316_441.jpg (117 KB, 641x1280)
117 KB JPG
On a scale from 1 to 10, how difficult would you find it to follow and modify this code of mine.
>>
-128
>>
>>108928765
Kindergarden easy. But something tells me there's more (((elegant))) way to do this.
Ask around lisp fags, they probably wasted a lot of time in emacs, they perhaps waited half their life for you to ask them this question.
>>
!is - i dont follow mishmash, either "!=" or "not is"

MoveBackwardToBoundary but isWordChar - is another mishmash, either PascalCase or camelCase

not following, guess function names are easy to modify, so 1 very easy, assuming !is - is non-modifiable 1000 impossible to modify.
>>
File: img.jpg (76 KB, 800x750)
76 KB JPG
preddy gud
>>
>>108928851
Yeah, this is a style I adopted from Go (which at first I didn't like): public methods are PascalCase, private are camelCase, variables are snake_case.
>>
>>108928765
>auto
Into the trash it goes.
>>
>>108928893
Also, D stdlib obviously doesn't follow my convention, but then it's easy to understand which functions are mine and which aren't.
>>
Looks reasonable to me.
Clearly named functions and values, function body isn't too long, functions get their state passed in / good scoping.
No obvious complaints. No comments from me on style, looks fine.
>>
>>108928916
Yeah, thanks. One of my goals in writing this is exceptional maintainability, so this work I'm doing now has a chance of being maintained for a long time by other people. Who knows.
>>
>>108928893
Go corpolang has no objects, thus, no methods. 's very poor naming, the proper way is

_privateFunc
publicFunc

and even

__privateFuncHelper

snake case is retarded, use hyphen-case as hashmap keys or file-names, snake case is only for THIS_IS_A_CONSTANT or MACRO_LANG_THING
>>
>>108928765
>this code of mine
you did nothing, this is just copy pasted slop you faggot
>>
>>108928765
Looks nice and straightforward
>>108928952
If that's the goal you might want to use a language that's less dead though
>>
>>108928961
Go has methods and objects, you are retarded.
_ is ugly btw, I feel like one of the few things Go got right is private/public thing, that was brilliant.
>>
>>108928965
unironically it isn't. If you check how any other editor jumps words (vim, nvim, helix kakoune etc...), you will see that my specific code is more human in how it sees boundaries and more precise. It's definitely not copypasta slop, this is handcrafted over two days of careful experimentation.
>>
>>108928893
I agree with this and disagree with this >>108928961
Even outside of Go I have adopted their style.

>>108928952
You're doing good it seems. Takes a while to perfect/refine the art.
I share your desire. Writing unmaintainable code feels like a waste of time. Like writing a book you hope nobody ever reads.
I'd rather write code that might live longer than myself.
>>
>>108928765
About 5.
Generally speaking, if you need to write a comment, it should be because you're expressing complex business logic. Your comments are not business logic but rather implementation logic. This is always a warning sign. The warning sign is upgraded to a red flag because the implementation logic you need to comment isn't special optimization or bug workarounds, which are the only cases where it is acceptable to have that kind of code smell.

More concretely and succinctly put, your code models the problem domain instead of the solution domain. This makes following the code awkward without domain knowledge -- which I have and the reason why I can give it a 5 instead of, say, a 7.
>>
>>108928973
> If that's the goal you might want to use a language that's less dead though

Perhaps, but D is pretty established and just werks, needs barely any maintenance. Also, I think it's a good idea to enjoy the process and D is pretty much the only language that joymaxxes the coding process for me, at least when it comes to writing text editors.
>>
>>108929004
>Even outside of Go I have adopted their style.
javascript uses "#" for private
>>
>>108929025
Yeah, and D also has the "private" keyword, that's not the point. The point is that it's visible without special characters or special words. For some reason I thought that private methods in D wouldn't be callable from a unit test, but so long as the unit test is in the same package, it seems work just fine. So one thing to do in the future would be to go through all my pseudo-private methods and mark them as private.
>>
>>108929014
Hm, can't agree with you here. Comments seem reasonable to me, they do help quickly decipher the lines that follow, which makes it easier to modify it later or experiment with it.
>>
>>108929062
Don't get me wrong: the comments are perfectly good on their own. The problem is not the comments, it's the fact the comments were needed in the first place, i.e. that the code they are applied to is not self-obvious. I argue that this is because the data model is fit to the problem rather than the solution domain, which is why it was not possible to express the solution in a way that was self-evident.
In the ideal case, the only comment needed would be the OP post explaining the domain the snippet comes from, but the code itself should not need any comment (to be clear, I also do not advocate avoiding comments in code in the self-documenting code meme manner, but only that the code should not need any decoding from comments).
I have also read another sensible description of what I mean: comments should never explain 'what', but rather 'why'.
>>
>>108929101
> comments should never explain 'what', but rather 'why'.

I used to follow that school of thought, but lately I realized this might yet another cargo cult. So thinkg about it: why should comments not explain "what?" Because the code should explain it? But what if for the code to explain the what, you'd need to reshape it and create more useless methods with nice readable names just to achieve what 1 line of comment and 3 lines of slightly less readable code can? I feel like it's a trade off is what I'm saying.
>>
>>108928984
>Go has methods and objects
> you are retarded

are you talking to yerself? hehe, whata retard.

> Go got right is private/public thing

i wrote private/public too, but that was only to explain a retard how to name properly. the private/public terms exist only in a very OOP oriented langs, like Java, i dont like it, i also more on procedural style (what is Go corpolang about), so in procedural langs there is no typecheck or explicit check and only a name factor, which is traditionally the _ underscore symbol, a special prefix. a letter cannot be special so it is lower weight than symbol, it is of worse readability and it lacks second power factor __ kinda "very private". so its worse naming design.

>>108929004
>I agree with this and disagree with this

you dont have a name or didnt show a proper thinking ("Go methods") to have authority/weight in judgements
>>
>>108929143
No, that's kinda the point. You SHOULDN'T need to create one-line methods with readable names. You're writing yourself into a corner there. If you get there, it means your entire initial design is simply wrong.
I agree that it sounds like cargo cult logic, but in my experience, it really isn't. I have seen plenty of cases were people swore it was impossible to write it correctly in a self-explainable way without sacrificing something, and it took me no time and no effort to fix it. No extra abstraction needed either. Just reslice the problem in a more natural way.
>>
your style is absolute shit. very inconsistent and also same lining an if statement is niggerlicious.
>>
>>108929148
You're arguing semantics. Bo has methods, Go doesn't have methods. Who cares? People use those functions as methods and build OOP-like abstractions with structs and functions that look like they're methods. I hate autism that so autistic it can't even into self-awareness.
>>
>>108929170
Well, you have a unique chance to show off here. This file is just a bunch of functions, no classes, no methods, so there's no need to understand the editor at large. And it's unit test covered. You can rewrite a few of those your way and see if tests pass :)

Here it is, if you're into it: https://code.qount25.dev/qount25/ick/src/branch/master/source/cmd/motion.d
>>
>>108929177
>self-awareness

you cannot into self-awarness because you treat everything as the same thing. awarness is also semantics and also syntax and also a hyphen-cased phrase that i recommend to use. see, you already following my recommendations. few more mental steps and you will shill them as you invented them, because, who cares, mine, yours, those are just semantics, same effect.
>>
>>108928765
Seems perfectly readable to me.
>>
>>108929197
bool MoveForwardToBoundary(ref Context ctx) {
auto cur = &ctx.document.vcursor;
auto start_pos = cur.position;
auto prev_char = cur.char_under;

while ( MoveForwardOne(ctx) ) {
if ( cur.position.x == 0 &&
cur.prev_pos.y != cur.position.y &&
cur.prev_pos.x != 0
) return true;
if ( isWordBoundary(prev_char, cur.char_under) ) return true;
prev_char = cur.char_under;
}

// This skips over empty lines to the next non empty line
while ( ctx.document.vcursor.line.IsEmpty && ctx.document.vcursor.line.next !is null ) {
if ( !MoveForwardToBoundary(ctx) ) return false;
}

// And this skips non-word characters in the beginning of a line
// that follows some empty lines.
while ( !isWordChar(ctx.document.vcursor.char_under) ) {
if ( !MoveForwardOne(ctx) ) return false;
}

return cur.position != start_pos;
} unittest {
auto ctx = Context(document: new Document("abc def\nghi\n jkl\n\n\nmno"));
auto cur = &ctx.document.vcursor;

MoveForwardToBoundary(ctx);
assert(cur.char_under.get == ' ');
MoveForwardToBoundary(ctx);
assert(cur.char_under.get == 'd');
MoveForwardToBoundary(ctx);
assert(cur.char_under.get == 'g');
MoveForwardToBoundary(ctx);
assert(cur.char_under.get == ' ');
MoveForwardToBoundary(ctx);
assert(cur.char_under.get == 'j');
MoveForwardToBoundary(ctx);
assert(cur.char_under.isNull);
MoveForwardToBoundary(ctx);
assert(cur.char_under.get == 'm');
} // end unittest


I puke. You suck and I bet you haven't noticed the problem in this fragment yet, but also it's clear you can't spell disgusting without d.
>>
>>108928765
That null checking is freaky. Also, your two functions are basically the same, even having the same comments. Why not factor out the commonality?



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.