Code Teachers?
-
On Fallcoast, @Cobaltasaurus is hosting a coding how-to on Monday. I don't remember the event number, but I think she's pretty amazeballs for doing this thing.
-
===================> Coding Lessons - Mon Jun 20 17:00 est <=================== Coding lessons! Are you interested in learning MUX code? I'm going to host a lesson. We'll go over: - Permissions & Inheritance - @commands vs functions - Build A +Who! Time: 2pm PT / 5pm ET This will be no more than 1.5hr long. Storyteller: Cobaltasaurus Genre: OOC Signups: Millicent, Katherine, Toma, Nope, Hamlet, Deckard, and Jackson ========================> 3543: Coding Lessons - Mon Jun 20 17:00 est - 7 <====
It won't be anywhere near as indepth or REAL PROGRAM like @Ashen-Shugar's stuff up above. But it'll hopefully be friendly enough that non-RL programmers will get something out of it. Since I learned to MU* code before anything, I have that as my perspective. It'll be short because I work that afternoon and frankly, I don't want to use my last day off before summer term starts teaching people how to code. (Sorry!)
But I'll probably try to do one the next week depending on how homework and stuff goes.
-
@Taika said in Code Teachers?:
@Lithium - Yeah, but if you can't think of how to get to that pretty chart you want to code (what attributes to pull, how to order them, adding commands to set new ones, etc), you won't get far either, I would think?
I actually think that developing this - learning how to /design/ the code, how to break it into all the pieces you want, and conversely, learning how to troubleshoot it to find the pieces that are broken - is the hardest thing to teach when it comes to coding.
There will always be some adjusting along the way, but if you can learn to tackle this early on, to design well, to think about your product in pieces and then to break those pieces down into pieces, you'll do much better. And it's much easier to tackle one cog than the whole machinery at once.
The best way to learn to code, in my opinion, is to pick a project and start. Just go. Stare at other people's stuff, maybe start by making adjustments. Change a color, add a column, see what breaks and fix it. Then do a simple command. A +who, a +finger. It's impressive how fast it gets complicated.
If you can find a mentor who you can ask questions of, even better. I often find that by talking someone else through my sticking point, I solve it myself (this is actually a thing - google 'Rubber Duck Debugging). Even typing up a post on a forum can help you find that spot. But it's also really useful to have someone who can point you in the direction of stuff you didn't know existed, or to just explain @switch to you in a way that makes sense, or whatever dumb (or not dumb) thing you need.
But the vast majority of learning to code is just coding.
Pro tip: Keep a copy of the old code until you're REALLY SURE nothing important is broken.
-
@Tat said in Code Teachers?:
@Taika said in Code Teachers?:
@Lithium - Yeah, but if you can't think of how to get to that pretty chart you want to code (what attributes to pull, how to order them, adding commands to set new ones, etc), you won't get far either, I would think?
I actually think that developing this - learning how to /design/ the code, how to break it into all the pieces you want, and conversely, learning how to troubleshoot it to find the pieces that are broken - is the hardest thing to teach when it comes to coding.
There will always be some adjusting along the way, but if you can learn to tackle this early on, to design well, to think about your product in pieces and then to break those pieces down into pieces, you'll do much better. And it's much easier to tackle one cog than the whole machinery at once.
The best way to learn to code, in my opinion, is to pick a project and start. Just go. Stare at other people's stuff, maybe start by making adjustments. Change a color, add a column, see what breaks and fix it. Then do a simple command. A +who, a +finger. It's impressive how fast it gets complicated.
If you can find a mentor who you can ask questions of, even better. I often find that by talking someone else through my sticking point, I solve it myself (this is actually a thing - google 'Rubber Duck Debugging). Even typing up a post on a forum can help you find that spot. But it's also really useful to have someone who can point you in the direction of stuff you didn't know existed, or to just explain @switch to you in a way that makes sense, or whatever dumb (or not dumb) thing you need.
But the vast majority of learning to code is just coding.
Pro tip: Keep a copy of the old code until you're REALLY SURE nothing important is broken.
This is one of the big reasons I'm trying to get the PennMUSH and MUX coders to add parenmatch() from Rhost to the codebases.
It's exceptionally nice as it color-codes the parenthesis, braces, and brackets via matching, or red-highlights missmatches. It also has a pretty-print option that breaks up the commands and functionality to make it easier to walk the code in question.
The first line is the contents of the 'VC' attribute.
The second line is the output of [parenmatch(me/vc)]
The third and later lines is the output of [parenmatch(me/vc,,1)]As for how I tend to code, I found this is the best method (for myself) and works well.
Picture how you want the final product. The output, the user-interface, every aspect of it.
Then you ask yourself these questions:
- How do I design this so that if I need to come back to it a year from now and add new features, it can be done with the least amount of work, because I'm a lazy bastard.
- How can I design this so that when I come back to it a year later, I can understand what the hell I was smoking when I wrote it and not have to spend much time to get re-acquainted with it, because again, I'm a lazy bastard.
- When I write my code, to get the end results, what is the functions and commands that I can use that will amount to the least work involved to design it, because I'm a lazy bastard.
- When I organize my code, it should be modular, so I should split commands, data, and functions likely on different objects so that I don't have to worry about cruft when future addons are done.
- The storage will likely change a lot, so I should prepare for methods to keep the data consistent and ways to clean out old or bad data.
- When I design the way the information is stored, I should always leave room to allow quick and easy changes, additions, and removals.
- The way everything works should be easy for someone else to pick up on, incase I get hit by a bus, or more importantly when Fallout 5 comes out and demands my attention from the horrors of dealing with whiney players and demanding co-staff... er... I mean when Fallout 5 comes out... cough.
Basically, I work backwards, find out what I need or want to have happen, work up a list of all the features and functions and commands it'll take to get me there, then code backwards to get to the starting point. I find it easier that way.
-
The only text editor I can use is TextWrangler/BBEdit from Bare Bones Software. It's Mac-only, more's the pity, but it does one thing that Sublime Text/Atom/et al. do not, and while it's difficult to explain why I can't live without it, @Chime assures me that I probably will not see it anywhere else.
In selecting a function to cut out of the code, I must, must have the ability to strip the contents, parenthesis, and the function name itself. It's no good at all for me to select just the contents of a function, or even the contents and the parens/brackets/etc.
TextWrangler allows me to select the contents and parens/etc. just like the others, but it also puts in two insertion points: One at each end of the selection so if I use the keyboard to shift-arrow backwards, it expands the selection backwards. All the other programming text editors I've tried put only one insertion point at the end.
Not having this feature drives me so goddamn batty. I would love to use Sublime Atom, but I'm told that this behavior is not accepted text-editor behavior, so no can do. Thanks a freakin' lot, guys.
-
@Thenomain said in Code Teachers?:
The only text editor I can use is TextWrangler/BBEdit from Bare Bones Software. It's Mac-only, more's the pity, but it does one thing that Sublime Text/Atom/et al. do not, and while it's difficult to explain why I can't live without it, @Chime assures me that I probably will not see it anywhere else.
In selecting a function to cut out of the code, I must, must have the ability to strip the contents, parenthesis, and the function name itself. It's no good at all for me to select just the contents of a function, or even the contents and the parens/brackets/etc.
TextWrangler allows me to select the contents and parens/etc. just like the others, but it also puts in two insertion points: One at each end of the selection so if I use the keyboard to shift-arrow backwards, it expands the selection backwards. All the other programming text editors I've tried put only one insertion point at the end.
Not having this feature drives me so goddamn batty. I would love to use Sublime Atom, but I'm told that this behavior is not accepted text-editor behavior, so no can do. Thanks a freakin' lot, guys.
Hummm... that almost sounds a bit like code-folding. VIM and emacs has a form of this, but I don't think it's as complex as you are alluding to with TextWangler.
Emacs and VIM allow folding based on the line(s), not based on character position, which honestly is a freakingly wonderful feature that now that you mention it I can see some amazing uses for.
Great, now I have to look up this editor and play with it. You're such a bastard.
-
I assure you I'm not so advanced a coder that I know what "code-folding" is, but I'll be looking it up shortly. I use cmd-shift-backarrow on the Mac, which is to say "select one word to the left". I know for a fact that TextWrangler uses dual insertion points for this because they say so in their documentation. Since I go coo-coo for spaces<*>, I'm assured that this will be the function name.
<*> Spaces after commas and semi-colons, everyone. Spaces after commas and semi-colons!!! Do you want us all to go blind or something? Put! Spaces! Everywhere!
Rar!
edit: Now that I looked this up, yes, TextWrangler can do code folding, but that's not what I'm talking about. This is what I'm talking about:
case( 1, strmatch( x, y ), do something, default condition )
I want to cut
strmatch( x, y )
out and replace it withu( f.match.things, x, y )
. In TextWrangler, I get inside the parens, typecmd-b
('balance and select') thenshift-cmd-backarrow
('select previous word') thendelete
. Then I start typing. Done. Easy. Done. -
@Thenomain said in Code Teachers?:
I want to cut
strmatch( x, y )
out and replace it withu( f.match.things, x, y )
. In TextWrangler, I get inside the parens, typecmd-b
('balance and select') thenshift-cmd-backarrow
('select previous word') thendelete
. Then I start typing. Done. Easy. Done.It wouldn't be hard to do this in emacs, though the terminology and conventions tend to be different.
In particular, if you're already using smartparens (or Riastradh's excellent paredit...), there's a function sp-backward-up-sexp:
Move backward out of one level of parentheses.
With ARG, do this that many times. A negative argument means move forward but still to a less deep spot.
If called interactively andsp-navigate-reindent-after-up
is enabled for current major-mode, remove the whitespace between
beginning of the expression and the first "thing" inside the expression.Examples:
(foo (bar baz) quux| blab) -> |(foo (bar baz) quux blab)
(foo (bar |baz) quux blab) -> |(foo (bar baz) quux blab) ;; 2
( foo |bar baz) -> |(foo bar baz)
Combine that with
backward-word
(M-b
) and/or various delete bits and you've got basically what you have above. In particular, something like:;;; replace-mush-function.el --- because Thenomain wanted it ;; Copyrights and module metadata should go here. Meh. Chime wrote ;; this. (require 'smartparens) ;;;###autoload (defun replace-mush-function () "Delete the enclosing parenthesized list and the preceeding word. This function uses `sp-backward-up-sexp' and friends from `smartparens-mode'; as a result it can and will reformat text across expanses of lines. Be wary." (interactive "*") (when (looking-at "(") (forward-char)) (sp-backward-up-sexp) (let ((sp-no-reindent-after-kill-modes (list major-mode))) (sp-kill-sexp)) (backward-word) (kill-word 1)) (global-set-key (kbd "C-c r") 'replace-mush-function) (provide 'replace-mush-function) ;;; replace-mush-function.el ends here
nb. this markdown code syntax highlighter has a truly rubbish selection of modes.
But anyway! After loading the above I can do all of what you want by typing C-c r (control-c, then r). The dynamic let chicanery could be skipped if we made a proper major-mode for mushcode.
Really though I'd rather do that for MOO and continue working on resurrecting that lovable beast...
-
@Chime I really need to dig into moo, it might be the codebase of choice for a project I have which is to do a Sword Art style of game, with autonomous bots without being so crazy fast paced as a diku mud is.
-
@Thenomain said in Code Teachers?:
TextWrangler allows me to select the contents and parens/etc. just like the others, but it also puts in two insertion points: One at each end of the selection so if I use the keyboard to shift-arrow backwards, it expands the selection backwards. All the other programming text editors I've tried put only one insertion point at the end.
I'm having a hard time picturing what you're saying here. What do you mean by "two insertion points"? What happens if you type when text is selected? Do you start typing on both sides of it?
-
@WTFE said in Code Teachers?:
@Thenomain said in Code Teachers?:
TextWrangler allows me to select the contents and parens/etc. just like the others, but it also puts in two insertion points: One at each end of the selection so if I use the keyboard to shift-arrow backwards, it expands the selection backwards. All the other programming text editors I've tried put only one insertion point at the end.
I'm having a hard time picturing what you're saying here. What do you mean by "two insertion points"? What happens if you type when text is selected? Do you start typing on both sides of it?
It's a selection, so like most selections it deletes what's selected and you start typing like usual.
Perhaps the technical term is "two selection points"?
Imagine the editor can both bracket-match and select the contents and brackets of the following text: cat( meow, meow, meow )
I would have selected:
( meow, meow, meow )
Now I type "shift + left arrow" three times.
In most text editors, I would end up with the following selected:
( meow, meow, meo
In TextWrangler, I would have:
cat( meow, meow, meow )
This is because TextWrangler's behavior is that if you're selecting from a selection, you're not trying to shorten it, but expand it. It does this by having two insertion (selection, whatever) points, one at each end. Depending on the direction you're expanding the selection, it will change the location of the more appropriate point.
This latter behavior is how I code on keyboard, only I select by word, not by character. It was mentioned this way to make a more dramatic and therefore clearer example. On these other editors, typing "cmd + shift + left arrow" once would get me:
( meow, meow,
Horrible. I can't do anything with that selection.
('cmd + left/right arrow' moves one word at a time, '+ shift' engages selection. Not too different from a lot of editors, but not everyone is Mac-friendly so I wanted to add even more description. Possibly too much.)
Why would I ever want to do this?
Because there are times, many many many times, where I have something like:
treat( %0, cat( meow, meow, meow ))
And I want to replace all instances of 'cat( <stuff> )' with 'dog( <different stuff> )'.
The variables I'm calling with may change, so I want to simply select it all at once, cull it, and start typing, in this case: dog( bark, woof, tail-wag ).
Well if I can't select 'cat( ... )' and its entire contents, then this is a tedious, annoying chore. As if dealing with Mushcode isn't tedious enough, I'm going to use the editor and style that makes things go as fast as possible.
-
I understand perfectly why you'd want to do it.
But I think you have the reasoning wrong.
The issue isn't that most text editors only have one selection point. Every editor I've seen (or inferred) the internals of has a minimum of two selection points for a range selection: beginning and end. (Those which can do multiple selections, naturally, have more.) The issue is that nobody has bound the keystrokes to manipulating the first selection point of a pair rather than the last.
The behaviour you describe is something I could code up in a function for Textadept in about five minutes. In your situation, for example, I could move the cursor to, say, one of the "meow" instances, then use the existing key binding to match everything in parentheses (Ctrl+( twice: once for the inside, once again to get the parens as well). This is just using a key binding to a function that calls textadept.editing.select_enclosed(), an exposed API function. To complete this I'd have to call that function twice, get the beginning and end points, find the word boundary left, then set a new selection. In total it's about five lines of code, plus an extra line to bind the function to a key combination.
So perhaps the problem isn't the text editors proper but rather the lack of customization ability. Which is something that can be cured by selecting a really customizable editor.
-
@Thenomain said in Code Teachers?:
Perhaps the technical term is "two selection points"?
Ah, ok, I grok what you're asking for.
Yea, other editors do offer this as well, most not out of the box, but they do have plugins that will enable it.
VIM is just one (https://github.com/terryma/vim-expand-region) emacs and other applications have varying plugins that allow the same thing.
I think if you have a preferred editor, Theno, you can likely get a plugin that'll do what you want, but you seem pretty happy with your editor of choice, so it's likely moot
-
Yeah, no point changing editors if you like the one you've got. Don't select emacs because it's what the cool kids use. (They don't. Emacs is for kids whose moms say they're cool.) Don't select vim for that reason either. (Vim is for kids whose moms say they're sexy.) Pick an editor you like and use it; fuck anybody who judges you for your choice.
-
If I'm on Linux I use vim, else if I'm on Windows I go with UltraEdit or Notepad++. It depends though on whether I want a true IDE with an integrated debugger or not.
-
@Arkandel I use Textadept as my primary (on all major platforms) with vim as my backup and ed as my "holy shit am I ever in trouble!" last resort.
-
@WTFE Not surprisingly need, rather than preference, dictates usage. For example I ssh and work on a significant number of VMs so unless I puppet'ed my credentials for each so I can edit files remotely it'd be a complete pain in the ass to do it any other way than by using an editor already installed on the machines themselves. vim fits that bill nicely.
I really don't do enough 'work' on Windows to warrant anything more than Notepad++ to be honest, it's just convenience for me. A few config files here and there but otherwise it's my go-to for MUSH log editing. I'll have to give Textadept a look though.
Also emacs is fine but it really needs a good text editor.
-
That's my precise use case for vim: remoting.
Textadept is pretty much a programmer's editor; if you're editing log files it's probably not got anything you want. I use it because it's infinitely malleable without being fugly like emacs and because it has the best language syntax support system I've ever seen, bar none. This is important because I use oddball languages no other code editor properly supports. (Mercury? SNOBOL4? Logtalk?)
-
@Lithium said in Code Teachers?:
@Chime I really need to dig into moo, it might be the codebase of choice for a project I have which is to do a Sword Art style of game, with autonomous bots without being so crazy fast paced as a diku mud is.
I just always feel the need to chime in to say how much nicer coding in MOO is than MUSH. I cannot describe how much I prefer it.
I miss MOO.
-
Hey everyone, if anyone is interested, I logged and threw the code class that Cobalt taught up on Fallcoast's wiki here (after removing any staff-sensitive information, since I'm Toska):
http://fallcoast.net/wiki/Code_Teaching_(%2BWho)
Wiki code sucks for formatting, but imagine that there's 38 spaces between the names when they're in columns. Enjoy!
Edit to add: Fixed, just made the bits where columns are into code blocks by adding a space in the formatting. Should be good now!