Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> requiring `fn` in front of the functions. This is to simplify searching for definitions in editors.

You don't have to do that even in C, you can use this style for function defs

  static int
  myfunc(...)
  {
  ...
  }
and search or grep for

  ^myfunc\(
to isolate the definition as opposed to the use.


Interestingly removing `fn` was something I've considered more than once, but I had people ask me to keep it. Even though you can get searchability in C by adhering to certain conventions, that's not the same as being able to search ANY code base in a simple manner, which I believe is what people wanted.


I doubt many C programmers were waiting for someone to force a function naming style on them after 50 years.


I think this is more aimed at people who couldn't quite get their head around C and were happy to have a forced function naming style that made tooling easier.

(note, I am -shit- at C, but genuinely wonder if I could write this without spending 98% of my debugging time tracing segfaults that were down to my own stupidity)


I was confused by this, thought they added `fn` to simplify the parser which to my understanding is why many languages moved away from C style function declarations. I'd rather they move the return type to the end like in Rust and Go for example


Simplifying the parser is cool, but what matters most to me is that I can grep/rg for function definitions. This is really hard in languages that don't have some function keyword.


It simplifies the parser somewhat, but C3 restricts the grammar somewhat from C, so it's possible to unambiguously parse it. However, for people writing tools using `fn` is much easier to parse for. Say you want to write a program that dumps all function names in a file. With `fn` that's a simple regex. Without it you have to do more work.


Or just use an IDE. It's 2022 people! We don't have to code like it's 1985.


I still haven't used a IDE that has made my developer experience better than simple text editor and some cli tools. They all seem to fail spectacularly if you have to do something bit more different than they were designed for (usually regarding how the project is built), and often feel very sluggish. Also the project files or build files they generate are usually horrible, and not great for version control.


Use the IDE for adding an index to your codebase for better navigation & editing and cross file refactoring.

Use whatever headless buildscripts you fancy (make?!) to build your project.

Problem solved.


Code search and an debugger that isn’t a pain to use are the main advantages of an IDE.

I don’t think I’ve ever seen the build and code repo tooling ever work on any professional codebase I’ve worked on, save one.


> I don’t think I’ve ever seen the build and code repo tooling ever work on any professional codebase I’ve worked on, save one.

Yeah I agree though in my experience it is because professional teams are usually infected by at least a few "everyone just uses Vim and a terminal right?" people who then go about turning the build system into some horrible script based system that IDEs can't work with.


>Code search

Use grep or ag

>debugger

What's so painful about it?


Grepping and entire code base just to find where some class is defined is certainly doable (I do it often), but it’s not as nice as just right clicking “Go to definition”. Especially in very large codebase with multiple git submodules.

No one serious would assert that inspecting complex data structure, managing breakpoints, stepping through code, or debugging remotely via text mode gdb like it’s 1986, is as easy or efficient as simply using a GUI in 2022, or even 1992.


My experience is that they always get in way. Either they slow down the whole thing down, or it randomly freezes. Or the code-completion window decides to popup and it again slows things down.

For navigation I've used something like this since eternity: https://cloudef.pw/armpit/vim-bemenu-curses.mp4

For search, grep or ag will do. As for refactoring, personally I've never had the need for a tooling for that.

>Use whatever headless buildscripts you fancy (make?!) to build your project.

These are just fancy text editors at this point. IDE is like visual studio, or xcode. Sure some of those fancy editors still share the same problems, especially all the java ones (eclipse, android studio, jetbrains ...)


Use cscope and/or [ex]ctags and there was no problem in the first place, even in 1985.


I don't even bother with code-completion. Not having it makes me actually dig the source code of other components, and is usually helpful deciding if I even want to use the said 3rd party component. Programming is more about thinking than looking up fast what functions to call anyhow.

If you wanted code-completion, you'd better use LSP anyways, and you'll get all that fancy compiler diagnostics and whatever in your editor.


I agree. I’m only using “word” completion from open buffers and include lists to save keystrokes. Makes you read, think and choose instead of blindly walking through dots in hope that some combination works. But I also had a good experience with ctags (in 10k+ projects), for quicker navigation.


cscope? Now there’s a name I haven’t heard in 23 years.


Yeah but that's a very quirky style; I don't want to change the structure of my code just to make it searchable!


Sticking fn in front of every def isn't quirkier?

Some parts of the kernel use this style.

It's also advantageous because it enables long return types and long function names neatly at the same time.


> Sticking fn in front of every def isn't quirkier?

No because almost every single programming language that's not C/C++ has a keyword that signals function declaration.


A good number of those don't have mandated return types, so that keyword is their way of copying c(++)'s look, so its "func main()", like "void main()", instead of just "main()", which to a some people may look strange.


I don't understand why this is relevant. Regardless of the rationale to add it to the language, if syntactically it's `func main()` I can tell it's a function definition because it's always `func`. You can't do that in C++ since it's often some type.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: